Bug with --disable-mutation-types and --enable-mutation-typesSee original GitHub issue
Hi I have been testing out the new commands since they are quite useful. However I found some bugs related to them.
Here is a testProgram for mutation purpose
def testfunction(): array['a'] = 123
I run this command after building v2.3
mutmut run --enable-mutation-types=number --paths-to-mutate testFunction.py
mutmut show all
and here is the output:
To apply a mutant on disk: mutmut apply <id> To show a mutant: mutmut show <id> Survived � (1) ---- testFunction.py (1) ---- # mutant 1 --- testFunction.py +++ testFunction.py @@ -1,3 +1,3 @@ def testfunction(): - array['a'] = 123 + array['XXaXX'] = 123
This seems like a string mutation and not a number mutation, the correct number mutation after taking a brief look at the source code shoule be something like
array['a'] = 124
You can get a similar “wrong” output when you run
I am not very familar with the code base but I think this bug has something to do with overwriting mutations? see these lines https://github.com/boxed/mutmut/blob/cc7e7825a8a2ca0d5abb5f4748aa8c8ccea7f0f7/mutmut/__init__.py#L629-L643
- Created 2 years ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
Oh, this is really a bug. Thanks @brutalsavage for being the beta tester for this! 😀
mutmut show shows a completely wrong mutant. Not only that it does not know about the enabled/disabled mutation types - it really shows the wrong mutant, not just one that was not run.
In the given example, the only mutant which is performed and run is changing the number to
If we don’t have any tests for this,
mutmut run will correctly report “1/1 SURVIVED”.
But when you then run
mutmut show all, it again lists only one surviving mutant, but this time it shows the mutant
I have to dig deeper how the mutants are cached and identified later on.
Putting the value in the config at least does not help with the most recent version where I refactored to Click’s subcommands. I have to double check if this is different for V2.2.0.
mutmut computes an array of possible mutations for each source code line.
The cache stores the
line and the
index (that is: the index in the array of possible mutations):
class Mutant(db.Entity): line = Required(Line) index = Required(int) tested_against_hash = Optional(str, autostrip=False) status = Required(str, autostrip=False) # really an enum of mutant_statuses
In my original implementation for
--enable-mutation-types I returned too early from the
mutate_node method and broke this indexing mechanism.
With the linked PR
mutmut now correctly identifies all possible mutations again, but simply does not perform a mutation if it does not belong to the desired mutation types.