Skip to main content
Reference tooling 2 min read Updated

minikin-cargo-crap-main-docs-guides-regression-gate

Regression gate (recommended for teams)

Save a baseline on main, then fail on any PR that makes a score go up. On GitHub, the GitHub Action does it without a stored baseline, by scoring the pull request’s base commit in the same job. It works regardless of the absolute threshold and catches a regression when it is introduced.

--baseline puts the report in delta mode and adds a Δ column. A function that moved between files with its body unchanged is reported as Moved rather than as a New plus a Removed entry, and the renderers print ← \<previous_file\> next to its new location. --fail-regression does not count a pure relocation as a regression. Baseline entries that the current run’s --exclude, --allow or default exclusions would drop are filtered out before the comparison, so changing the exclusion set between runs does not flood the removed list. --epsilon decides how much movement counts as noise. Score deltas with absolute value at or below it (0.01 by default) are reported Unchanged. Set it to 0.0 to flag every increase, or higher when coverage numbers wobble between runs.

# On main branch — upload baseline as a CI artifact
- run: cargo llvm-cov --lcov --output-path lcov.info
- run: cargo crap --lcov lcov.info --format json --output baseline.json
- uses: actions/upload-artifact@v4
  with:
    name: crap-baseline
    path: baseline.json

# On pull requests — download baseline and compare
# NOTE: actions/download-artifact@v4 extracts to a subfolder named after the
# artifact by default — pin `path:` so the file lands somewhere predictable.
- uses: actions/download-artifact@v4
  with:
    name: crap-baseline
    path: baseline
- run: cargo llvm-cov --lcov --output-path lcov.info
- run: cargo crap --lcov lcov.info --baseline baseline/baseline.json --fail-regression

A baseline can also be committed to git instead of uploaded as an artifact. Add --sort file when generating it so entries are ordered by (file, function, line) rather than by score. The order then stays put across runs, and a code change touches only the affected entry’s fields:

cargo crap --lcov lcov.info --format json --sort file --output crap_baseline.json

In --baseline mode the human and markdown tables list only the functions that changed (Regressed, Improved, New, Moved), so pass --show-unchanged when you want the full table. The human table also caps the changed rows below the threshold at the 10 worst, though it always lists every regression (see The human table’s cap). When nothing changed at all the table is replaced with No changes since baseline., while the summary line still counts every entry. JSON stays exhaustive either way, and pr-comment keeps its own row policy. Both --show-unchanged and --fail-regression error out when --baseline is missing.

--top and --min choose only which rows are shown. The baseline is compared with every function, so the Removed list holds only functions that are gone, and the summary line and --fail-regression count changes outside the rows shown. A run with --top 10 --fail-regression can fail on a regression in the eleventh-worst function. When every change lies outside the rows shown, the table says No changes among the rows shown.

See JSON output schema for the baseline file’s format.