Documentation
¶
Overview ¶
Package mutator defines the Mutator function type and the registration mechanism used by all built-in and third-party mutation operators.
Implementing a custom operator requires three steps:
- Write a function with the Mutator signature.
- Call Register from an init() function so it is available at startup.
- Import your package (blank import) in a fork of cmd/go-mutesting/main.go.
Example:
func init() {
mutator.Register("mypkg/flip-sign", flipSign)
}
func flipSign(_ *types.Package, _ *types.Info, node ast.Node) []mutator.Mutation {
n, ok := node.(*ast.UnaryExpr)
if !ok || n.Op != token.SUB {
return nil
}
return []mutator.Mutation{
{Change: func() { n.Op = token.ADD }, Reset: func() { n.Op = token.SUB }},
}
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Mutation ¶
type Mutation struct {
// Position is the source position of the original syntax changed by this
// mutation. MutateWalkWithPositions falls back to the visited node position
// when it is unset, preserving compatibility with third-party mutators.
Position token.Pos
// Change is called before executing the exec command.
Change func()
// Reset is called after executing the exec command.
Reset func()
}
Mutation defines the behavior of one mutation
Directories
¶
| Path | Synopsis |
|---|---|
|
Package composite holds mutators that operate on composite literals (struct, map, and keyed array/slice literals).
|
Package composite holds mutators that operate on composite literals (struct, map, and keyed array/slice literals). |
Click to show internal directories.
Click to hide internal directories.