diff --git a/src/bin/test.rs b/src/bin/test.rs index 5f7f9eb8cf7..afd482cd68c 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -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 diff --git a/tests/test.rs b/tests/test.rs index 7d2969735e8..5102bca446e 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -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 [..]`")) +}