Expand description
test-better-runner: optional pretty runner.
Library half of the cargo-test-better subcommand. It wraps cargo test,
forwarding every argument and propagating the exit code; it also groups
failures by their context chain.
§The structured-output channel
The runner never parses rendered failure text. It consumes the structured
StructuredError form (test-better’s owned, serializable mirror of
TestError), and the channel that carries it is a marker-wrapped JSON
line in the test’s own captured output (the emitting side lives in
test-better-core’s runner module):
- The runner exports
RUNNER_ENV=1into thecargo testit spawns. - When that variable is set, a failing
test-bettertest prints one line of the form<STRUCTURED_MARKER><json><STRUCTURED_MARKER>to stdout, in addition to its normal human-readable failure. cargo testalready captures test output and replays it for failing tests, which is exactly when the runner needs it, so no side-channel file and no--nocaptureis required.- A failure with no marker line (a plain
panic!, or non-test-bettercode) is shown ungrouped and labelled “unstructured”; the runner never falls back to parsing prose.
§Grouping
run pipes the wrapped cargo test’s stdout, tees every non-marker line
straight through, and feeds the stream to scan_output, which builds a
GroupedReport: structured failures bucketed by their top
ContextFrame message, plus a flat list of
unstructured ones. run prints that report after the wrapped build exits.
§Progress and summary
scan_output also reads libtest’s own test result: lines into a
RunSummary (passed/failed/ignored counts, summed across every test
binary), which run prints as a one-line summary table once the build
exits, alongside the wall-clock duration it measured itself.
While the build runs, run keeps a live progress counter. It is gated
on stderr being a TTY: on a terminal the per-test ... ok lines are
replaced by an updating running: done/total line on stderr; piped or
redirected, the output is the plain cargo test stream, unchanged.
Structs§
- Context
Group - Structured failures that share a top context-frame message.
- Grouped
Report - The result of scanning a wrapped
cargo testrun: structured failures bucketed by feature area, the unstructured ones left ungrouped, and the run’s pass/fail/ignored summary. - RunSummary
- The pass/fail/ignored tallies of a wrapped
cargo testrun, summed across every test binary (libtest prints onetest result:line per binary, andscan_outputadds them up). - Structured
Failure - One structured failure: the test that produced it and its structured error.
Enums§
- Progress
Event - A step in the wrapped run’s progress, recovered from one line of libtest
output by
progress_event.
Constants§
- RUNNER_
ENV - The environment variable the runner sets on the
cargo testit spawns. - STRUCTURED_
MARKER - The sentinel that brackets the JSON structured-error payload on its own line in captured test output. Chosen to be unmistakable in prose and to sit alone on a line.
Functions§
- cargo_
test_ command - Builds the
cargo testinvocation the runner wraps. - progress_
event - Classifies one line of libtest output as a
ProgressEvent, orNoneif it is neither a test-count announcement nor a per-test outcome line. - run
- Runs the wrapped
cargo testto completion and returns the exit code to propagate, after printing the grouped failure report and the run summary. - scan_
output - Scans a wrapped
cargo test’s stdout, line by line, into aGroupedReport.