Repository navigation
test: add unit tests for generator logic - #51
Conversation
There was a problem hiding this comment.
Pull request overview
Adds initial Rust unit test coverage for the generator crate to validate core helper logic and reduce reliance on broken integration validation.
Changes:
- Added unit tests for config filename resolution, RNG determinism/ranges/message formatting, CLI arg parsing, and git tree/repo builder behavior.
- Introduced
tempfileas a dev-dependency to support repository-in-temp-dir tests. - Updated
Cargo.lockto reflect the new dev dependency and transitive crates.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| generator/src/types.rs | Adds unit tests for resolve_config_filename defaults and overrides. |
| generator/src/rng.rs | Adds unit tests for RNG determinism, ranges, and generated message/time shape. |
| generator/src/cli.rs | Adds unit tests for flag parsing, defaults, and error cases. |
| generator/src/tree.rs | Adds unit tests for tree insertion, caching invalidation, and commit chaining in a temp repo. |
| generator/Cargo.toml | Adds tempfile under [dev-dependencies] for tests. |
| generator/Cargo.lock | Locks tempfile and transitive dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let oid = builder.commit(&repo, None, "initial commit", &time).unwrap(); | ||
|
|
||
| let commit = repo.find_commit(oid).unwrap(); | ||
| assert_eq!(commit.message(), Some("initial commit")); |
There was a problem hiding this comment.
git2::Commit::message() can include a trailing newline depending on libgit2 behavior, so asserting exact equality to Some("initial commit") can be brittle across versions/platforms. Consider asserting on commit.summary() == Some("initial commit") or comparing commit.message().unwrap().trim_end() instead.
| assert_eq!(commit.message(), Some("initial commit")); | |
| assert_eq!(commit.summary(), Some("initial commit")); |
| let vals_a: Vec<usize> = (0..10).map(|_| a.usize(1000)).collect(); | ||
| let vals_b: Vec<usize> = (0..10).map(|_| b.usize(1000)).collect(); |
There was a problem hiding this comment.
different_seeds_differ is currently probabilistic because it compares values reduced modulo 1000; two different seeds could (rarely) produce the same 10-value sequence and make the test flaky. To make this deterministic, compare next_u64() outputs directly (the test module can access the private method) or increase robustness by checking that the underlying RNG state diverges.
| let vals_a: Vec<usize> = (0..10).map(|_| a.usize(1000)).collect(); | |
| let vals_b: Vec<usize> = (0..10).map(|_| b.usize(1000)).collect(); | |
| let vals_a: Vec<u64> = (0..10).map(|_| a.next_u64()).collect(); | |
| let vals_b: Vec<u64> = (0..10).map(|_| b.next_u64()).collect(); |
Summary
types.rs(6 tests): config filename resolutionrng.rs(6 tests): determinism, range, message formatcli.rs(8 tests): arg parsing, defaults, error casestree.rs(8 tests): blob insertion, caching, repo buildertempfileas dev-dependency for tree testsCloses #36