Skip to content

Commit

Permalink
Auto merge of #3716 - matklad:multi-tests, r=alexcrichton
Browse files Browse the repository at this point in the history
Allow to run several integration tests

It's useful to be able to run several, but not all, test targets at once (especially in the IDE, where you want to select a bunch of files and command "run these!"). This seems to work, but obviously needs some tests. `Options` `struct` already supports several targets.
  • Loading branch information
bors committed Feb 17, 2017
2 parents 9706b06 + f7fa9cb commit 3dfe72f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ Options:
-h, --help Print this message
--lib Test only this package's library
--doc Test only this library's documentation
--bin NAME Test only the specified binary
--example NAME Test only the specified example
--test NAME Test only the specified integration test target
--bench NAME Test only the specified benchmark target
--bin NAME ... Test only the specified binaries
--example NAME ... Check that the specified examples compile
--test NAME ... Test only the specified integration test targets
--bench NAME ... Test only the specified benchmark targets
--no-run Compile, but don't run tests
-p SPEC, --package SPEC ... Package to run tests for
--all Test all packages in the workspace
Expand Down
55 changes: 55 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2571,3 +2571,58 @@ fn doctest_only_with_dev_dep() {
assert_that(p.cargo_process("test").arg("--doc").arg("-v"),
execs().with_status(0));
}

#[test]
fn test_many_targets() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.1.0"
"#)
.file("src/bin/a.rs", r#"
fn main() {}
#[test] fn bin_a() {}
"#)
.file("src/bin/b.rs", r#"
fn main() {}
#[test] fn bin_b() {}
"#)
.file("src/bin/c.rs", r#"
fn main() {}
#[test] fn bin_c() { panic!(); }
"#)
.file("examples/a.rs", r#"
fn main() {}
#[test] fn example_a() {}
"#)
.file("examples/b.rs", r#"
fn main() {}
#[test] fn example_b() {}
"#)
.file("examples/c.rs", r#"
#[test] fn example_c() { panic!(); }
"#)
.file("tests/a.rs", r#"
#[test] fn test_a() {}
"#)
.file("tests/b.rs", r#"
#[test] fn test_b() {}
"#)
.file("tests/c.rs", r#"
does not compile
"#);

assert_that(p.cargo_process("test").arg("--verbose")
.arg("--bin").arg("a").arg("--bin").arg("b")
.arg("--example").arg("a").arg("--example").arg("b")
.arg("--test").arg("a").arg("--test").arg("b"),
execs()
.with_status(0)
.with_stdout_contains("test bin_a ... ok")
.with_stdout_contains("test bin_b ... ok")
.with_stdout_contains("test test_a ... ok")
.with_stdout_contains("test test_b ... ok")
.with_stderr_contains("[RUNNING] `rustc --crate-name a examples[/]a.rs [..]`")
.with_stderr_contains("[RUNNING] `rustc --crate-name b examples[/]b.rs [..]`"))
}

0 comments on commit 3dfe72f

Please sign in to comment.