Skip to content

Commit bbe8359

Browse files
committed
[nextest-runner] fix heuristic error extraction for Rust 1.66
Rust 1.66 prints out Result-based test failures in a slightly different format.
1 parent e7a1583 commit bbe8359

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

nextest-runner/src/reporter/aggregator.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ static PANICKED_AT_REGEX: Lazy<Regex> = Lazy::new(|| {
253253
builder.build().unwrap()
254254
});
255255

256+
static ERROR_REGEX_STR: &str = "^Error: ";
257+
static ERROR_REGEX: Lazy<Regex> = Lazy::new(|| {
258+
let mut builder = RegexBuilder::new(ERROR_REGEX_STR);
259+
builder.multi_line(true);
260+
builder.build().unwrap()
261+
});
262+
256263
#[allow(unused_variables)]
257264
/// Not part of the public API: only used for testing.
258265
#[doc(hidden)]
@@ -306,6 +313,9 @@ pub fn heuristic_extract_description<'a>(
306313
if let Some(description) = heuristic_stack_trace(stderr) {
307314
return Some(description);
308315
}
316+
if let Some(description) = heuristic_error_str(stderr) {
317+
return Some(description);
318+
}
309319
heuristic_should_panic(stdout)
310320
}
311321

@@ -334,6 +344,13 @@ fn heuristic_stack_trace(stderr: &str) -> Option<String> {
334344
Some(Output::new(stderr[start..].trim_end()).into_string())
335345
}
336346

347+
fn heuristic_error_str(stderr: &str) -> Option<String> {
348+
// Starting Rust 1.66, Result-based errors simply print out "Error: ".
349+
let error_match = ERROR_REGEX.find(stderr)?;
350+
let start = error_match.start();
351+
Some(Output::new(stderr[start..].trim_end()).into_string())
352+
}
353+
337354
#[cfg(test)]
338355
mod tests {
339356
use super::*;
@@ -388,6 +405,10 @@ thread 'test_result_failure' panicked at 'assertion failed: `(left == right)`
388405
right: `0`: the test returned a termination value with a non-zero status code (1) which indicates a failure', /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/test/src/lib.rs:186:5
389406
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace"#,
390407
),
408+
(
409+
"foobar\nError: \"this is an error\"\n",
410+
"Error: \"this is an error\"\n",
411+
),
391412
];
392413

393414
for (input, output) in tests {

nextest-runner/tests/integration/basic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ fn test_run() -> Result<()> {
152152
// Check that stderr can be parsed heuristically.
153153
let stdout = String::from_utf8_lossy(&run_status.stdout);
154154
let stderr = String::from_utf8_lossy(&run_status.stderr);
155+
println!("stderr: {stderr}");
155156
let description =
156157
heuristic_extract_description(run_status.result, &stdout, &stderr);
157158
assert!(

0 commit comments

Comments
 (0)