Commands
The two subcommands and their options, what a mutation run does to your files, the keys of a mutation table, and the exit codes.
ostiarius count
Asserts how many tests a cargo test run passed. It either reads saved logs or runs the
command itself and reads its output.
ostiarius count [OPTIONS] -- COMMAND...
A log must hold both of Cargo’s streams, because the Running headers that name
each test binary go to stderr while the results go to stdout. Logs may be UTF-8 or UTF-16 with a
byte-order mark, so a log saved by Windows PowerShell 5.1 with > is read correctly.
PowerShell’s own 2>&1 rewrites every line on stderr, however, so in
PowerShell the streams are merged in cmd instead. Running the command through
count avoids saving a log at all, since count reads both streams on one
pipe and keeps the headers in order with the results.
cmd /c "cargo test 2>&1" > test.log
ostiarius count --min-passed 120 test.log
Options
| Option | Meaning |
|---|---|
--expect-passed N |
Exactly N tests must pass in total. |
--min-passed N |
At least N tests must pass in total. |
--min-passed-in LABEL=N |
At least N tests must pass in the test binary LABEL. It may be
given more than once. |
--allow-empty |
Do not fail when no test passed. Without it, that fails. |
--expect-names FILE |
Every test named in FILE must exist. The file holds one name per line, and
lines starting with # are comments. |
--list-mode |
With --expect-names, list the tests rather than run them, by adding
--list --format terse to the command.
|
--log PATH |
With a command, also save its output to PATH. |
--per-binary |
Print each test binary’s counts, with the labels --min-passed-in
uses. |
--json |
Print the result as one JSON object. |
A total can hide a lost module, since a binary that lost twelve tests and another that gained
twelve leave the sum unchanged. A per-binary floor or a list of expected names catches what the
total cannot, and --list-mode checks the names in seconds because nothing is
run.
$ ostiarius count --expect-names names.txt --list-mode -- cargo test -p mycrate
45 tests listed
FAILED: tests not found: parity::renamed_case
Binary labels
<target> (<stem>)Each test binary is labeled by the target Cargo names in its Running header and the
binary’s file name without its hash, such as unittests src/lib.rs (mycrate)
or tests/parity.rs (parity). Separators are always forward slashes, so a label
written on Windows also works on Linux. --min-passed-in also accepts the target
alone, such as tests/parity.rs, when only one binary has that target.
$ ostiarius count --per-binary --min-passed-in "tests/parity.rs=12" -- cargo test -p mycrate
45 passed, 0 failed, 0 ignored, in 3 test binaries
unittests src/lib.rs (mycrate): 30 passed, 0 failed, 0 ignored
tests/parity.rs (parity): 13 passed, 0 failed, 0 ignored
doctests (mycrate): 2 passed, 0 failed, 0 ignored
JSON output
--json prints one object in place of the summary, with keys in a fixed order so the
output is stable from run to run. failing, missing_names and
problems are lists of strings, and lossy is true when bytes in a log
could not be decoded and were replaced. A listed count is added in list mode, and an
error string when no result could be read.
{"ok":true,"exit_code":0,"passed":5,"failed":0,"ignored":0,
"binaries":[{"label":"unittests src/lib.rs (intervals)","passed":5,"failed":0,"ignored":0}],
"failing":[],"missing_names":[],"problems":[],"lossy":false}
The object is printed on one line. It is wrapped here only to fit the page.
ostiarius mutate
Runs the entries of one or more mutation tables. Each entry edits one file, runs its command, and passes only if the tests it names fail.
ostiarius mutate [OPTIONS] TABLE...ostiarius mutate --restore [--log-dir DIR]
Options
| Option | Meaning |
|---|---|
--id ID |
Run only this entry. It may be given more than once. |
--list |
List the entries and exit. |
--dry-run |
Check that every edit applies, then exit without building or running anything. |
--root DIR |
Use DIR as every table’s root. |
--log-dir DIR |
Where logs and saved copies go. The default is target/ostiarius. |
--timeout S |
Seconds allowed for each command run, for entries whose table sets none. |
--skip-baseline |
Do not run the baseline. Every entry then needs a timeout of its own. |
--allow-dirty |
Run even if target files have uncommitted changes. |
--restore |
Put back every file a stopped run left mutated, and exit. |
--dry-run is a cheap check to run after a refactor. When the code an entry targets
has changed, its find no longer occurs and the run stops before touching anything.
This is the table doing its job, since the entry recorded an argument about specific code and that
code has moved.
error: tables/core.toml: overlap-open: the code this entry targets has changed: "a.lo <= b.hi && b.lo <= a.hi" no longer occurs in src/interval.rs; re-examine the entry's claim against the current code, then update `find`
What a run does
A run edits source files in your working tree, so it is built to put every byte back. It goes in this order.
| Step | What happens |
|---|---|
| Load | Every table is read and checked, and all problems are reported together. |
| Refuse | The run stops, touching nothing, if saved copies remain from a run that was killed, or if a target file has uncommitted changes in a git work tree. A leftover mutation looks exactly like an uncommitted change. |
| Check edits | Every edit must apply, with each find occurring exactly once. |
| Baseline | Each distinct command runs once on the unmutated tree and must pass. Its time sets the default timeout, five times the baseline and never less than 60 seconds. |
| Entries | For each entry the file is saved under target/ostiarius/.originals/, edited,
and the command run. The file is then restored, its bytes are read back and compared, and its
modification time is set to now so Cargo rebuilds it. |
| Restored run | Each distinct command runs once more on the restored tree and must pass with at least
min_passed tests.
|
The file is restored whatever ended the command, whether the tests failed, the command outlived
its timeout or Ctrl-C was pressed. A command past its timeout has its whole process tree killed,
including any test binary still running, and Ctrl-C restores the file before the run exits with
code 130. Only a run killed outright, by closing its window or ending its process, cannot restore
its file. Its saved copy stays behind, and the next run refuses to start until
ostiarius mutate --restore has put the copies back.
Verdicts
Each entry prints one line. An entry passes only if the mutated tree built, every test in
must_fail failed, and any other failing test is listed in may_fail.
| Line | Meaning |
|---|---|
ok <id> <what>: fails <tests> |
The named tests failed, and no others did unless listed in may_fail. |
ok <id> <what>: rejected by the compiler |
An entry with expect = "compile-error" failed to build, as
required. |
FAIL <id> <what>: … nothing caught it |
No test failed. The argument is not load-bearing for these tests, or the edit misses the code they exercise. |
FAIL <id> <what>: missing […], unexpected […] |
Named tests did not fail, or other tests did. |
FAIL <id> <what>: the mutated tree did not build |
The edit broke the build. If that is the claim, the entry needs
expect = "compile-error".
|
TIMEOUT <id> <what>: … |
The command outlived its timeout. This counts as a failure, since a hang is not a named test failing. |
Every FAIL line ends with the path of the entry’s log, which holds the full
output of its command.
Mutation tables
A mutation table is a TOML file in format version 1. Top-level keys set defaults, and each
[[mutation]] section is one entry, which inherits command,
min_passed, env and timeout unless it sets them itself. The
complete table-format reference covers every key, rule and
message, and the tables below are a summary of it.
Top-level keys
| Key | Meaning |
|---|---|
version |
Required, and must be 1. |
command |
The command each entry runs, as a list of arguments or a string. |
min_passed |
The fewest tests the baseline and the restored run must pass. The default is 1. |
env |
Environment variables for every run. Values are strings. |
timeout |
Seconds allowed for each run. By default it is derived from the baseline. |
timeout_multiplier, timeout_floor |
Used for the derived timeout. The defaults are 5 and 60 seconds. |
root |
The folder that file paths are relative to and that commands run in. The
default is the table file’s own folder. |
Entry keys
| Key | Meaning |
|---|---|
id |
Required. Names the entry, and must be unique across every table in a run. |
what |
A short description, shown after the id. |
file |
Required. The file to edit, relative to the root. |
find, replace |
Required. A string, or a list of strings applied in order. Each find must occur exactly once in the text the earlier replacements left. |
must_fail |
Required. The tests the mutation must fail. It may not be empty. |
may_fail |
Tests that are allowed, but not required, to fail, for randomized tests that catch the mutation on some runs and not others. |
expect |
"tests-fail" by default, or "compile-error"
for an argument the type checker enforces. |
A find that spans lines is written with \n, and in a file whose line endings are all
CRLF it matches as \r\n, so a table written on Linux works on a Windows checkout. A
command is best written as a list of arguments, because a string is split by POSIX quoting rules
that remove the backslashes from an unquoted Windows path.
Exit codes
Both subcommands use the same codes for the same kinds of outcome, so a script can tell a failed check from a problem with the run itself.
| Code | count |
mutate |
|---|---|---|
0 |
Every check passed. | Every entry and every restored run passed. |
1 |
A test failed, the command failed, or a count or name check failed. | An entry or a restored run failed or timed out. |
2 |
No result could be read, or the log cannot be trusted. | The run was refused, a table or an edit has a problem, or a file could not be restored. |
3 |
A usage error. | A usage error. |
130 |
Ctrl-C stopped the run after restoring the file. |