Skip to main content

Crate test_better_runner

Crate test_better_runner 

Source
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=1 into the cargo test it spawns.
  • When that variable is set, a failing test-better test prints one line of the form <STRUCTURED_MARKER><json><STRUCTURED_MARKER> to stdout, in addition to its normal human-readable failure.
  • cargo test already captures test output and replays it for failing tests, which is exactly when the runner needs it, so no side-channel file and no --nocapture is required.
  • A failure with no marker line (a plain panic!, or non-test-better code) 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§

ContextGroup
Structured failures that share a top context-frame message.
GroupedReport
The result of scanning a wrapped cargo test run: 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 test run, summed across every test binary (libtest prints one test result: line per binary, and scan_output adds them up).
StructuredFailure
One structured failure: the test that produced it and its structured error.

Enums§

ProgressEvent
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 test it 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 test invocation the runner wraps.
progress_event
Classifies one line of libtest output as a ProgressEvent, or None if it is neither a test-count announcement nor a per-test outcome line.
run
Runs the wrapped cargo test to 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 a GroupedReport.