Skip to content

conditional/negated mutator is fully implemented but never registered in main.go #55

@danrneal

Description

@danrneal

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions