More granular FnValue
mutations
#360
john-h-kastner
started this conversation in
Ideas
Replies: 1 comment
-
Yep, this sounds like a great extension, and a patch or series of patches to do it would be welcome. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This idea is an extension to the current function value replacement mutations. In brief: instead of replacing whole function bodies
cargo-mutants
would replace one branch at a time to obtain more granular mutants. I've implemented and been trying out these changes on a local build already, so I can polish everything and put up a PR pretty quickly if you like the idea.Motivating Example
A function recursively visiting a data structure will often look something like this.
The current function value mutation replace the whole function body.
Killing this mutant doesn't tell us if our tests exercise all the branches. With this idea,
cargo-mutants
would instead find and replace each expression in "return position". In this function, it would mutate each branch of thematch
independently, so we could be confident that every branch is exercised by our tests.For example,
cargo-mutants
would generate a mutant replacing the expression in theMinus
branch. Detecting this mutant requires at least one test case properly exercisingMinus
while the original mutant would be detected by any test properly exercising theeval
function, even if it never constructed aMinus
.Details
Extend function value rewriting is a recursive procedure with the following cases:
if
expression, we recursively generate mutants for both branches, but do not rewrite the condition.match
expression we recursively generate mutants for allmatch
arms, but do not rewrite the matched expression.return_type_replacements
procedure.In the following example, the block and
if
cases work together to allow replacing just the finalelse
branch without touching anything else. Note that thethen
branch uses the localb
, which we have left untouched.Implemented as a separate pass,
cargo-mutants
should also find explicitreturn
statements and and mutates the returned value. I expect that early returns tend to handle uncommon cases and error conditions, so it is important that they are exercised by a test-suit. Implementing this properly requires some additional book-keeping to track if the visitor is inside a closure.Drawbacks
There are some cases where the more granular mutation breaks type inference for local variable bindings. In the following function, Rust cannot infer a collection type for
s
if it is not returned. The whole body function mutation deletess
, so type inference is not an issue.Beta Was this translation helpful? Give feedback.
All reactions