Documentation
¶
Overview ¶
Package gomutants exposes go-mutants' reusable mutation engine.
Open freezes a source tree in a disposable snapshot. A Workspace can run baseline commands against that snapshot and can be prepared exactly once. Preparing discovers, validates, and instruments the selected mutants and compiles the selected packages' test binaries once. The resulting Session then executes any number of mutant and test-target combinations without rebuilding or rewriting the user's source tree.
Commands are argv vectors and never pass through a shell. Directories are module-relative, GO_MUTANTS_ activation variables are reserved, temporary files and compiled binaries live outside the snapshot, and every child is supervised as a process tree. Workspace and Session both own temporary resources and should be closed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Artifact ¶
Artifact is one bounded standard fuzz-corpus file captured before a target's private execution scratch is removed.
type Catalog ¶
type Catalog struct {
WorkspaceDigest string
Digest string
ModulePath string
GoVersion string
Toolchain string
Profile string
Mutants []Mutant
Rejections []Rejection
TestPackages []string
}
Catalog is the immutable public description of one prepared session. Session.Catalog returns a deep copy.
type Change ¶
type Change struct {
Kind ChangeKind
Path string
BeforeSHA256 string
AfterSHA256 string
}
Change is one module-relative difference from the state captured when Prepare completed. Changes are returned in path order.
type ChangeKind ¶
type ChangeKind string
ChangeKind describes how a prepared snapshot moved while targets ran.
const ( ChangeAdded ChangeKind = "added" ChangeRemoved ChangeKind = "removed" ChangeModified ChangeKind = "modified" )
Snapshot change kinds.
type Command ¶
type Command struct {
// Argv is the executable followed by its arguments. No element is split,
// expanded, substituted, or interpreted by a shell.
Argv []string
// Dir is the working directory relative to the module root. Empty means
// the module root. Absolute and escaping paths are rejected.
Dir string
// Env overlays the environment frozen by Open. Each element has KEY=VALUE
// form. Activation and temporary-directory variables are reserved.
Env []string
// Timeout bounds the whole process tree. Zero uses a ten-minute safety
// default. A negative duration is invalid.
Timeout time.Duration
// OutputLimit caps retained combined stdout and stderr. The runner's safe
// default is used when this is not positive.
OutputLimit int
}
Command is one shell-free process invocation in a frozen workspace.
type CommandResult ¶
CommandResult describes a command that started. A non-zero exit and a timeout are results rather than infrastructure errors.
type ExecRequest ¶
type ExecRequest struct {
// Mutant is a full ID or an unambiguous catalog prefix.
Mutant string
// Package is an import path or one module-relative package directory.
// Empty executes the selected target in every compiled test package.
Package string
// Args are passed verbatim to each selected test binary. -test.timeout is
// reserved because the session owns both timeout layers.
Args []string
// Env overlays the environment frozen by Open for this execution.
Env []string
// Timeout overrides PrepareOptions.MutantTimeout when positive. A negative
// duration is invalid.
Timeout time.Duration
}
ExecRequest selects one mutant and one test or fuzz target from a prepared session. Args are standard Go test-binary arguments, for example `-test.run=^TestRoundTrip$` or `-test.fuzz=^FuzzRoundTrip$`.
type Mutant ¶
type Mutant struct {
Index uint32
ID string
DisplayID string
Path string
Package string
Line int
Column int
StartByte uint32
EndByte uint32
Family string
Rule string
RuleVersion int
SourceDigest string
Original string
Replacement string
Accepted bool
}
Mutant is one canonical, deduplicated source edit.
type MutantResult ¶
type MutantResult struct {
ID string
DisplayID string
Outcome Outcome
KilledBy string
Duration time.Duration
OutputTail string
Artifacts []Artifact
}
MutantResult is one execution of one mutant against the selected binaries.
type OpenOptions ¶
type OpenOptions struct {
// GoBinary selects the go executable. Empty resolves "go" through PATH.
GoBinary string
// ReportDirectory is a module-relative report directory to exclude from
// the snapshot in addition to go-mutants' conventional report directory.
ReportDirectory string
// TempDirectory is the parent for the snapshot and all session scratch
// directories. Empty uses the operating system's temporary directory.
TempDirectory string
// Env is the complete environment to freeze for child processes. Nil
// captures the current process environment. GO_MUTANTS_ and temporary
// directory variables are removed and replaced by the engine as needed.
Env []string
}
OpenOptions controls how Open freezes a workspace. Its zero value is the ordinary local invocation.
type Outcome ¶
type Outcome string
Outcome is the stable result vocabulary returned by Session.Exec.
type PrepareOptions ¶
type PrepareOptions struct {
// Profile is balanced, strong, or all. Empty selects balanced.
Profile string
// Operators, when non-empty, selects canonical operator family or rule
// names instead of Profile. The result is always in canonical order.
Operators []string
// Include and Exclude are module-relative mutation glob patterns. Excludes
// win. They select candidates and never remove files from the snapshot.
Include []string
Exclude []string
// Packages are relative Go package patterns whose test binaries are built.
// Empty selects ./....
Packages []string
// Jobs bounds concurrent test-binary builds. Zero uses min(NumCPU, 8).
Jobs int
// BuildTimeout bounds each validation and test-binary build. Zero uses ten
// minutes. A negative duration is invalid.
BuildTimeout time.Duration
// MutantTimeout is the default outer timeout used by Session.Exec. Zero
// uses ten seconds. An ExecRequest may override it with a positive value.
MutantTimeout time.Duration
// Verify is run once after instrumentation with no mutant active. Its zero
// value means `go test ./...`. Vet is disabled only for this generated tree.
Verify Command
}
PrepareOptions selects and prepares a reusable mutation session.
type Rejection ¶
type Rejection struct {
ID string
DisplayID string
Path string
Line int
Column int
Rule string
Diagnostic string
}
Rejection is a catalogued mutant that validation proved does not compile.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a discovered, validated, instrumented snapshot with test binaries compiled once. Its zero value is not usable. A Session permits concurrent Exec calls; Changes and Close wait for those calls to finish.
func (*Session) Changes ¶
Changes compares the current snapshot with the state captured after preparation. It waits for in-flight Exec calls so the result cannot observe a target halfway through a write.
func (*Session) Close ¶
Close waits for target executions and releases the session's binaries and scratch files. It is idempotent. Closing a Session does not close its parent Workspace; closing the Workspace closes both.
func (*Session) Exec ¶
func (s *Session) Exec(ctx context.Context, request ExecRequest) (MutantResult, error)
Exec runs one mutant against a selected test or fuzz target without rebuilding the prepared test binaries.
type Workspace ¶
type Workspace struct {
// contains filtered or unexported fields
}
Workspace is a frozen disposable copy of one module. Its zero value is not usable. Open constructs one and Close releases it.
func Open ¶
Open locates the Go toolchain and copies root into a disposable snapshot. At most one OpenOptions value may be supplied.
func (*Workspace) Close ¶
Close stops accepting work and removes the session scratch directory and snapshot. It is idempotent and waits for in-flight Session.Exec calls.
func (*Workspace) Exec ¶
Exec runs command against the frozen snapshot. It is available before Prepare; after instrumentation begins, commands belong to Session targets.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
go-mutants
command
Command go-mutants is the mutation testing CLI for Go modules.
|
Command go-mutants is the mutation testing CLI for Go modules. |
|
internal
|
|
|
cache
Package cache stores the outcome of one mutant so that a later run of the same code, by the same build, against the same command, need not measure it again.
|
Package cache stores the outcome of one mutant so that a later run of the same code, by the same build, against the same command, need not measure it again. |
|
cli
Package cli is the go-mutants command tree.
|
Package cli is the go-mutants command tree. |
|
config
Package config reads .go-mutants.toml and resolves it against built-in defaults and command-line flags.
|
Package config reads .go-mutants.toml and resolves it against built-in defaults and command-line flags. |
|
console
Package console renders an engine event stream as plain lines.
|
Package console renders an engine event stream as plain lines. |
|
coverage
Package coverage reads Go coverage profiles and decides which test binaries each mutant needs to be measured against.
|
Package coverage reads Go coverage profiles and decides which test binaries each mutant needs to be measured against. |
|
discover
Package discover finds the mutation candidates in a snapshot.
|
Package discover finds the mutation candidates in a snapshot. |
|
drift
Package drift identifies snapshot changes that mutation instrumentation did not make.
|
Package drift identifies snapshot changes that mutation instrumentation did not make. |
|
engine
Package engine orchestrates one mutation run and reports what it is doing through a single stream of events.
|
Package engine orchestrates one mutation run and reports what it is doing through a single stream of events. |
|
execute
Package execute builds a snapshot's test binaries once and then schedules every mutant against them.
|
Package execute builds a snapshot's test binaries once and then schedules every mutant against them. |
|
gitdiff
Package gitdiff answers one question: which lines of the workspace have changed since a given ref.
|
Package gitdiff answers one question: which lines of the workspace have changed since a given ref. |
|
glob
Package glob implements the path matching language that decides which files go-mutants mutates.
|
Package glob implements the path matching language that decides which files go-mutants mutates. |
|
gocmd
Package gocmd finds the Go toolchain and describes how to invoke it.
|
Package gocmd finds the Go toolchain and describes how to invoke it. |
|
instrument
Package instrument rewrites snapshot source bytes so that every compilable mutant of a file lives in the file at once, dormant behind a guard.
|
Package instrument rewrites snapshot source bytes so that every compilable mutant of a file lives in the file at once, dormant behind a guard. |
|
interval
Package interval composes overlapping byte spans into a forest of nested rewrite sites.
|
Package interval composes overlapping byte spans into a forest of nested rewrite sites. |
|
mutation
Package mutation holds the pure core of go-mutants: byte spans, the stable mutant identity, the operator registry, the mutant catalogue, run outcomes, the mutation score, and the exit-code policy.
|
Package mutation holds the pure core of go-mutants: byte spans, the stable mutant identity, the operator registry, the mutant catalogue, run outcomes, the mutation score, and the exit-code policy. |
|
operatorselect
Package operatorselect resolves mutation profiles, family names, and rule names against the canonical registry.
|
Package operatorselect resolves mutation profiles, family names, and rule names against the canonical registry. |
|
report
Package report is the RunReport v1 document: the lossless record of one mutation run, and the store it is kept in.
|
Package report is the RunReport v1 document: the lossless record of one mutation run, and the store it is kept in. |
|
runner
Package runner starts one child process, supervises its whole process tree, and returns what happened.
|
Package runner starts one child process, supervises its whole process tree, and returns what happened. |
|
schemas
Package schemas validates go-mutants JSON documents against the schemas embedded in the binary.
|
Package schemas validates go-mutants JSON documents against the schemas embedded in the binary. |
|
snapshot
Package snapshot copies a source tree into a disposable working directory so that mutation testing never writes to the tree a user is editing.
|
Package snapshot copies a source tree into a disposable working directory so that mutation testing never writes to the tree a user is editing. |
|
testflag
Package testflag recognises flags passed directly to a Go test binary.
|
Package testflag recognises flags passed directly to a Go test binary. |
|
testsupport
Package testsupport holds the test helpers that more than one package needs.
|
Package testsupport holds the test helpers that more than one package needs. |
|
tui
Package tui renders an engine event stream as a live dashboard.
|
Package tui renders an engine event stream as a live dashboard. |
|
validate
Package validate compiles an instrumented snapshot and finds out, one build at a time, which of its mutants are real.
|
Package validate compiles an instrumented snapshot and finds out, one build at a time, which of its mutants are real. |
|
Package schema carries the JSON Schema documents go-mutants publishes, and nothing else.
|
Package schema carries the JSON Schema documents go-mutants publishes, and nothing else. |
|
stryker
Package stryker carries the vendored mutation-testing-report schema, and nothing else.
|
Package stryker carries the vendored mutation-testing-report schema, and nothing else. |
|
Package vendorassets carries the third-party browser assets the HTML report is built from, and nothing else.
|
Package vendorassets carries the third-party browser assets the HTML report is built from, and nothing else. |