Command line
On this page
gomagi run [flags] [packages]
gomagi --version
gomagi --help
Packages are go package patterns such as ./..., the default, or ./shell. Flags take two dashes and may come before, between or after the packages; -- ends them.
Flags #
| Flag | Meaning |
|---|---|
--workers N | test binaries run at the same time (default: half the CPUs); on Linux, ones whose tests mostly wait count as a part of one, up to 8 per worker |
--covering-only | report a mutant the covering tests let live as lived without running the whole suite; faster, but misses kills by tests whose coverage is not recorded, such as tests that run a built binary |
--diff REV | mutate only the lines changed since the git revision REV, such as origin/main |
--exclude REGEXP | leave out the files whose path relative to this directory, with slashes, the regular expression matches, such as ‘_gen.go$’ or ‘^cmd/’; may repeat |
--exclude-mutators LIST | leave out the kinds of mutant LIST names, comma separated, each as the report names it in lower case with dashes, such as invert-bitwise; may repeat |
--tags TAG,... | build tags |
--output FILE | also write a report to FILE: HTML when FILE ends in .html, JSON otherwise |
--matrix | run every covering test of a mutant and report which tests kill which mutants |
--shard K/N | run only the K-th of N equal parts of the mutants, for N parallel CI jobs |
--verify N | per package, compile N switched mutants on their own and fail when an outcome differs |
--cache | reuse the result of a package whose code, tests, go.mod and flags have not changed since a run with –cache, kept in the user cache directory |
--min-score P | exit 3 when the mutation score, killed / (killed + lived), is below P percent; a run with no killed or lived mutant passes unless some are not covered |
--min-coverage P | exit 3 when the share of mutants some test reaches, killed, lived or timed out, is below P percent |
--memory-limit MIB | stop a test process that holds more than MIB MiB, 0 for no limit; the mutant counts as killed (default 4096) |
--version | print the version |
--help | print this help |
–covering-only #
By default a mutant that the tests covering its line let live runs against the whole suite of its package, in the usual order, before it is reported as lived. That catches a kill by a test whose coverage is not recorded, such as one that runs a built binary in a child process, or by a test that reads state a covering test left behind. --covering-only skips that step; Compare shows what it saves on three packages.
–shard #
The parts follow the import paths of the packages and the source order of the mutants, so every job of a matrix selects the same split, and the parts together hold every mutant once. A package with no mutant in a part is not built by that job.
–verify #
Most mutants run inside one shared test binary. --verify N compiles N of them per package as separate binaries, the way a tool without a shared binary would, and fails the run when an outcome differs and each side repeats it on a second run. It checks gomagi’s rewriting on your code; a difference that does not repeat comes from a flaky test and is only named in a note.
Exit status #
| Code | Meaning |
|---|---|
| 0 | the run finished and the score is at or above --min-score |
| 1 | the run failed, for example a package whose tests fail without any mutant, or --verify found a difference |
| 2 | the command line is invalid |
| 3 | the mutation score is below --min-score |
A package that cannot be mutated is reported after the others finish; its failure sets exit code 1.
Progress #
On a terminal gomagi writes a row per package, named within its module, with one mark per mutant as it finishes: . killed, L lived, T timed out, x not viable. Killed marks are green, lived marks red and timed-out marks yellow, and the summary colors the same counts, unless NO_COLOR is set. The width follows COLUMNS, or 80. Written to a pipe or a file, as in CI, the progress is one line per package and per note. Packages appear in the order they start, the one with the most mutants first, so the first is reported while it runs.
Notes include a package that stopped, as soon as it stops, tests that fail when run alone, packages whose tests collide with each other, and files the mutants wrote into the package directory that gomagi removed, restored or moved, with where it moved them. How it works explains each of them.
Reports #
The summary goes to standard output: the lived mutants, then the totals.
--output report.json writes the results in the mutation-testing-report-schema of Stryker, version 2, which the mutation-testing-elements viewer and the Stryker dashboard read. files maps each path, relative to the directory gomagi runs in, to its source and its mutants, each with an id, its kind as mutatorName, the replacement, its location and a status: Killed, Survived (LIVED in the text summary), NoCoverage, Timeout or CompileError (NOT VIABLE). killedBy lists the tests that failed, and statusReason says when the tests ran out of memory. gomagi adds rebuilt, for a mutant compiled on its own, and suiteOnly, for one only the whole suite killed. performance holds the build, coverage and mutation milliseconds summed over the packages, and framework the gomagi version. Columns count UTF-16 code units, as the viewer does.
--output report.html writes one self-contained page: the totals, then each file with the lines that hold mutants, their source and the outcome and killing tests of each mutant. Files with a lived mutant start expanded.
--matrix adds, per package, the number of mutants each test kills and the number no other test kills. A test that kills nothing alone adds no detection the rest of the suite lacks.