cargo-mutants icon indicating copy to clipboard operation
cargo-mutants copied to clipboard

v25.0.1 match arms and guards are mutated in excluded functions

Open jamillambert opened this issue 7 months ago • 1 comments

The new mutation patterns that delete match arms or replace match guards with true/false are applied in sections that have been excluded, e.g. exclude_re = ["impl Debug"].

I have added "match arm" and "match guard" to the exclusion list to overcome it, but ideally they would be shown for other areas. I think testing these is a good idea if it can be modified so that excluded implementations, functions etc. exclude the whole block from any further mutations.

jamillambert avatar Apr 29 '25 10:04 jamillambert

The immediate cause here is that the exclude_re matches against the mutant name, and these mutants don't include the impl/fn name.

So I think there are two possibly complementary fixes:

  1. Include the type/impl/fn names in all mutant names, which may anyhow just make them easier to quickly read.
  2. Perhaps have separate "exclude impls of this type" (e.g., Debug) and then just don't walk into them at all, rather than matching the names. This does add more configuration options but it's also more precise.

I'll also mention that it's often easy and perhaps useful to write tests for custom Debug impls although I can also see how people might not feel it's a priority.

sourcefrog avatar May 04 '25 16:05 sourcefrog

Nice. The fix is good. We have removed the match arm and guard excludes from our mutation testing in https://github.com/rust-bitcoin/rust-bitcoin/pull/4654 and it's working as expected.

jamillambert avatar Jul 02 '25 13:07 jamillambert

Great, thanks for letting me know.

sourcefrog avatar Jul 04 '25 17:07 sourcefrog