]> git.proxmox.com Git - cargo.git/commitdiff
Pass through extra arguments to `cargo test`
authorAlex Crichton <alex@alexcrichton.com>
Thu, 10 Jul 2014 20:53:36 +0000 (13:53 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 13 Jul 2014 03:29:51 +0000 (20:29 -0700)
This allows `cargo test` usage to filter test being run, use --nocapture, etc.

src/bin/cargo-test.rs
tests/test_cargo_test.rs

index bee0541ceeed265d3558125193532d5ca6a80981..fdd9dce7222b0ce8bb80703c5732c8f4de3cfbb3 100644 (file)
@@ -59,7 +59,9 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
     let test_dir = root.dir_path().join("target").join("test");
 
     for file in test_executables.iter() {
-        try!(util::process(test_dir.join(file.as_slice())).exec().map_err(|e| {
+        try!(util::process(test_dir.join(file.as_slice()))
+                  .args(options.rest.as_slice())
+                  .exec().map_err(|e| {
             CliError::from_boxed(e.box_error(), 1)
         }));
     }
index 85129fa1f31d0dfb1b01ebda10d7d319e28d2898..3727a071314f0c8f9e228aaf8802ff44b90bcd66 100644 (file)
@@ -239,3 +239,43 @@ test!(dont_run_examples {
     assert_that(p.cargo_process("cargo-test"),
                 execs().with_status(0));
 })
+
+test!(pass_through_command_line {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/lib.rs", "
+            #[test] fn foo() {}
+            #[test] fn bar() {}
+        ");
+
+    assert_that(p.cargo_process("cargo-test").arg("bar"),
+                execs().with_status(0)
+                       .with_stdout(format!("\
+{compiling} foo v0.0.1 (file:{dir})
+
+running 1 test
+test bar ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n\
+                       ",
+                       compiling = COMPILING,
+                       dir = p.root().display()).as_slice()));
+
+    assert_that(p.cargo_process("cargo-test").arg("foo"),
+                execs().with_status(0)
+                       .with_stdout(format!("\
+{compiling} foo v0.0.1 (file:{dir})
+
+running 1 test
+test foo ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n\
+                       ",
+                       compiling = COMPILING,
+                       dir = p.root().display()).as_slice()));
+})