Slightly improve ergonomics of writing Cargo tests
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 16 Mar 2018 17:03:27 +0000 (20:03 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 16 Mar 2018 21:08:23 +0000 (00:08 +0300)
tests/testsuite/build.rs
tests/testsuite/cargotest/support/mod.rs
tests/testsuite/clean.rs
tests/testsuite/run.rs
tests/testsuite/rustc.rs
tests/testsuite/test.rs

index 7cf2e011640c035cb33d6ee3e35683dbe3de4dbe..c87d588c1d38320d54056f0e29d6cfb45b078760 100644 (file)
@@ -3705,16 +3705,7 @@ fn build_multiple_packages() {
         .file("d2/src/main.rs", "fn main() { println!(\"d2\"); }")
         .build();
 
-    assert_that(
-        p.cargo("build")
-            .arg("-p")
-            .arg("d1")
-            .arg("-p")
-            .arg("d2")
-            .arg("-p")
-            .arg("foo"),
-        execs().with_status(0),
-    );
+    assert_that(p.cargo("build -p d1 -p d2 -p foo"), execs().with_status(0));
 
     assert_that(&p.bin("foo"), existing_file());
     assert_that(
index 089f1680234729477c0987e970dee3d37001f643..9ee70bf7c46681feaee02bdf08a8f5b361a9a96f 100644 (file)
@@ -233,7 +233,12 @@ impl Project {
 
     pub fn cargo(&self, cmd: &str) -> ProcessBuilder {
         let mut p = self.process(&cargo_exe());
-        p.arg(cmd);
+        for arg in cmd.split_whitespace() {
+            if arg.contains('"') || arg.contains('\'') {
+                panic!("shell-style argument parsing is not supported")
+            }
+            p.arg(arg);
+        }
         return p;
     }
 
index ca76682f9d22342d90b91df612963ace12ad24f3..f5a409f6728d316f64c655bf2588855719c1c93d 100644 (file)
@@ -85,16 +85,7 @@ fn clean_multiple_packages() {
         .file("d2/src/main.rs", "fn main() { println!(\"d2\"); }")
         .build();
 
-    assert_that(
-        p.cargo("build")
-            .arg("-p")
-            .arg("d1")
-            .arg("-p")
-            .arg("d2")
-            .arg("-p")
-            .arg("foo"),
-        execs().with_status(0),
-    );
+    assert_that(p.cargo("build -p d1 -p d2 -p foo"), execs().with_status(0));
 
     let d1_path = &p.build_dir()
         .join("debug")
@@ -108,12 +99,7 @@ fn clean_multiple_packages() {
     assert_that(d2_path, existing_file());
 
     assert_that(
-        p.cargo("clean")
-            .arg("-p")
-            .arg("d1")
-            .arg("-p")
-            .arg("d2")
-            .cwd(&p.root().join("src")),
+        p.cargo("clean -p d1 -p d2").cwd(&p.root().join("src")),
         execs().with_status(0).with_stdout(""),
     );
     assert_that(&p.bin("foo"), existing_file());
index c691891052465cef8a40ce7421b006df71982817..742f37d04f1f5214aba91aeb1b294ad9525da756 100644 (file)
@@ -59,12 +59,12 @@ fn simple_quiet() {
         .build();
 
     assert_that(
-        p.cargo("run").arg("-q"),
+        p.cargo("run -q"),
         execs().with_status(0).with_stdout("hello"),
     );
 
     assert_that(
-        p.cargo("run").arg("--quiet"),
+        p.cargo("run --quiet"),
         execs().with_status(0).with_stdout("hello"),
     );
 }
@@ -1133,12 +1133,5 @@ fn explicit_bin_with_args() {
         )
         .build();
 
-    assert_that(
-        p.cargo("run")
-            .arg("--bin")
-            .arg("foo")
-            .arg("hello")
-            .arg("world"),
-        execs().with_status(0),
-    );
+    assert_that(p.cargo("run --bin foo hello world"), execs().with_status(0));
 }
index dd5de43fa0f5fc5f2a7b29b886919dbe620038f5..d3984bdde385a6cdf0c17db9773bee189914c1d6 100644 (file)
@@ -111,13 +111,7 @@ fn build_main_and_allow_unstable_options() {
         .build();
 
     assert_that(
-        p.cargo("rustc")
-            .arg("-v")
-            .arg("--bin")
-            .arg("foo")
-            .arg("--")
-            .arg("-C")
-            .arg("debug-assertions"),
+        p.cargo("rustc -v --bin foo -- -C debug-assertions"),
         execs().with_status(0).with_stderr(&format!(
             "\
 [COMPILING] {name} v{version} ({url})
@@ -208,13 +202,7 @@ fn build_with_args_to_one_of_multiple_binaries() {
         .build();
 
     assert_that(
-        p.cargo("rustc")
-            .arg("-v")
-            .arg("--bin")
-            .arg("bar")
-            .arg("--")
-            .arg("-C")
-            .arg("debug-assertions"),
+        p.cargo("rustc -v --bin bar -- -C debug-assertions"),
         execs().with_status(0).with_stderr(format!(
             "\
 [COMPILING] foo v0.0.1 ({url})
@@ -292,13 +280,7 @@ fn build_with_args_to_one_of_multiple_tests() {
         .build();
 
     assert_that(
-        p.cargo("rustc")
-            .arg("-v")
-            .arg("--test")
-            .arg("bar")
-            .arg("--")
-            .arg("-C")
-            .arg("debug-assertions"),
+        p.cargo("rustc -v --test bar -- -C debug-assertions"),
         execs().with_status(0).with_stderr(format!(
             "\
 [COMPILING] foo v0.0.1 ({url})
@@ -420,13 +402,7 @@ fn build_only_bar_dependency() {
         .build();
 
     assert_that(
-        foo.cargo("rustc")
-            .arg("-v")
-            .arg("-p")
-            .arg("bar")
-            .arg("--")
-            .arg("-C")
-            .arg("debug-assertions"),
+        foo.cargo("rustc -v -p bar -- -C debug-assertions"),
         execs().with_status(0).with_stderr(
             "\
 [COMPILING] bar v0.1.0 ([..])
@@ -504,12 +480,7 @@ fn fail_with_multiple_packages() {
         .build();
 
     assert_that(
-        foo.cargo("rustc")
-            .arg("-v")
-            .arg("-p")
-            .arg("bar")
-            .arg("-p")
-            .arg("baz"),
+        foo.cargo("rustc -v -p bar -p baz"),
         execs().with_status(1).with_stderr_contains(
             "\
 error: The argument '--package <SPEC>' was provided more than once, \
index 3711222ec328df7c42b3e8c6c883954eb8685ca0..608eb9faf47d21b46a3ea37c3a6544681a189534 100644 (file)
@@ -2833,14 +2833,7 @@ fn selective_test_wonky_profile() {
     let p = p.build();
 
     assert_that(
-        p.cargo("test")
-            .arg("-v")
-            .arg("--no-run")
-            .arg("--release")
-            .arg("-p")
-            .arg("foo")
-            .arg("-p")
-            .arg("a"),
+        p.cargo("test -v --no-run --release -p foo -p a"),
         execs().with_status(0),
     );
 }
@@ -3051,13 +3044,7 @@ fn panic_abort_multiple() {
         .file("a/src/lib.rs", "")
         .build();
     assert_that(
-        p.cargo("test")
-            .arg("--release")
-            .arg("-v")
-            .arg("-p")
-            .arg("foo")
-            .arg("-p")
-            .arg("a"),
+        p.cargo("test --release -v -p foo -p a"),
         execs().with_status(0),
     );
 }
@@ -3246,14 +3233,7 @@ fn test_many_with_features() {
         .build();
 
     assert_that(
-        p.cargo("test")
-            .arg("-v")
-            .arg("-p")
-            .arg("a")
-            .arg("-p")
-            .arg("foo")
-            .arg("--features")
-            .arg("foo"),
+        p.cargo("test -v -p a -p foo --features foo"),
         execs().with_status(0),
     );
 }