mbj / mutant

Automated code reviews via mutation testing - semantic code coverage.
Other
1.95k stars 153 forks source link

Equivalent mutation on modulo operation involving integer literal #272

Open deniciocode opened 9 years ago

deniciocode commented 9 years ago

The mutant changes variables in modulo calculations. E.G.

final_sum.modulo(10).zero?

will be changed into

final_sum.modulo(-10).zero?

I think on modulo it make no sense to check the negative part. Or do I make a mistake on using the modulo for mutant?

mbj commented 9 years ago

@DenniJensen You did no mistake, and mutant did no mistake. You just found a case where the mutated semantics of a negated literal are the same as the original because of combination with the Fixnum#zero? operator. Summary: You found an equivalent mutant.

I can do something about this, but the decision is not easy and needs a bit of a wider scope.

One option would be to special case the mutation emitter to NOT emit literal negations in case the method selector is modulo inside another method call to zero?.

Problem is here: With just processing at the AST I do not know if Fixnum#modulo was called as receiver of Fixnum#zero? with skipping this specific mutation emit I might case blind spots that are valid for other cases. (Ruby does not tell me which exact objects are in use at the AST level). And I do not want to write a ruby interpreter for obvious reasons ;)

Another option would be to question if the mutation of integer literals to its negated version is actually a good mutation. I never saw an alive valid mutant where this mutation showed me a weak spot in my code / test. We currently do a series of mutations to integer literals that might already include the semantics of the negated version: https://github.com/mbj/mutant/blob/master/meta/int.rb.

Also you should have the option to ignore this specific mutation instance from your coverage analysis.. Mutant contains the code path for such exclusions but its right now not connected to the CLI or the (missing) configuration file.

I'll keep this ticket open till skipping specific mutation instances is possible, and or something other relevant to this behavior happens. And feel free to discuss this issue here.