From 0bc115575336d20d99bc9d0b56baab1ce286043d Mon Sep 17 00:00:00 2001
From: Ximin Luo <infinity0@pwned.gg>
Date: Mon, 19 Mar 2018 18:20:54 +0100
Subject: [PATCH] Split tests, apparently `cargo clean` does not work well on
 windows

---
 tests/testsuite/build.rs | 31 +++++++++++++++++++++++--------
 tests/testsuite/check.rs | 32 ++++++++++++++++++++++----------
 tests/testsuite/rustc.rs | 31 +++++++++++++++++++++++--------
 3 files changed, 68 insertions(+), 26 deletions(-)

diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs
index 9025c51d3d8..b7c44347341 100644
--- a/tests/testsuite/build.rs
+++ b/tests/testsuite/build.rs
@@ -5337,7 +5337,7 @@ fn build_filter_infer_profile() {
 }
 
 #[test]
-fn all_targets_with_and_without() {
+fn targets_selected_default() {
     let p = project("foo")
         .file(
             "Cargo.toml",
@@ -5351,35 +5351,50 @@ fn all_targets_with_and_without() {
         .file("src/main.rs", "fn main() {}")
         .build();
     assert_that(
-        p.cargo("build").arg("-v").arg("--all-targets"),
+        p.cargo("build").arg("-v"),
         execs().with_status(0)
         // bin
         .with_stderr_contains("\
             [RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
             --emit=dep-info,link[..]")
         // bench
-        .with_stderr_contains("\
+        .with_stderr_does_not_contain("\
             [RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
             -C opt-level=3 --test [..]")
         // unit test
-        .with_stderr_contains("\
+        .with_stderr_does_not_contain("\
             [RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
             -C debuginfo=2 --test [..]"),
     );
-    assert_that(p.cargo("clean"), execs().with_status(0));
+}
+
+#[test]
+fn targets_selected_all() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [package]
+            name = "foo"
+            version = "0.1.0"
+            authors = []
+        "#,
+        )
+        .file("src/main.rs", "fn main() {}")
+        .build();
     assert_that(
-        p.cargo("build").arg("-v"),
+        p.cargo("build").arg("-v").arg("--all-targets"),
         execs().with_status(0)
         // bin
         .with_stderr_contains("\
             [RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
             --emit=dep-info,link[..]")
         // bench
-        .with_stderr_does_not_contain("\
+        .with_stderr_contains("\
             [RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
             -C opt-level=3 --test [..]")
         // unit test
-        .with_stderr_does_not_contain("\
+        .with_stderr_contains("\
             [RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
             -C debuginfo=2 --test [..]"),
     );
diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs
index 7a6b1b33165..264abf898a1 100644
--- a/tests/testsuite/check.rs
+++ b/tests/testsuite/check.rs
@@ -606,7 +606,7 @@ fn check_virtual_all_implied() {
 }
 
 #[test]
-fn all_targets_with_and_without() {
+fn targets_selected_default() {
     let foo = project("foo")
         .file("Cargo.toml", SIMPLE_MANIFEST)
         .file("src/main.rs", "fn main() {}")
@@ -617,25 +617,37 @@ fn all_targets_with_and_without() {
         .build();
 
     assert_that(
-        foo.cargo("check").arg("--all-targets").arg("-v"),
+        foo.cargo("check").arg("-v"),
         execs()
             .with_status(0)
             .with_stderr_contains("[..] --crate-name foo src[/]lib.rs [..]")
             .with_stderr_contains("[..] --crate-name foo src[/]main.rs [..]")
-            .with_stderr_contains("[..] --crate-name example1 examples[/]example1.rs [..]")
-            .with_stderr_contains("[..] --crate-name test2 tests[/]test2.rs [..]")
-            .with_stderr_contains("[..] --crate-name bench3 benches[/]bench3.rs [..]"),
+            .with_stderr_does_not_contain("[..] --crate-name example1 examples[/]example1.rs [..]")
+            .with_stderr_does_not_contain("[..] --crate-name test2 tests[/]test2.rs [..]")
+            .with_stderr_does_not_contain("[..] --crate-name bench3 benches[/]bench3.rs [..]"),
     );
-    assert_that(foo.cargo("clean"), execs().with_status(0));
+}
+
+#[test]
+fn targets_selected_all() {
+    let foo = project("foo")
+        .file("Cargo.toml", SIMPLE_MANIFEST)
+        .file("src/main.rs", "fn main() {}")
+        .file("src/lib.rs", "pub fn smth() {}")
+        .file("examples/example1.rs", "fn main() {}")
+        .file("tests/test2.rs", "#[test] fn t() {}")
+        .file("benches/bench3.rs", "")
+        .build();
+
     assert_that(
-        foo.cargo("check").arg("-v"),
+        foo.cargo("check").arg("--all-targets").arg("-v"),
         execs()
             .with_status(0)
             .with_stderr_contains("[..] --crate-name foo src[/]lib.rs [..]")
             .with_stderr_contains("[..] --crate-name foo src[/]main.rs [..]")
-            .with_stderr_does_not_contain("[..] --crate-name example1 examples[/]example1.rs [..]")
-            .with_stderr_does_not_contain("[..] --crate-name test2 tests[/]test2.rs [..]")
-            .with_stderr_does_not_contain("[..] --crate-name bench3 benches[/]bench3.rs [..]"),
+            .with_stderr_contains("[..] --crate-name example1 examples[/]example1.rs [..]")
+            .with_stderr_contains("[..] --crate-name test2 tests[/]test2.rs [..]")
+            .with_stderr_contains("[..] --crate-name bench3 benches[/]bench3.rs [..]"),
     );
 }
 
diff --git a/tests/testsuite/rustc.rs b/tests/testsuite/rustc.rs
index 582a9ee175c..297e1050c10 100644
--- a/tests/testsuite/rustc.rs
+++ b/tests/testsuite/rustc.rs
@@ -438,7 +438,7 @@ fn build_only_bar_dependency() {
 }
 
 #[test]
-fn all_targets_with_and_without() {
+fn targets_selected_default() {
     let p = project("foo")
         .file(
             "Cargo.toml",
@@ -452,35 +452,50 @@ fn all_targets_with_and_without() {
         .file("src/main.rs", "fn main() {}")
         .build();
     assert_that(
-        p.cargo("rustc").arg("-v").arg("--all-targets"),
+        p.cargo("rustc").arg("-v"),
         execs().with_status(0)
         // bin
         .with_stderr_contains("\
             [RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
             --emit=dep-info,link[..]")
         // bench
-        .with_stderr_contains("\
+        .with_stderr_does_not_contain("\
             [RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
             -C opt-level=3 --test [..]")
         // unit test
-        .with_stderr_contains("\
+        .with_stderr_does_not_contain("\
             [RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
             -C debuginfo=2 --test [..]"),
     );
-    assert_that(p.cargo("clean"), execs().with_status(0));
+}
+
+#[test]
+fn targets_selected_all() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [package]
+            name = "foo"
+            version = "0.1.0"
+            authors = []
+        "#,
+        )
+        .file("src/main.rs", "fn main() {}")
+        .build();
     assert_that(
-        p.cargo("rustc").arg("-v"),
+        p.cargo("rustc").arg("-v").arg("--all-targets"),
         execs().with_status(0)
         // bin
         .with_stderr_contains("\
             [RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
             --emit=dep-info,link[..]")
         // bench
-        .with_stderr_does_not_contain("\
+        .with_stderr_contains("\
             [RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
             -C opt-level=3 --test [..]")
         // unit test
-        .with_stderr_does_not_contain("\
+        .with_stderr_contains("\
             [RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
             -C debuginfo=2 --test [..]"),
     );