Report hint if single failure with --no-fail-fast
authorLukas Lueg <lukas.lueg@gmail.com>
Fri, 6 Oct 2017 16:14:23 +0000 (18:14 +0200)
committerLukas Lueg <lukas.lueg@gmail.com>
Fri, 6 Oct 2017 16:14:23 +0000 (18:14 +0200)
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

src/cargo/ops/cargo_test.rs
tests/test.rs

index 32c92e7315674d48c6f19be2d8b63c7c5b9e3e91..f808ff5e1b393c645cb2339c07cccb936760106c 100644 (file)
@@ -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,
index f9d69e1f27505916e931adca20ce75ae4f7d6eea..47878a433200fbaea34d61d0b8147047ba62af58 100644 (file)
@@ -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'"));
+}