From: Lukas Lueg Date: Fri, 6 Oct 2017 16:14:23 +0000 (+0200) Subject: Report hint if single failure with --no-fail-fast X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~6^2~16^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b8c8e307e6514469a82ee227a0369a20e102c15e;p=cargo.git Report hint if single failure with --no-fail-fast If a single unit-test fails, report a rerun-hint for it, even with --no-fail-fast. Fixes reporting a doctest-hint if doctest succeeds while unittest fail with --no-fail-fast. Fixes #4534 --- diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 32c92e731..f808ff5e1 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -42,11 +42,12 @@ pub fn run_tests(ws: &Workspace, } let (doctest, docerrors) = run_doc_tests(options, test_args, &compilation)?; + let test = if docerrors.is_empty() { test } else { doctest }; errors.extend(docerrors); if errors.is_empty() { Ok(None) } else { - Ok(Some(CargoTestError::new(doctest, errors))) + Ok(Some(CargoTestError::new(test, errors))) } } @@ -105,9 +106,9 @@ fn run_unit_tests(options: &TestOptions, match result { Err(CargoError(CargoErrorKind::ProcessErrorKind(e), .. )) => { - errors.push(e); + errors.push((kind.clone(), test.clone(), e)); if !options.no_fail_fast { - return Ok((Test::UnitTest(kind.clone(), test.clone()), errors)) + break; } } Err(e) => { @@ -117,7 +118,13 @@ fn run_unit_tests(options: &TestOptions, Ok(()) => {} } } - Ok((Test::Multiple, errors)) + + if errors.len() == 1 { + let (kind, test, e) = errors.pop().unwrap(); + Ok((Test::UnitTest(kind, test), vec![e])) + } else { + Ok((Test::Multiple, errors.into_iter().map((|(_, _, e)| e)).collect())) + } } fn run_doc_tests(options: &TestOptions, diff --git a/tests/test.rs b/tests/test.rs index f9d69e1f2..47878a433 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -2837,3 +2837,33 @@ fn find_dependency_of_proc_macro_dependency_with_target() { assert_that(workspace.cargo("test").arg("--all").arg("--target").arg(rustc_host()), execs().with_status(0)); } + +#[test] +fn test_hint_not_masked_by_doctest() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + "#) + .file("src/lib.rs", r#" + /// ``` + /// assert_eq!(1, 1); + /// ``` + pub fn this_works() {} + "#) + .file("tests/integ.rs", r#" + #[test] + fn this_fails() { + panic!(); + } + "#); + assert_that(p.cargo_process("test") + .arg("--no-fail-fast"), + execs() + .with_status(101) + .with_stdout_contains("test this_fails ... FAILED") + .with_stdout_contains("[..]this_works (line [..]ok") + .with_stderr_contains("[ERROR] test failed, to rerun pass \ + '--test integ'")); +}