Skip to content

fix(cargo): show a failed test run as printed when it shows no failure block - #5103

Open
KuSh wants to merge 2 commits into
rtk-ai:developfrom
KuSh:fix/cargo-d1-nocapture
Open

KuSh wants to merge 2 commits into
rtk-ai:developfrom
KuSh:fix/cargo-d1-nocapture

Conversation

@KuSh

@KuSh KuSh commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #5095: until it merges this PR also shows its commit; review the second one, "fix(cargo): show a failed test run as printed when it shows no failure block".

Summary

With --nocapture the test harness prints a failing test's panic as it happens, outside the failures: section, and the cargo test filter only kept the blocks inside that section: a failed run showed test result: FAILED and nothing about why. A test binary that aborts prints no result at all, and what explains the abort can be on stdout or on stderr.

When a run exits non-zero, tests ran (libtest printed its running N tests line) and no ---- name stdout ---- failure block was shown, the filter now hands its input back unchanged and the run is printed as captured, stdout on stdout and stderr on stderr, with its exit code. The stream runner applies the rule #5095 gives the captured runner: output handed back is printed stream by stream and gets no recall hint.

Behaviour changes

  • A failed --nocapture run, and a run whose test binary aborts, print what cargo printed. They are not shortened.
  • A passing run, a failed run that shows its failure blocks and a run that fails to compile are summarised as before.
  • A test's own line starting with running is no longer dropped from its failure block, and libtest's start line may name a shuffle seed.
  • Known limits: a run in which one failing test still prints a block (a should_panic test that did not panic) is summarised, so the reasons other tests printed outside blocks are only in the recall copy; a --no-fail-fast run in which one binary shows failure blocks and another aborts is summarised without the abort.

Test plan

  • cargo fmt --all, cargo clippy --all-targets, cargo test --all --no-fail-fast (5,610 passed)
  • Real cargo test under LC_ALL=C on probe crates: failing --nocapture runs (parallel, single-threaded, tests printing on both streams, a failing doctest) and aborting binaries match raw cargo stream for stream with exit code 101 and no hint; runs with failure blocks, passing runs and compile errors print what develop prints
  • End-to-end test through the binary with a cargo stub, comparing both streams and the exit code
  • Each new guard fails a test when removed

Fixes #5063

🤖 Generated with Claude Code

@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes the cargo test output filter so that failed --nocapture runs and aborting test binaries (which print no failure block) are shown as raw cargo output instead of being silently summarized with no explanation. Also hardens the cargo nextest filter to strip ANSI codes before parsing, handle unsummarized/interrupted runs by passing through raw output, and fixes a regression where lines starting with 'running' were incorrectly dropped from failure blocks.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #5063


Analyzed automatically by wshm · This is an automated analysis, not a human review.

KuSh and others added 2 commits November 17, 2026 01:50
`filter_cargo_nextest` returned an empty string when it found no summary and no
test status line, so `rtk cargo nextest list`, `show-config`, `help`, `-V` and
`archive` printed nothing, and so did a `run` that fails to compile, `run --no-run`,
a `run` with a rejected option and a `run` killed before its summary (the compiler
error or usage message was lost, only the exit code remained). A coloured run
(`--color always`, `CARGO_TERM_COLOR=always`) printed nothing either: the escape
codes around `PASS`, `FAIL` and `Summary` kept them from matching at the start of
a line.

The filter now strips the escape codes before matching (only when the text has
one), and returns the output unchanged when it has no summary and no failure block
to show. A run killed after a `FAIL` line still shows its failure blocks; a run
killed after only `PASS` lines is shown as nextest printed it. The summary and
starting-line regexes are compiled once.

The runner joins stdout and stderr to give a filter its input, so a filter that
hands the text back would have printed all of it on stdout: the `Finished` line of
`rtk cargo nextest list --message-format json | jq` would have broken the pipe, and
nextest's stderr-only text (a compile error, `archive`'s report) would have moved to
stdout. When a filter returns exactly the text it was given, the runner now prints
the command's stdout on stdout and its stderr on stderr, each exactly as captured.
A stdout-only filter is not compared with the joined text and is unaffected.

Output handed back this way is printed in full, so there is nothing to recover: no
recall entry is stored and no recovery hint is added, also when the command failed.
A filter's own output is not affected.

The exit code was already forwarded. A test run, passing or failing, is summarised
as before; a test killed by a signal is counted in the summary but not listed, which
is unchanged. The hook does not rewrite `cargo nextest`, so this only changes an
explicit `rtk cargo nextest …`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e block

With `--nocapture` the test harness prints a failing test's panic as it
happens, outside the `failures:` section, and the cargo test filter only
kept the blocks inside that section: a failed run showed `test result:
FAILED` and nothing about why. A test binary that aborts prints no result
at all, and what explains the abort can be on stdout or on stderr.

When a run exits non-zero, tests ran (libtest printed its `running N tests`
line) and no `---- name stdout ----` failure block was shown, the filter
now hands its input back unchanged, and the run is printed as captured: its
stdout on stdout, its stderr on stderr, line by line, with its exit code.
Such a run is not shortened. A passing run, a failed run that shows its
failure blocks and a run that fails to compile are summarised as before. A
line that starts with `running ` but is not libtest's does not count as
tests having run, so a build that fails after one keeps its compile-error
summary, and a test's own such line is no longer dropped from its failure
block. libtest's start line may name a shuffle seed. A run in which one
failing test still prints a block (a `should_panic` test that did not
panic) is summarised as before, so the reasons other tests printed outside
blocks stay in the recovery copy only.

cargo test is filtered as it streams. The stream runner now applies the
rule the captured runner already applies: when a filter returns at exit
exactly the text it was given (stdout followed by stderr), each stream is
written to its own, as captured, instead of all of it going to the stream
the last line came from, and no recovery hint is added, since the output
shown is all that was captured. `stream::is_handed_back` defines the rule for both runners, and
only the filter's answer at exit is compared: a streamed filter that showed
every line live still gets its recovery hint.

The other streamed handlers return the raw output only through the
never-worse guard. `rtk cargo build` and `rtk cargo check` on an up-to-date
crate print cargo's `Finished` line on stderr, as before (it went there as
the last line read) and as cargo does. The tsc and `rtk err` filters never return their input.

The fixtures are real `cargo test` output captured under `LC_ALL=C`. An
end-to-end test runs `rtk cargo test` against a `cargo` stub and compares
both streams and the exit code; the stub helper moves to `tests/common` so
the nextest tests share it.

Fixes rtk-ai#5063

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk cargo test -- --nocapture drops the panic message of a failing test

1 participant