cargo mutants generates mutants by inspecting the existing source code and applying a set of rules to generate new code that is likely to compile but have different behavior.
Mutants each have a "genre", each of which is described below.
FnValue genre of mutants replaces a function's body with a value that is guessed to be of the right type.
This checks that the tests:
- Observe any side effects of the original function.
- Distinguish return values.
More mutation genres and patterns will be added in future releases.
|Return type||Mutation pattern|
|empty and one-element collections|
|empty map and the product of all key and value replacements|
|Leaked empty and one-element vecs|
|Empty and one-element iterators of the inner type|
... in the mutation patterns indicates that the type is recursively mutated.
Result<bool> can generate
The recursion can nest for types like
Some of these values may not be valid for all types: for example, returning
Default::default() will work for many types, but not all. In this case the
mutant is said to be "unviable": by default these are counted but not printed,
although they can be shown with
Binary operators are replaced with other binary operators in expressions
a == 0.
Equality operators are not currently replaced with comparisons like
because they are
too prone to generate false positives, for example when unsigned integers are compared to 0.
|| are replaced with
!= which function as XNOR and XOR respectively,
although they are fairly often unviable due to needing parenthesis when the original operator does not.