feat: add Rust closure fixtures to gix-testtools#2412
Conversation
…to gix-testtools Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
748fa15 to
a0d9d91
Compare
Reviewed-by: Claude <noreply@anthropic.com>
a0d9d91 to
fff844b
Compare
There was a problem hiding this comment.
Pull request overview
Adds Rust-closure-driven fixture generation to gix-testtools, integrating with the existing cached fixture/archive system while switching cache invalidation to a caller-supplied version integer.
Changes:
- Introduce
rust_fixture_read_only*andrust_fixture_writable*APIs, withversion: u32used as the cache/archive identity. - Refactor fixture generation to reuse shared marker/failure/archive handling and centralize tar extension selection.
- Add tests for Rust fixture caching, version invalidation, error propagation, and standalone fixture roots; move existing unit tests into a dedicated test module file.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
tests/tools/src/lib.rs |
Adds new Rust fixture APIs; factors out common “run generator + marker/archive handling”; adds tar_extension() and externalizes unit tests module. |
tests/tools/tests/rust_fixture.rs |
New integration tests validating Rust fixture behaviors (cache hit, version bump, writable mode, error propagation, standalone root). |
tests/tools/src/tests.rs |
New internal unit test module extracted from lib.rs. |
tests/tools/.gitignore |
Adds ignore rule for the standalone fixtures/ directory. |
| let dir_str = dir.to_string_lossy(); | ||
| assert!( | ||
| dir_str.contains("fixtures") && dir_str.contains("generated-do-not-edit"), | ||
| "Standalone fixture should be in fixtures/generated-do-not-edit directory, got: {dir_str}" | ||
| ); | ||
| assert!( | ||
| !dir_str.contains("tests/fixtures"), | ||
| "Standalone fixture should NOT be in tests/fixtures directory, got: {dir_str}" |
There was a problem hiding this comment.
This path assertion is string-based and assumes / separators. On Windows, a wrong path like tests\\fixtures\\... would still satisfy the positive check and the negative "tests/fixtures" check would not catch it. Prefer checking path components via Path APIs (e.g., starts_with("fixtures") and !starts_with("tests")) to make the test platform-correct.
| let dir_str = dir.to_string_lossy(); | |
| assert!( | |
| dir_str.contains("fixtures") && dir_str.contains("generated-do-not-edit"), | |
| "Standalone fixture should be in fixtures/generated-do-not-edit directory, got: {dir_str}" | |
| ); | |
| assert!( | |
| !dir_str.contains("tests/fixtures"), | |
| "Standalone fixture should NOT be in tests/fixtures directory, got: {dir_str}" | |
| let components: Vec<_> = dir.components().collect(); | |
| let has_fixtures = components.iter().any(|c| c.as_os_str() == "fixtures"); | |
| let has_generated = components | |
| .iter() | |
| .any(|c| c.as_os_str() == "generated-do-not-edit"); | |
| assert!( | |
| has_fixtures && has_generated, | |
| "Standalone fixture should be in fixtures/generated-do-not-edit directory, got: {}", | |
| dir.display() | |
| ); | |
| let has_tests_fixtures = components | |
| .windows(2) | |
| .any(|pair| pair[0].as_os_str() == "tests" && pair[1].as_os_str() == "fixtures"); | |
| assert!( | |
| !has_tests_fixtures, | |
| "Standalone fixture should NOT be in tests/fixtures directory, got: {}", | |
| dir.display() |
| @@ -0,0 +1 @@ | |||
| fixtures/ | |||
There was a problem hiding this comment.
With the new integration-style rust fixture tests, running this crate’s tests will also generate tests/fixtures/generated-archives/*, which isn’t covered by this ignore entry and may leave untracked archives in the working tree. Consider narrowing the ignore to generated fixture outputs and/or adding an ignore entry for tests/fixtures/generated-archives/ (or a pattern matching *.tar/*.tar.xz) to keep local worktrees clean.
Adds ability to create fixtures using Rust closures instead of shell scripts, with manual version numbers for cache invalidation.
New API
rust_fixture_read_only(name, version, closure)- cached read-only fixturerust_fixture_writable(name, version, mode, closure)- writable temp directory copy*_standalonevariants forfixtures/instead oftests/fixtures/Implementation
rust-(e.g.,rust-my_fixture.tar.xz)Example
Increment version when closure behavior changes to force cache rebuild.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.