I noticed that go-mutesting was failing to mutate equality checks (e.g., swapping == to !=). After looking through the source code, I found that an entire mutator specifically designed for this (conditional/negated) is fully implemented but is never actually compiled into the CLI binary.
The mutator is perfectly defined in mutator/conditional/negated.go and uses an init() function to register itself:
func init() {
mutator.Register("conditional/negated", MutatorConditionalNegated)
}
However, because the conditional package is never imported anywhere in the application, the Go compiler treats it as dead code and strips it from the binary. The init() function never executes, and the mutator never appears when running --list-mutators.
The Fix
This can be fixed with a single line of code. The package just needs to be anonymously imported in cmd/go-mutesting/main.go alongside the other mutator packages:
import (
// ... existing imports ...
"github.com/avito-tech/go-mutesting/mutator"
_ "github.com/avito-tech/go-mutesting/mutator/arithmetic"
_ "github.com/avito-tech/go-mutesting/mutator/branch"
+ _ "github.com/avito-tech/go-mutesting/mutator/conditional"
_ "github.com/avito-tech/go-mutesting/mutator/expression"
_ "github.com/avito-tech/go-mutesting/mutator/loop"
_ "github.com/avito-tech/go-mutesting/mutator/numbers"
_ "github.com/avito-tech/go-mutesting/mutator/statement"
)
Adding this import will activate the conditional/negated mutator, allowing the tool to properly mutate == to != (and vice-versa), which is a critical piece of mutation testing that is currently missing.
I noticed that
go-mutestingwas failing to mutate equality checks (e.g., swapping==to!=). After looking through the source code, I found that an entire mutator specifically designed for this (conditional/negated) is fully implemented but is never actually compiled into the CLI binary.The mutator is perfectly defined in
mutator/conditional/negated.goand uses aninit()function to register itself:However, because the
conditionalpackage is never imported anywhere in the application, the Go compiler treats it as dead code and strips it from the binary. Theinit()function never executes, and the mutator never appears when running--list-mutators.The Fix
This can be fixed with a single line of code. The package just needs to be anonymously imported in
cmd/go-mutesting/main.goalongside the other mutator packages:Adding this import will activate the
conditional/negatedmutator, allowing the tool to properly mutate==to!=(and vice-versa), which is a critical piece of mutation testing that is currently missing.