test: add unit tests for metadata, cache, project, and logging data paths#668
Closed
MatthewMckee4 wants to merge 1 commit intomainfrom
Closed
test: add unit tests for metadata, cache, project, and logging data paths#668MatthewMckee4 wants to merge 1 commit intomainfrom
MatthewMckee4 wants to merge 1 commit intomainfrom
Conversation
Merging this PR will not alter performance
|
Member
Author
|
Superseded by #670 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds targeted unit tests to the pure-data crates where filesystem and process state are irrelevant. Integration tests still cover end-to-end behavior, but several classes of regressions (config merge precedence, cache pruning order, duration formatting boundaries, path resolution on unusual inputs) are hard to exercise from the CLI, so these unit tests pin them down at the source.
karva_metadatacrates/karva_metadata/src/options.rspreviously had no unit tests for the TOML parser,Combinederive, or thefail_fast/max_failprecedence added in #666. The new tests parse a nested[test] / [terminal] / [src]document and walk through the resultingProjectSettings, and they assert that an unknown key or an unknown top-level section is rejected (the struct usesdeny_unknown_fields, so a future accidental removal would silently accept garbage config). A dedicated test confirms thatto_settingstreatsfail_fast = trueasmax_fail = 1, thatfail_fast = falseis unlimited, and — importantly — that an explicitmax_failwins when both are set:There is also a regression test for
max-fail = 0: becauseMaxFailwrapsNonZeroU32, the deserializer must reject the literal zero rather than silently collapsing tounlimited. Finally there areCombinetests that assert CLI values win over config file values for scalars and thatVec-typed fields likeSrcOptions::includeconcatenate file entries before CLI entries (so CLI precedence works by tail position).karva_cachecrates/karva_cache/src/cache.rsgains coverage forwrite_last_failed/read_last_failed(round trip, overwrite, missing file returns empty, cache dir is created on write) and forprune_cache. The most useful test isprune_cache_keeps_newest_even_when_names_are_lexicographically_out_of_order:run-9sorts lexicographically afterrun-100, so a naive string sort would delete the newest run. This test locks in the numericsort_keybehavior. There are also tests thatprune_cacheignores non-run-*entries, that it handles a missing cache directory, and thatclean_cachereports whether it actually removed anything.aggregate_results_merges_failed_tests_and_durations_across_workersexercises the failed-test and duration merge paths that the existing stats-merge test did not touch.karva_projectcrates/karva_project/src/path/utils.rsalready tested the basicabsolutecases. The new tests cover the edge cases integration tests cannot reliably reach: an empty relative input falls back to cwd,../..past the filesystem root stays at/instead of producing..in the result, Unicode path components (カルヴァ/ユーザー) and paths with spaces round-trip unchanged, a trailing slash is normalized away, and.resolves to the cwd.karva_loggingcrates/karva_logging/src/time.rshad no tests at all.format_durationis one of the most visible output formats in the tool, and it has a subtle< 2scutoff — the new tests cover0, sub-millisecond (truncates to0ms), the exact one-second boundary (1000ms, still in ms),1999ms, the2.00sswitch to seconds, and a larger value like125.00s. A rounding test pins down the two-decimal formatter (the behavior is banker's rounding via{:.2}, which surprised me — see follow-ups).format_duration_bracketedgets width/padding tests at zero,15ms, and a large value that overflows the usual8.3width.Follow-ups
While writing the tests I noticed that
format_duration's two-decimal formatting uses the standard{:.2}formatter, which uses banker's rounding (2.345formats as2.34, not2.35). This is fine but worth knowing if anyone ever tries to snapshot-test a duration near a rounding boundary. No code change required.Test Plan
cargo test -p karva_metadata -p karva_cache -p karva_project -p karva_logging --libjust test(866 passed)uvx prek run -a