Skip to content

Commit 78abc7f

Browse files
added tests + code change to display message
1 parent ebe124e commit 78abc7f

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

src/cargo/ops/cargo_test.rs

Lines changed: 15 additions & 6 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,
@@ -429,8 +430,16 @@ fn report_test_error(
429430
}
430431

431432
crate::display_error(&err, &mut ws.config().shell());
432-
drop(ws.config().shell().note(
433-
"test was terminated by the signal, stderr might be truncated, \
434-
pass `--nocapture` disable output buffering.",
435-
));
433+
434+
// println!("{:#?}", opts);
435+
// println!("{:#?}", test_args);
436+
437+
let harness: bool = unit_err.unit.target.harness();
438+
let nocapture: bool = test_args.contains(&"--nocapture");
439+
440+
if !is_simple && harness && !nocapture {
441+
drop(ws.config().shell().note(
442+
"test was terminated via a signal. stderr might be truncated. use `--nocapture` flag to disable output buffering."
443+
));
444+
}
436445
}

tests/testsuite/test.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4792,6 +4792,21 @@ error: test failed, to rerun pass `--test t1`
47924792
[RUNNING] tests/t2.rs (target/debug/deps/t2[..])
47934793
error: test failed, to rerun pass `--test t2`
47944794
4795+
Caused by:
4796+
process didn't exit successfully: `[ROOT]/foo/target/debug/deps/t2[..]` (exit [..]: 4)
4797+
note: test was terminated via a signal. stderr might be truncated. use `--nocapture` flag to disable output buffering.
4798+
",
4799+
)
4800+
.with_status(4)
4801+
.run();
4802+
4803+
p.cargo("test --test t2 -- --nocapture")
4804+
.with_stderr(
4805+
"\
4806+
[FINISHED] test [..]
4807+
[RUNNING] tests/t2.rs (target/debug/deps/t2[..])
4808+
error: test failed, to rerun pass `--test t2`
4809+
47954810
Caused by:
47964811
process didn't exit successfully: `[ROOT]/foo/target/debug/deps/t2[..]` (exit [..]: 4)
47974812
",
@@ -4809,6 +4824,28 @@ error: test failed, to rerun pass `--test t1`
48094824
[RUNNING] tests/t2.rs (target/debug/deps/t2[..])
48104825
error: test failed, to rerun pass `--test t2`
48114826
4827+
Caused by:
4828+
process didn't exit successfully: `[ROOT]/foo/target/debug/deps/t2[..]` (exit [..]: 4)
4829+
note: test was terminated via a signal. stderr might be truncated. use `--nocapture` flag to disable output buffering.
4830+
error: 2 targets failed:
4831+
`--test t1`
4832+
`--test t2`
4833+
",
4834+
)
4835+
.with_status(101)
4836+
.run();
4837+
4838+
p.cargo("test --no-fail-fast -- --nocapture")
4839+
.with_stderr(
4840+
"\
4841+
[FINISHED] test [..]
4842+
[RUNNING] tests/t1.rs (target/debug/deps/t1[..])
4843+
thread 't' panicked at 'this is a normal error', tests/t1[..]
4844+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
4845+
error: test failed, to rerun pass `--test t1`
4846+
[RUNNING] tests/t2.rs (target/debug/deps/t2[..])
4847+
error: test failed, to rerun pass `--test t2`
4848+
48124849
Caused by:
48134850
process didn't exit successfully: `[ROOT]/foo/target/debug/deps/t2[..]` (exit [..]: 4)
48144851
error: 2 targets failed:

0 commit comments

Comments
 (0)