Skip to content

Commit dd8cd9c

Browse files
add nocapture message to report_test_err
1 parent dde17cf commit dd8cd9c

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/cargo/ops/cargo_test.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn run_unit_tests(
149149
unit: unit.clone(),
150150
kind: test_kind,
151151
};
152-
report_test_error(ws, &options.compile_opts, &unit_err, e);
152+
report_test_error(ws, test_args, &options.compile_opts, &unit_err, e);
153153
errors.push(unit_err);
154154
if !options.no_fail_fast {
155155
return Err(CliError::code(code));
@@ -275,7 +275,7 @@ fn run_doc_tests(
275275
unit: unit.clone(),
276276
kind: TestKind::Doctest,
277277
};
278-
report_test_error(ws, &options.compile_opts, &unit_err, e);
278+
report_test_error(ws, test_args, &options.compile_opts, &unit_err, e);
279279
errors.push(unit_err);
280280
if !options.no_fail_fast {
281281
return Err(CliError::code(code));
@@ -407,6 +407,7 @@ fn no_fail_fast_err(
407407
/// Displays an error on the console about a test failure.
408408
fn report_test_error(
409409
ws: &Workspace<'_>,
410+
test_args: &[&str],
410411
opts: &ops::CompileOptions,
411412
unit_err: &UnitTestError,
412413
test_error: anyhow::Error,
@@ -420,13 +421,23 @@ fn report_test_error(
420421
let mut err = format_err!("{}, to rerun pass `{}`", which, unit_err.cli_args(ws, opts));
421422
// Don't show "process didn't exit successfully" for simple errors.
422423
// libtest exits with 101 for normal errors.
423-
let is_simple = test_error
424+
let (is_simple, executed) = test_error
424425
.downcast_ref::<ProcessError>()
425426
.and_then(|proc_err| proc_err.code)
426-
.map_or(false, |code| code == 101);
427+
.map_or((false, false), |code| (code == 101, true));
428+
427429
if !is_simple {
428430
err = test_error.context(err);
429431
}
430432

431433
crate::display_error(&err, &mut ws.config().shell());
434+
435+
let harness: bool = unit_err.unit.target.harness();
436+
let nocapture: bool = test_args.contains(&"--nocapture");
437+
438+
if !is_simple && executed && harness && !nocapture {
439+
drop(ws.config().shell().note(
440+
"test exited abnormally; to see the full output pass --nocapture to the harness.",
441+
));
442+
}
432443
}

tests/testsuite/test.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4794,6 +4794,7 @@ error: test failed, to rerun pass `--test t2`
47944794
47954795
Caused by:
47964796
process didn't exit successfully: `[ROOT]/foo/target/debug/deps/t2[..]` (exit [..]: 4)
4797+
note: test exited abnormally; to see the full output pass --nocapture to the harness.
47974798
",
47984799
)
47994800
.with_status(4)
@@ -4825,6 +4826,7 @@ error: test failed, to rerun pass `--test t2`
48254826
48264827
Caused by:
48274828
process didn't exit successfully: `[ROOT]/foo/target/debug/deps/t2[..]` (exit [..]: 4)
4829+
note: test exited abnormally; to see the full output pass --nocapture to the harness.
48284830
error: 2 targets failed:
48294831
`--test t1`
48304832
`--test t2`
@@ -4834,23 +4836,10 @@ error: 2 targets failed:
48344836
.run();
48354837

48364838
p.cargo("test --no-fail-fast -- --nocapture")
4837-
.with_stderr(
4838-
"\
4839-
[FINISHED] test [..]
4840-
[RUNNING] tests/t1.rs (target/debug/deps/t1[..])
4841-
thread 't' panicked at 'this is a normal error', tests/t1[..]
4842-
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
4843-
error: test failed, to rerun pass `--test t1`
4844-
[RUNNING] tests/t2.rs (target/debug/deps/t2[..])
4845-
error: test failed, to rerun pass `--test t2`
4846-
4847-
Caused by:
4848-
process didn't exit successfully: `[ROOT]/foo/target/debug/deps/t2[..]` (exit [..]: 4)
4849-
error: 2 targets failed:
4850-
`--test t1`
4851-
`--test t2`
4852-
",
4853-
)
4854-
.with_status(101)
4855-
.run();
4839+
.with_stderr_does_not_contain("test exited abnormally; to see the full output pass --nocapture to the harness.")
4840+
.with_stderr_contains("[..]thread 't' panicked [..] tests/t1[..]")
4841+
.with_stderr_contains("note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace")
4842+
.with_stderr_contains("[..]process didn't exit successfully: `[ROOT]/foo/target/debug/deps/t2[..]` (exit [..]: 4)")
4843+
.with_status(101)
4844+
.run();
48564845
}

0 commit comments

Comments
 (0)