Skip to content

Commit 2516f81

Browse files
committed
[nextest-runner] ensure that the last "panicked at" message is picked up
Some libraries like proptest produce a lot of "panicked at" messages. Ensure that only the last one is picked up. Also switch the color of panics from bold to fail, which highlights them more clearly in the output.
1 parent 0aaa2d6 commit 2516f81

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

nextest-runner/src/reporter/displayer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,15 +1481,15 @@ impl<'a> TestReporterImpl<'a> {
14811481
writer.write_all(&output.buf[..start])?;
14821482
writer.write_all(RESET_COLOR)?;
14831483

1484-
write!(writer, "{}", FmtPrefix(&self.styles.count))?;
1484+
write!(writer, "{}", FmtPrefix(&self.styles.fail))?;
14851485

14861486
// Strip ANSI escapes from this part of the output. It's unlikely there are any, but
14871487
// strip it just in case.
14881488
let mut no_color = strip_ansi_escapes::Writer::new(writer);
14891489
no_color.write_all(&output.buf[start..end])?;
14901490
let writer = no_color.into_inner()?;
14911491

1492-
write!(writer, "{}", FmtSuffix(&self.styles.count))?;
1492+
write!(writer, "{}", FmtSuffix(&self.styles.fail))?;
14931493

14941494
// `end` is guaranteed to be within the bounds of `output.buf`. (It is actually safe
14951495
// for it to be equal to `output.buf.len()` -- it gets treated as an empty list in

nextest-runner/src/reporter/helpers.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ fn heuristic_should_panic(stdout: &[u8]) -> Option<ByteSubslice<'_>> {
210210
}
211211

212212
fn heuristic_panic_message(stderr: &[u8]) -> Option<ByteSubslice<'_>> {
213-
let panicked_at_match = PANICKED_AT_REGEX.find(stderr)?;
213+
// Look for the last instance to handle situations like proptest which repeatedly print out
214+
// `panicked at ...` messages.
215+
let panicked_at_match = PANICKED_AT_REGEX.find_iter(stderr).last()?;
214216
// If the previous line starts with "Error: ", grab it as well -- it contains the error with
215217
// result-based test failures.
216218
let mut start = panicked_at_match.start();
@@ -300,7 +302,7 @@ test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 13 filtered out;
300302
}
301303

302304
#[test]
303-
fn test_heuristic_stack_trace() {
305+
fn test_heuristic_panic_message() {
304306
let tests: &[(&str, &str)] = &[
305307
(
306308
"thread 'main' panicked at 'foo', src/lib.rs:1\n",
@@ -330,7 +332,17 @@ thread 'test_result_failure' panicked at 'assertion failed: `(left == right)`
330332
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
331333
more text at the end, followed by some newlines"#,
332334
),
333-
// With RUST_BACKTRACE=1
335+
// Multiple panics: only the last one should be extracted.
336+
(
337+
r#"
338+
thread 'main' panicked at src/lib.rs:1:
339+
foo
340+
thread 'main' panicked at src/lib.rs:2:
341+
bar
342+
"#,
343+
r#"thread 'main' panicked at src/lib.rs:2:
344+
bar"#,
345+
), // With RUST_BACKTRACE=1
334346
(
335347
r#"
336348
some initial text

0 commit comments

Comments
 (0)