mutate

package
v0.7.186 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package mutate implements mutation testing stages for chunk mutate.

Index

Constants

View Source
const (
	OpConditionalsBoundary     = "CONDITIONALS_BOUNDARY"
	OpConditionalsNegation     = "CONDITIONALS_NEGATION"
	OpArithmeticBase           = "ARITHMETIC_BASE"
	OpIncrementDecrement       = "INCREMENT_DECREMENT"
	OpInvertAssignments        = "INVERT_ASSIGNMENTS"
	OpInvertBitwise            = "INVERT_BITWISE"
	OpInvertBitwiseAssignments = "INVERT_BITWISE_ASSIGNMENTS"
)

Gremlins operator names.

View Source
const DefaultTestTimeout = 3 * time.Minute

DefaultTestTimeout caps how long a single mutation's test run may stream output before the mutation is marked as an infrastructure failure.

Variables

This section is empty.

Functions

func DetectedStack

func DetectedStack(dir string, cfg *config.ProjectConfig) string

DetectedStack is exported for use in the cmd layer.

func MutationPatch

func MutationPatch(workDir string, m Mutation) ([]byte, error)

MutationPatch computes a unified diff for mutation m without modifying any local file. The patch is suitable for applying on a synced sidecar workspace.

Types

type GoEnumerator

type GoEnumerator struct {
	// Paths to search: package dirs, files, or ./... patterns.
	// Defaults to the full workDir tree when empty.
	Paths []string
}

GoEnumerator walks Go source files and enumerates mutation candidates using the built-in operator set. No external tools required.

func EnumeratorFor

func EnumeratorFor(dir string, cfg *config.ProjectConfig) (*GoEnumerator, error)

EnumeratorFor returns the GoEnumerator for the project. It consults cfg.Environment.Stack first, then falls back to file pattern detection in dir.

func (*GoEnumerator) Enumerate

func (g *GoEnumerator) Enumerate(_ context.Context, dir string) ([]Mutation, error)

type Mutation

type Mutation struct {
	ID       string `json:"id"`
	File     string `json:"file"`
	Line     int    `json:"line"`
	Col      int    `json:"col"`
	Operator string `json:"operator"`
	Status   string `json:"status"` // RUNNABLE or NOT COVERED
	Before   string `json:"before"` // original token, e.g. "<"
	After    string `json:"after"`  // mutated token, e.g. "<="
}

Mutation is a single candidate change to production code.

type Result

type Result struct {
	Mutation Mutation
	Killed   bool   // true if the test suite caught the mutation
	Output   string // combined test output (may be truncated)
	Error    string // non-empty if setup failed (patch apply, reset, etc.)
}

Result is the outcome of running a single mutation against the test suite.

func Run

func Run(
	ctx context.Context,
	pool *sidecar.Pool,
	mutations []Mutation,
	workDir, testCmd string,
	testTimeout time.Duration,
	status iostream.StatusFunc,
) ([]Result, error)

Run computes a tiny per-mutation patch for each candidate, then dispatches test runs to the sidecar pool in parallel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL