| title | behave commands, spec format and CI notes |
|---|---|
| description | Command reference, the YAML spec layout, how recordings stay deterministic, and notes on the example CI jobs. |
This page is the CLI reference for behave: every command, the YAML spec layout, how recordings stay deterministic, and notes on the example CI jobs.
| command | what it does |
|---|---|
behave probe <cmd> |
discover flags, generate and record cases (--arg, --inputs text|json|both, --max, --skip-flag, --sample-files, --dry-run) |
behave record <spec> |
re-record expectations from the original |
behave add <spec> -- ARGS |
add one hand-written case |
behave run <spec> |
replay against the original |
behave diff <spec> --impl <bin> |
replay against another implementation (--ignore-stderr, --ignore-exit, --tag, --skip-tag, --json, --junit file, -v) |
behave coverage <spec> |
which documented flags (from --help/man) the cases exercise (--min PCT, --all, --json) |
behave normalizers |
list built-in normalizers |
behave mcp |
serve the same features over stdio (see MCP) |
run and diff exit with 1 when any case fails, so they drop straight into CI. Pass --junit report.xml to write a JUnit XML report for CI dashboards.
For tools that need a positional argument, pass samples with --arg:
behave probe jq --arg . --arg '.a' --arg keys--skip-flag and --max cut the set down when a tool is large or unsafe to probe in full.
When the help text lists the values a flag accepts, probe adds one case per value next to the invalid-value cases. It understands GNU style (WHEN can be: auto, always, never), clap's [possible values: ...], argparse's {json,yaml} and <fast|safe>. It only keeps plain lowercase lists it can tie to that flag. --dry-run shows what it found:
$ behave probe ls --dry-run
--color WHEN {always,auto,never}
--sort WORD {none,size,time,version,extension,name,width}
coverage tells you what a spec doesn't test yet. It reads flags the same way probe does, understands --long=value, unambiguous long prefixes and clustered short flags (-sf1), and exits 1 with --min 80 when coverage drops below 80%:
$ behave coverage examples/cut
cut: 27 cases exercise 7 of 12 documented flags (58%)
not exercised (5): -n --zero-terminated --help --version -M
used but not in help: --no-such-flag
A spec is a directory you can commit and review:
behave-cut/
behave.yaml # command, timeout, normalizers, recorded_from (--version line)
cases/
0001-help.yaml
0135-flag-output-delimiter-value-1-arg-f1.yaml
...
name: flag --output-delimiter, value -1, arg -f1
args: [--output-delimiter, "-1", -f1]
stdin: |
hello
tags: [flag-value, "flag:--output-delimiter"]
expect:
exit: 0
stdout: |
hello
stderr: ""Cases can also set env, files (created in a fresh temp dir), and timeout_ms. Add your own with behave add behave-cut --stdin 'a,b' -- -d, -f2. behave.yaml stores the version of the tool you recorded (recorded_from), and run / diff print it next to the version being replayed.
- every case runs in a new temp directory with a fixed environment (
LC_ALL=C.UTF-8,TZ=UTC,NO_COLOR=1,HOME=temp dir) - input files get fixed modification times, and tools that read the current directory (
ls,du,rg; help text mentions "current directory" or recursion) get a small sample tree (--sample-files auto|on|off) whose names, sizes and extensions sort differently, sols --sort=size,ls -t,du --timeanddu -Sproduce output worth comparing - each case is recorded 3 times; anything that changes between runs is marked
flakyand skipped (for examplesort --random-sort) - normalizers remove noise before comparing:
ansi,workdir,cmd(jq:vsgojq:),timestamp,hexaddr,duration,pid, plus your own regex rules inbehave.yaml - timeouts kill the whole process group
GitHub Actions runs go vet, go test -race, a smoke probe/run on wc, then most of the committed example specs. On runners where the default tools are uutils, the workflow puts GNU coreutils first on PATH so those examples replay against GNU.
A few cases depend on a newer GNU than the runner's GNU coreutils:
- since GNU coreutils 9.5,
base32/base64-daccepts input without padding. Those cases are taggedgnu-9.5and skipped in CI:behave run examples/base32 --skip-tag gnu-9.5(same forbase64) ptx -toutput changed after GNU 9.7, so that case is taggedgnu-9.12and skipped in CIenvshell-quotes printed values since GNU 9.12 and gained-ain 9.5, so those cases are taggedgnu-9.12orgnu-9.5and skipped in CIfmtfills multibyte words and-w 20 -g 20differently after GNU 9.7, so those two cases are taggedgnu-9.12and skipped in CI
examples/sysctl needs the sbin directories on PATH. There is also a small self-check: behave run examples/behave.
The cksum, md5sum and tail example specs are in the repo but are not part of the CI workflow yet.
A longer walk-through of the probe / run / diff flow, including how to keep the recording in CI, is in Test a rewrite against the original. If you want snapshot tests for a tool you already own, rather than a comparison against a second binary, the same recording is enough: see Golden tests from --help.