expression

package
v2.7.6 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MutatorComparison

func MutatorComparison(_ *types.Package, _ *types.Info, node ast.Node) []mutator.Mutation

MutatorComparison implements a mutator to change comparisons.

func MutatorContextNil added in v2.6.1

func MutatorContextNil(_ *types.Package, info *types.Info, node ast.Node) []mutator.Mutation

MutatorContextNil replaces context.Context arguments at call sites with nil. Mirrors ooze's context-cancellation operator.

func MutatorErrorGuard added in v2.6.1

func MutatorErrorGuard(_ *types.Package, info *types.Info, node ast.Node) []mutator.Mutation

MutatorErrorGuard replaces error-check conditions in if-statements:

if err != nil  →  if false
if err == nil  →  if true

Inspired by gomu's error-handling mutations.

func MutatorErrorfWrap added in v2.7.0

func MutatorErrorfWrap(_ *types.Package, _ *types.Info, node ast.Node) []mutator.Mutation

MutatorErrorfWrap downgrades the error-wrapping verb in Errorf-style calls:

fmt.Errorf("load config: %w", err)  →  fmt.Errorf("load config: %v", err)

The mutated message is byte-for-byte identical, but the returned error no longer wraps the cause: errors.Is and errors.As against the original error stop matching. This catches the extremely common pattern where code wraps errors with %w purely out of habit and no test ever unwraps the result — a hallmark of machine-generated Go that looks correct but pins no behaviour.

One mutation is emitted per %w verb in the format string.

func MutatorLogical

func MutatorLogical(_ *types.Package, _ *types.Info, node ast.Node) []mutator.Mutation

MutatorLogical swaps && and || operators.

func MutatorRecoverClear added in v2.7.0

func MutatorRecoverClear(_ *types.Package, _ *types.Info, node ast.Node) []mutator.Mutation

MutatorRecoverClear neutralises a recover() call by turning it into a typed nil:

if r := recover(); r != nil { ... }  →  if r := any(nil); r != nil { ... }

recover() returns any, and so does any(nil), so the rewrite type-checks in every context recover() can appear in (assignment, comparison, bare call). The difference is behavioural: the recovered value is always nil, so the guarded recovery branch never runs and a panic propagates instead of being swallowed. Deferred recover blocks are classic untested defensive code — generated "just in case" and never exercised. If this mutant survives, the panic-safety net is dead weight or, worse, silently masking real failures.

func MutatorRemoveTerm

func MutatorRemoveTerm(_ *types.Package, _ *types.Info, node ast.Node) []mutator.Mutation

MutatorRemoveTerm implements a mutator to remove expression terms.

func MutatorStringLiteral added in v2.6.7

func MutatorStringLiteral(_ *types.Package, _ *types.Info, node ast.Node) []mutator.Mutation

MutatorStringLiteral zeros non-empty string literals in equality and inequality comparisons (== and !=). This tests whether the exact string value matters — e.g. if err.Error() == "not found" where "" would pass when no error occurs but fail when the specific message is expected.

Scoped to comparisons only to avoid high-noise mutations in log messages, metric names, and other strings whose values are not asserted by tests.

Types

This section is empty.

Jump to

Keyboard shortcuts

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