test(lorm-macros): improve mutation coverage (47% → 93.75%) - #51
Merged
Conversation
…tion coverage Add 46 unit tests across attributes, models, column, utils, and orm modules to kill survived mutants identified by cargo-mutants. Mutation score improves from 47% (67/143) to 68.5% (98/143): - attributes.rs: table_name/pk_selector_name/has_relations/field accessor logic - utils.rs: to_column_type Option stripping, String→str conversion, constraints - orm/column.rs: should_generate_query_function branching conditions - models.rs: PrimaryKey variants, update/insert/query column filters - Also bless stale trybuild snapshot for has_many_no_as_for_self (compiler wording change) Note: codegen functions (generate_by, generate_delete, generate_select, etc.) cannot be unit-tested directly from within the proc-macro crate as darling/quote require the proc_macro2 bridge active during macro expansion.
… targeted integration tests
- Add .cargo/mutants.toml with test_workspace=true so cargo-mutants runs
lorm integration tests for every lorm-macros mutant; this catches all
codegen function mutations (generate_by, generate_delete, generate_select,
generate_with, generate_save, generate_belongs_to, generate_has_relations)
without needing any new unit tests for those functions
- Add Tag#[lorm(by)] on pk field + TagRef struct (no #[lorm(by)] on pk) and
test_tag_by_name_pk_selector to cover the dedup logic in generate_by that
prevents duplicate method generation when pk_selector == by_{pk_field}
- Remove unused 'parse' import from utils.rs and tidy test module in models.rs
Mutation score: 68.5% -> 93.75% (30/32 viable mutants caught; 2 remaining
are untestable dead-code paths)
- Update has_many_no_as_for_self.stderr to match rustc 1.96 error wording
('the type must implement Default' vs 'cannot satisfy _: Default')
- Fix formatting of struct literal and long parse_str line
- Remove TagRef from mysql models block (unused, would fail with -D warnings);
TagRef is only needed in the sqlite/postgres block where it's exercised by
test_tag_by_name_pk_selector
Format long lines and struct literals to conform to rustfmt style. Required after Rust toolchain update from 1.92 to 1.96 which changed some formatting decisions.
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
Adds unit tests and testing infrastructure to to significantly improve mutation testing coverage.
Approach
Problem:
cargo-mutantswas only runninglorm-macrostests when evaluating each mutant, so mutations to codegen functions (generate_by,generate_delete, etc.) appeared missed even though the generated code is exercised bylorm's integration tests.Solution:
.cargo/mutants.toml— addstest_workspace = trueso cargo-mutants runs all workspace tests (includinglorm's integration tests) for every mutant inlorm-macros. This immediately catches all codegen function mutations.Unit tests in
lorm-macros(46 tests) — covers darling-parsed types, utility functions, column logic, and ORM model building that can be tested without the proc_macro2 bridge.Integration test coverage — adds
Tag#[lorm(by)]on pk field +TagRefstruct (no#[lorm(by)]on pk) +test_tag_by_name_pk_selectorto cover the dedup logic ingenerate_bythat prevents duplicate method generation.Mutation Score Progression
Remaining 2 Untestable Mutants
attributes.rs:158— deadMeta::Pathbranch inRelationTarget::from_metanever reached under normal attribute parsingmodels.rs:228— redundant||guard where the inner checks handle the same invalid-input casesThese represent inherently untestable code paths, not coverage gaps.