Unleash¶
The main command used in Gremlins is unleash, that unleashes the gremlins and starts a mutation test of your code.
If unleash is too long to type for you, you can use its aliases run and r.
To execute a mutation testing run just type
gremlins unleash
If the module build requires tags
gremlins unleash --tags "tag1,tag2"
Gremlins mutates only the files the go command compiles with these tags on the current GOOS and GOARCH. A file
whose //go:build line is false there, or whose name ends in another platform's _GOOS or _GOARCH suffix (such as
proc_windows.go on Linux), is left out of the run: no test run there can reach its code, so its mutants would
only count as not covered. To test such a file, run Gremlins where it is built, or with the tag that builds it.
Flags¶
unleash supports several flags to fine tune its behaviour.
Arithmetic base¶
--arithmetic-base · Default: true
Enables/disables the ARITHMETIC BASE mutant type.
gremlins unleash --arithmetic-base=false
Conditionals-boundary¶
--conditionals-boundary · Default: true
Enables/disables the CONDITIONALS BOUNDARY mutant type.
gremlins unleash --conditionals_boundary=false
Conditionals negation¶
--conditionals-negation · Default: true
Enables/disables the CONDITIONALS NEGATION mutant type.
gremlins unleash --conditionals_negation=false
Cover packages¶
--coverpkg · Default: empty
Apply coverage analysis in each test to packages matching the patterns. The default is for each test to analyze only the package being tested.
gremlins unleash --coverpkg "./internal/...,./pkg/..."
Coverage profile¶
--coverage-profile · Default: empty
Reuses a pre-computed Go coverage profile instead of gathering coverage.
Gremlins normally starts by running the whole test suite to find out which code is covered, since there is no point mutating code no test exercises. A caller that has just run that suite itself — a CI pipeline with its own coverage gate, for instance — is paying for it twice, and on a large suite the coverage run can cost more than the mutation testing that follows it.
The profile must describe the current state of the source, so it is up to the caller to be sure it is fresh: Gremlins reads it as given. A stale profile silently mutates the wrong lines.
Requires --coverage-elapsed.
go test ./... -coverprofile coverage.out -count=1
gremlins unleash --coverage-profile coverage.out --coverage-elapsed 2m42s
Coverage elapsed¶
--coverage-elapsed · Default: empty
How long the test run that produced --coverage-profile took.
Gremlins derives the per-mutant timeout from the duration of the coverage run
(see Timeout coefficient), which it cannot measure when
it did not perform that run. Supplying a duration far below the real one makes
mutants that the tests do in fact kill get reported as TIMED OUT instead.
The value is any Go duration string.
gremlins unleash --coverage-profile coverage.out --coverage-elapsed 90s
Exclude files¶
--exclude-files/-E · Default: empty
Allows to exclude generated or not important files.
If a file path matches a regular expression, it is skipped from execution and threshold calculation.
The default is to skip only test files.
gremlins unleash --exclude-files "_(gen|wrap).go"
You can provide a few rules. File is skipped if matches any regexp.
gremlins unleash -E "_(gen|wrap).go$" -E "^(generate|wrap)/" -E "internal/super_old/"
Diff¶
--diff/-D · Default: empty
Run tests only for mutants inside code changes between current state and git reference (branch or commit). The default is each mutant covered by tests.
Branch merge base¶
gremlins unleash --diff "origin/main"
Commit¶
gremlins unleash --diff "b62af323"
PR¶
gremlins unleash --diff "origin/$GITHUB_BASE_REF"
Use actions/checkout@v4 with fetch-depth: 0 to fetch all history.
Dry run¶
--dry-run/-d · Default: false
Just performs the analysis but not the mutation testing.
gremlins unleash --dry-run
Statuses output¶
--output-statuses/-S · Default: empty - show all
Filters stdout to print only statuses from flag. Useful to filter important findings in big project output.
Alternative to gremlins r | grep LIVED configured from file.
Flag do not change json file and stats report content.
Examples¶
Show only LIVED and NOT COVERED¶
gremlins unleash --output-statuses "lc"
Output
LIVED CONDITIONALS_BOUNDARY at aFolder/aFile.go:12:3
NOT COVERED CONDITIONALS_BOUNDARY at aFolder/aFile.go:12:3
Filter out out SKIPPED, KILLED.¶
gremlins unleash --S lctv
Output
LIVED CONDITIONALS_BOUNDARY at aFolder/aFile.go:12:3
NOT COVERED CONDITIONALS_BOUNDARY at aFolder/aFile.go:12:3
NOT VIABLE CONDITIONALS_BOUNDARY at aFolder/aFile.go:12:3
TIMED OUT CONDITIONALS_BOUNDARY at aFolder/aFile.go:12:3
Filter letters¶
l- LIVEDc- NOT COVEREDt- TIMED OUTk- KILLEDv- NOT VIABLEs- SKIPPEDr- RUNNABLE
Diff statuses output¶
--output-diff-statuses · Default: empty - no diffs shown
Prints a unified diff of the original vs mutated code snippet for mutants whose status matches
the filter. Only l (LIVED) and k (KILLED) are accepted — other statuses are not valid because
diffs are only meaningful for mutants that were actually executed and had their source changed.
This flag works in combination with --output-statuses: a mutant that is hidden by
--output-statuses will produce no output at all — no status line and no diff.
Examples¶
Show diff for survived mutants¶
gremlins unleash --output-diff-statuses l
Output
LIVED CONDITIONALS_BOUNDARY at aFolder/aFile.go:12:3
-x > y
+x >= y
Show diff for both lived and killed mutants¶
gremlins unleash --output-diff-statuses lk
Filter letters¶
l- LIVEDk- KILLED
Increment decrement¶
--increment-decrement · Default: true
Enables/disables the INCREMENT DECREMENT mutant type.
gremlins unleash --increment-decrement=false
Integration mode¶
--integration/-i · Default: false
In normal mode, Gremlins executes only the tests of the packages where the mutant is found. This is done to optimize the performance, running less test cases for each mutation.
The drawback of this approach lies in the fact that if a mutation in a package influences the tests of another package, this is not caught by Gremlins. In general, this is an acceptable drawback because packages should rely on their own tests, not on the tests of other packages.
Nonetheless, there may be cases where you may want to run all the test suite for each mutation, for example if you are analysing integration or E2E tests. In this scenario, you can enable integration mode. However, you should be aware that integration mode is generally much slower, and you can also get slightly different results depending on your test suite.
gremlins unleash --integration
Invert assignments¶
--invert-assignments · Default: false
Enables/disables the INVERT ASSIGNMENTS mutant type.
gremlins unleash --invert-assignments
Invert bitwise¶
--invert-bitwise · Default: false
Enables/disables the INVERT BITWISE mutant type.
gremlins unleash --invert-bitwise
Invert bitwise assignments¶
--invert-bwassign · Default: false
Enables/disables the INVERT BWASSIGN mutant type.
gremlins unleash --invert-bwassign
Invert logical operators¶
--invert-logical · Default: false
Enables/disables the INVERT LOGICAL mutant type.
gremlins unleash --invert_logical
Invert loop control¶
--invert-loopctrl · Default: false
Enables/disables the INVERT LOOP mutant type.
gremlins unleash --invert-loopctrl
Invert negatives¶
--invert-negatives · Default: true
Enables/disables the INVERT NEGATIVES mutant type.
gremlins unleash --invert_negatives=false
Output¶
--output/-o · Default: empty
When set, Gremlins will write the give output file with machine readable results.
gremlins unleash --output=output.json
The output file in JSON format and has the following structure:
{
"go_module": "github.com/go-gremlins/gremlins",
"test_efficacy": 82.00,
//(1)
"mutations_coverage": 80.00,
//(2)
"mutants_total": 100,
"mutants_killed": 82,
"mutants_lived": 8,
"mutants_not_viable": 2,
//(3)
"mutants_not_covered": 10,
"elapsed_time": 123.456,
//(4)
"files": [
{
"file_name": "myFile.go",
"mutations": [
{
"line": 10,
"column": 8,
"type": "CONDITIONALS_NEGATION",
"status": "KILLED"
}
]
}
]
}
- This is a percentage expressed as floating point number.
- This is a percentage expressed as floating point number.
- NOT VIABLE mutants are excluded from all the calculations.
- The elapsed time is expressed in seconds, expressed as floating point number.
Warning
The JSON output file is not pretty printed; it is optimised for machine reading.
Remove self-assignments¶
--remove-self-assignments · Default: false
Enables/disables the REMOVE_SELF ASSIGNMENTS mutant type.
gremlins unleash --remove-self-assignments
Tags¶
--tags/-t · Default: empty
Sets the go command build tags.
gremlins unleash --tags "tag1,tag2"
Test CPU¶
--test-cpu · Default: 0
Tip
To understand better the use of these flag, check workers
This flag overrides the number of CPUs the Go test tool will utilize. By default, Gremlins doesn't set this value.
gremlins unleash --test-cpu=1
Threshold efficacy¶
--threshold-efficacy · Default: 0
When set, it makes Gremlins exit with an error (code 10) if the test efficacy
is below the threshold. The threshold is satisfied when the actual efficacy is
greater than or equal to the configured value (so --threshold-efficacy 100
is met when every reached mutant is killed). By default it is zero, which
means Gremlins never exits with an error.
The test efficacy is calculated as KILLED / (KILLED + LIVED) and assesses how effective are the tests.
gremlins unleash --threshold-efficacy 80
Threshold mutant coverage¶
--threshold-mcover · Default: 0
When set, it makes Gremlins exit with an error (code 11) if the mutant coverage is below the threshold. The threshold is satisfied when the actual coverage is greater than or equal to the configured value. By default it is zero, which means Gremlins never exits with an error.
The mutant coverage is calculated as (KILLED + LIVED) / (KILLED + LIVED + NOT_COVERED) and assesses how many mutants
are covered by tests.
gremlins unleash --threshold-mcover 80
Timeout coefficient¶
--timeout-coefficient ·
Default: 0 (uses default value of 5)
Tip
To understand better the use of these flag, check workers
Gremlins determines the timeout for each Go test run by multiplying by a
coefficient the time it took to perform the coverage run. The default
coefficient is 5, which can be overridden with this flag (0 means use
the default).
To ensure reasonable timeouts even when the coverage run is very fast, Gremlins enforces a minimum base timeout of 1 second before applying the coefficient. For example:
- Coverage run takes 500ms → timeout = max(500ms, 1s) × 5 = 5 seconds
- Coverage run takes 2s → timeout = 2s × 5 = 10 seconds
gremlins unleash --timeout-coefficient=10
Timeout min¶
--timeout-min · Default: 0s
A floor under each mutant's timeout:
timeout = max(coverage time × coefficient, timeout-min). Use it when a fast
suite gives a bound too tight for mutants that hit slower failure paths.
The value needs a unit, such as 30s or 2m. Gremlins rejects a bare number
like 30, and 0 (the default) means no floor.
gremlins unleash --timeout-min=30s
Result Consistency
You may observe small fluctuations in the number of killed/lived/timed-out mutants between runs (typically ±2-4 mutants). This is normal and can be caused by: - Race conditions: Mutations may introduce or remove race conditions that behave differently each run - Timing-sensitive tests: Tests involving timeouts, concurrency, or I/O timing - System variations: CPU scheduling, system load, and other OS-level factors These minor variations do not indicate a problem with the mutation testing process. Large variations or progressive degradation would indicate an issue.
Workers¶
--workers · Default: 0
Tip
To understand better the use of these flag, check workers
Gremlins runs in parallel mode, which means that more than one test at a time will be performed, based on the number of CPU cores available.
By default, Gremlins will use all the available CPU cores of, and , in integration mode, it will use half of the available CPU cores.
The --workers flag allows to override the number of CPUs to use (0 means use the default).
gremlins unleash --workers=4