From 33431d715dd89204311f17e186a366050d1f33c9 Mon Sep 17 00:00:00 2001 From: debris Date: Thu, 27 Jul 2017 22:44:45 +0200 Subject: [PATCH] Proper building virtual manifest with -p flag --- .gitignore | 3 +- src/bin/bench.rs | 11 +- src/bin/build.rs | 11 +- src/bin/check.rs | 11 +- src/bin/doc.rs | 2 +- src/bin/test.rs | 11 +- src/cargo/ops/cargo_compile.rs | 4 +- tests/bench.rs | 404 +++++++++++++-------------------- tests/build.rs | 34 +++ 9 files changed, 219 insertions(+), 272 deletions(-) diff --git a/.gitignore b/.gitignore index e0d63ba2e18..df490beb2f3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ src/registry/Cargo.lock rustc __pycache__ .idea/ -*.iml \ No newline at end of file +*.iml +*.swp diff --git a/src/bin/bench.rs b/src/bin/bench.rs index 31004a2d4cf..d164c7a81b6 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -102,13 +102,10 @@ pub fn execute(options: Options, config: &Config) -> CliResult { let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; - let spec = if options.flag_all || ws.is_virtual() { - Packages::All - } else { - Packages::from_flags(options.flag_all, - &options.flag_exclude, - &options.flag_package)? - }; + let spec = Packages::from_flags(ws.is_virtual(), + options.flag_all, + &options.flag_exclude, + &options.flag_package)?; let ops = ops::TestOptions { no_run: options.flag_no_run, diff --git a/src/bin/build.rs b/src/bin/build.rs index 9f0757aa368..04a108a4030 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -94,13 +94,10 @@ pub fn execute(options: Options, config: &Config) -> CliResult { let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; - let spec = if options.flag_all || ws.is_virtual() { - Packages::All - } else { - Packages::from_flags(options.flag_all, - &options.flag_exclude, - &options.flag_package)? - }; + let spec = Packages::from_flags(ws.is_virtual(), + options.flag_all, + &options.flag_exclude, + &options.flag_package)?; let opts = CompileOptions { config: config, diff --git a/src/bin/check.rs b/src/bin/check.rs index 03c15e62497..ed4942de61c 100644 --- a/src/bin/check.rs +++ b/src/bin/check.rs @@ -91,13 +91,10 @@ pub fn execute(options: Options, config: &Config) -> CliResult { let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; - let spec = if options.flag_all || ws.is_virtual() { - Packages::All - } else { - Packages::from_flags(options.flag_all, - &options.flag_exclude, - &options.flag_package)? - }; + let spec = Packages::from_flags(ws.is_virtual(), + options.flag_all, + &options.flag_exclude, + &options.flag_package)?; let opts = CompileOptions { config: config, diff --git a/src/bin/doc.rs b/src/bin/doc.rs index cfa1116d88f..25aa0ec8a49 100644 --- a/src/bin/doc.rs +++ b/src/bin/doc.rs @@ -83,7 +83,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult { let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; - let spec = if options.flag_all || ws.is_virtual() { + let spec = if options.flag_all || (ws.is_virtual() && options.flag_package.is_empty()) { Packages::All } else { Packages::Packages(&options.flag_package) diff --git a/src/bin/test.rs b/src/bin/test.rs index daef1e47223..7010fbad441 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -138,13 +138,10 @@ pub fn execute(options: Options, config: &Config) -> CliResult { &options.flag_bench, options.flag_benches); } - let spec = if options.flag_all || ws.is_virtual() { - Packages::All - } else { - Packages::from_flags(options.flag_all, - &options.flag_exclude, - &options.flag_package)? - }; + let spec = Packages::from_flags(ws.is_virtual(), + options.flag_all, + &options.flag_exclude, + &options.flag_package)?; let ops = ops::TestOptions { no_run: options.flag_no_run, diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index de2cc1e2b56..c1b0243e786 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -110,9 +110,11 @@ pub enum Packages<'a> { } impl<'a> Packages<'a> { - pub fn from_flags(all: bool, exclude: &'a Vec, package: &'a Vec) + pub fn from_flags(virtual_ws: bool, all: bool, exclude: &'a Vec, package: &'a Vec) -> CargoResult { + let all = all || (virtual_ws && package.is_empty()); + let packages = match (all, &exclude) { (true, exclude) if exclude.is_empty() => Packages::All, (true, exclude) => Packages::OptOut(exclude), diff --git a/tests/bench.rs b/tests/bench.rs index 9c848d0b1d8..728536d80b2 100644 --- a/tests/bench.rs +++ b/tests/bench.rs @@ -16,7 +16,7 @@ fn cargo_bench_simple() { let p = project("foo") .file("Cargo.toml", &basic_bin_manifest("foo")) - .file("src/foo.rs", r#" + .file("src/main.rs", r#" #![feature(test)] extern crate test; @@ -44,13 +44,7 @@ fn cargo_bench_simple() { [COMPILING] foo v0.5.0 ({}) [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]foo-[..][EXE]", p.url())) - .with_stdout(" -running 1 test -test bench_hello ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains("test bench_hello ... bench: [..]")); } #[test] @@ -85,13 +79,7 @@ fn bench_bench_implicit() { [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]mybench-[..][EXE] ", dir = prj.url())) - .with_stdout(" -running 1 test -test run2 ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains("test run2 ... bench: [..]")); } #[test] @@ -126,13 +114,7 @@ fn bench_bin_implicit() { [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]foo-[..][EXE] ", dir = prj.url())) - .with_stdout(" -running 1 test -test run1 ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains("test run1 ... bench: [..]")); } #[test] @@ -162,13 +144,7 @@ fn bench_tarname() { [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]bin2-[..][EXE] ", dir = prj.url())) - .with_stdout(" -running 1 test -test run2 ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains("test run2 ... bench: [..]")); } #[test] @@ -177,7 +153,7 @@ fn cargo_bench_verbose() { let p = project("foo") .file("Cargo.toml", &basic_bin_manifest("foo")) - .file("src/foo.rs", r#" + .file("src/main.rs", r#" #![feature(test)] extern crate test; fn main() {} @@ -187,16 +163,10 @@ fn cargo_bench_verbose() { assert_that(p.cargo_process("bench").arg("-v").arg("hello"), execs().with_stderr(&format!("\ [COMPILING] foo v0.5.0 ({url}) -[RUNNING] `rustc [..] src[/]foo.rs [..]` +[RUNNING] `rustc [..] src[/]main.rs [..]` [FINISHED] release [optimized] target(s) in [..] [RUNNING] `[..]target[/]release[/]deps[/]foo-[..][EXE] hello --bench`", url = p.url())) - .with_stdout(" -running 1 test -test bench_hello ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains("test bench_hello ... bench: [..]")); } #[test] @@ -243,7 +213,7 @@ fn cargo_bench_failing_test() { let p = project("foo") .file("Cargo.toml", &basic_bin_manifest("foo")) - .file("src/foo.rs", r#" + .file("src/main.rs", r#" #![feature(test)] extern crate test; fn hello() -> &'static str { @@ -266,18 +236,16 @@ fn cargo_bench_failing_test() { execs().with_stdout("hello\n")); assert_that(p.cargo("bench"), - execs().with_stdout_contains(" -running 1 test -test bench_hello ... ") + execs().with_stdout_contains("test bench_hello ... ") .with_stderr_contains(format!("\ [COMPILING] foo v0.5.0 ({}) [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]foo-[..][EXE] thread '[..]' panicked at 'assertion failed: \ - `(left == right)` (left: \ - `\"hello\"`, right: `\"nope\"`)', src[/]foo.rs:14 -[..] -", p.url())) + `(left == right)`[..]", p.url())) + .with_stderr_contains("[..]left: `\"hello\"`[..]") + .with_stderr_contains("[..]right: `\"nope\"`[..]") + .with_stderr_contains("[..]src[/]main.rs:14[..]") .with_status(101)); } @@ -327,19 +295,8 @@ fn bench_with_lib_dep() { [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]foo-[..][EXE] [RUNNING] target[/]release[/]deps[/]baz-[..][EXE]", p.url())) - .with_stdout(" -running 1 test -test lib_bench ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - - -running 1 test -test bin_bench ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")) + .with_stdout_contains("test lib_bench ... bench: [..]") + .with_stdout_contains("test bin_bench ... bench: [..]")); } #[test] @@ -390,13 +347,7 @@ fn bench_with_deep_lib_dep() { [COMPILING] bar v0.0.1 ({dir}) [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]bar-[..][EXE]", dir = p.url())) - .with_stdout(" -running 1 test -test bar_bench ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains("test bar_bench ... bench: [..]")); } #[test] @@ -437,19 +388,8 @@ fn external_bench_explicit() { [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]foo-[..][EXE] [RUNNING] target[/]release[/]deps[/]bench-[..][EXE]", p.url())) - .with_stdout(" -running 1 test -test internal_bench ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - - -running 1 test -test external_bench ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")) + .with_stdout_contains("test internal_bench ... bench: [..]") + .with_stdout_contains("test external_bench ... bench: [..]")); } #[test] @@ -487,19 +427,8 @@ fn external_bench_implicit() { [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]foo-[..][EXE] [RUNNING] target[/]release[/]deps[/]external-[..][EXE]", p.url())) - .with_stdout(" -running 1 test -test internal_bench ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - - -running 1 test -test external_bench ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")) + .with_stdout_contains("test internal_bench ... bench: [..]") + .with_stdout_contains("test external_bench ... bench: [..]")); } #[test] @@ -547,25 +476,13 @@ fn pass_through_command_line() { [COMPILING] foo v0.0.1 ({dir}) [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]foo-[..][EXE]", dir = p.url())) - .with_stdout(" -running 1 test -test bar ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains("test bar ... bench: [..]")); assert_that(p.cargo("bench").arg("foo"), execs().with_status(0) .with_stderr("[FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]foo-[..][EXE]") - .with_stdout(" -running 1 test -test foo ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains("test foo ... bench: [..]")); } // Regression test for running cargo-bench twice with @@ -630,19 +547,7 @@ fn lib_bin_same_name() { [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]foo-[..][EXE] [RUNNING] target[/]release[/]deps[/]foo-[..][EXE]", p.url())) - .with_stdout(" -running 1 test -test [..] ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - - -running 1 test -test [..] ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")) + .with_stdout_contains_n("test [..] ... bench: [..]", 2)); } #[test] @@ -684,19 +589,8 @@ fn lib_with_standard_name() { [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]syntax-[..][EXE] [RUNNING] target[/]release[/]deps[/]bench-[..][EXE]", dir = p.url())) - .with_stdout(" -running 1 test -test foo_bench ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - - -running 1 test -test bench ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains("test foo_bench ... bench: [..]") + .with_stdout_contains("test bench ... bench: [..]")); } #[test] @@ -735,13 +629,7 @@ fn lib_with_standard_name2() { [COMPILING] syntax v0.0.1 ({dir}) [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]syntax-[..][EXE]", dir = p.url())) - .with_stdout(" -running 1 test -test bench ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains("test bench ... bench: [..]")); } #[test] @@ -806,19 +694,8 @@ fn bench_dylib() { [FINISHED] release [optimized] target(s) in [..] [RUNNING] `[..]target[/]release[/]deps[/]foo-[..][EXE] --bench` [RUNNING] `[..]target[/]release[/]deps[/]bench-[..][EXE] --bench`", dir = p.url())) - .with_stdout(" -running 1 test -test foo ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured + .with_stdout_contains_n("test foo ... bench: [..]", 2)); - -running 1 test -test foo ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); p.root().move_into_the_past(); assert_that(p.cargo("bench").arg("-v"), execs().with_status(0) @@ -828,19 +705,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured [FINISHED] release [optimized] target(s) in [..] [RUNNING] `[..]target[/]release[/]deps[/]foo-[..][EXE] --bench` [RUNNING] `[..]target[/]release[/]deps[/]bench-[..][EXE] --bench`", dir = p.url())) - .with_stdout(" -running 1 test -test foo ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - - -running 1 test -test foo ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains_n("test foo ... bench: [..]", 2)); } #[test] @@ -869,25 +734,13 @@ fn bench_twice_with_build_cmd() { [COMPILING] foo v0.0.1 ({dir}) [FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]foo-[..][EXE]", dir = p.url())) - .with_stdout(" -running 1 test -test foo ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains("test foo ... bench: [..]")); assert_that(p.cargo("bench"), execs().with_status(0) .with_stderr("[FINISHED] release [optimized] target(s) in [..] [RUNNING] target[/]release[/]deps[/]foo-[..][EXE]") - .with_stdout(" -running 1 test -test foo ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains("test foo ... bench: [..]")); } #[test] @@ -956,19 +809,8 @@ fn bench_with_examples() { [RUNNING] `{dir}[/]target[/]release[/]deps[/]testbench-[..][EXE] --bench` [RUNNING] `{dir}[/]target[/]release[/]deps[/]testb1-[..][EXE] --bench`", dir = p.root().display(), url = p.url())) - .with_stdout(" -running 1 test -test bench_bench1 ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - - -running 1 test -test bench_bench2 ... bench: [..] 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured - -")); + .with_stdout_contains("test bench_bench1 ... bench: [..]") + .with_stdout_contains("test bench_bench2 ... bench: [..]")); } #[test] @@ -1003,13 +845,7 @@ fn test_a_bench() { [COMPILING] foo v0.1.0 ([..]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] [RUNNING] target[/]debug[/]deps[/]b-[..][EXE]") - .with_stdout(" -running 1 test -test foo ... ok - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured - -")); + .with_stdout_contains("test foo ... ok")); } #[test] @@ -1043,6 +879,44 @@ fn test_bench_no_run() { ")); } +#[test] +fn test_bench_no_fail_fast() { + if !is_nightly() { return } + + let p = project("foo") + .file("Cargo.toml", &basic_bin_manifest("foo")) + .file("src/foo.rs", r#" + #![feature(test)] + extern crate test; + fn hello() -> &'static str { + "hello" + } + + pub fn main() { + println!("{}", hello()) + } + + #[bench] + fn bench_hello(_b: &mut test::Bencher) { + assert_eq!(hello(), "hello") + } + + #[bench] + fn bench_nope(_b: &mut test::Bencher) { + assert_eq!("nope", hello()) + }"#); + + assert_that(p.cargo_process("bench").arg("--no-fail-fast"), + execs().with_status(101) + .with_stderr_contains("\ +[RUNNING] target[/]release[/]deps[/]foo-[..][EXE]") + .with_stdout_contains("running 2 tests") + .with_stderr_contains("\ +[RUNNING] target[/]release[/]deps[/]foo-[..][EXE]") + .with_stdout_contains("test bench_hello [..]") + .with_stdout_contains("test bench_nope [..]")); +} + #[test] fn test_bench_multiple_packages() { if !is_nightly() { return } @@ -1113,20 +987,10 @@ fn test_bench_multiple_packages() { execs().with_status(0) .with_stderr_contains("\ [RUNNING] target[/]release[/]deps[/]bbaz-[..][EXE]") - .with_stdout_contains(" -running 1 test -test bench_baz ... bench: 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured -") + .with_stdout_contains("test bench_baz ... bench: [..]") .with_stderr_contains("\ [RUNNING] target[/]release[/]deps[/]bbar-[..][EXE]") - .with_stdout_contains(" -running 1 test -test bench_bar ... bench: 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured -")); + .with_stdout_contains("test bench_bar ... bench: [..]")); } #[test] @@ -1179,20 +1043,63 @@ fn bench_all_workspace() { execs().with_status(0) .with_stderr_contains("\ [RUNNING] target[/]release[/]deps[/]bar-[..][EXE]") - .with_stdout_contains(" -running 1 test -test bench_bar ... bench: 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured -") - .with_stderr_contains("\ + .with_stdout_contains("test bench_bar ... bench: [..]") + .with_stderr_contains("\ [RUNNING] target[/]release[/]deps[/]foo-[..][EXE]") - .with_stdout_contains(" -running 1 test -test bench_foo ... bench: 0 ns/iter (+/- 0) + .with_stdout_contains("test bench_foo ... bench: [..]")); +} -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured -")); +#[test] +fn bench_all_exclude() { + if !is_nightly() { return } + + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.1.0" + + [workspace] + members = ["bar", "baz"] + "#) + .file("src/main.rs", r#" + fn main() {} + "#) + .file("bar/Cargo.toml", r#" + [project] + name = "bar" + version = "0.1.0" + "#) + .file("bar/src/lib.rs", r#" + #![feature(test)] + + extern crate test; + + #[bench] + pub fn bar(b: &mut test::Bencher) { + b.iter(|| {}); + } + "#) + .file("baz/Cargo.toml", r#" + [project] + name = "baz" + version = "0.1.0" + "#) + .file("baz/src/lib.rs", r#" + #[test] + pub fn baz() { + break_the_build(); + } + "#); + + assert_that(p.cargo_process("bench") + .arg("--all") + .arg("--exclude") + .arg("baz"), + execs().with_status(0) + .with_stdout_contains("\ +running 1 test +test bar ... bench: [..] ns/iter (+/- [..])")); } #[test] @@ -1245,20 +1152,42 @@ fn bench_all_virtual_manifest() { execs().with_status(0) .with_stderr_contains("\ [RUNNING] target[/]release[/]deps[/]bar-[..][EXE]") - .with_stdout_contains(" -running 1 test -test bench_bar ... bench: 0 ns/iter (+/- 0) - -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured -") - .with_stderr_contains("\ + .with_stdout_contains("test bench_bar ... bench: [..]") + .with_stderr_contains("\ [RUNNING] target[/]release[/]deps[/]foo-[..][EXE]") - .with_stdout_contains(" -running 1 test -test bench_foo ... bench: 0 ns/iter (+/- 0) + .with_stdout_contains("test bench_foo ... bench: [..]")); +} -test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured -")); +// https://github.com/rust-lang/cargo/issues/4287 +#[test] +fn legacy_bench_name() { + if !is_nightly() { return } + + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.1.0" + + [[bench]] + name = "bench" + "#) + .file("src/lib.rs", r#" + pub fn foo() {} + "#) + .file("src/bench.rs", r#" + #![feature(test)] + extern crate test; + + use test::Bencher; + + #[bench] + fn bench_foo(_: &mut Bencher) -> () { () } + "#); + + assert_that(p.cargo_process("bench"), execs().with_status(0).with_stderr_contains("\ +[WARNING] path `[..]src[/]bench.rs` was erroneously implicitly accepted for benchmark `bench`, +please set bench.path in Cargo.toml")); } #[test] @@ -1281,9 +1210,7 @@ fn bench_virtual_manifest_all_implied() { .file("foo/benches/foo.rs", r#" #![feature(test)] extern crate test; - use test::Bencher; - #[bench] fn bench_foo(_: &mut Bencher) -> () { () } "#) @@ -1298,9 +1225,7 @@ fn bench_virtual_manifest_all_implied() { .file("bar/benches/bar.rs", r#" #![feature(test)] extern crate test; - use test::Bencher; - #[bench] fn bench_bar(_: &mut Bencher) -> () { () } "#); @@ -1313,7 +1238,6 @@ fn bench_virtual_manifest_all_implied() { .with_stdout_contains(" running 1 test test bench_bar ... bench: 0 ns/iter (+/- 0) - test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured ") .with_stderr_contains("\ @@ -1321,8 +1245,6 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured .with_stdout_contains(" running 1 test test bench_foo ... bench: 0 ns/iter (+/- 0) - test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured ")); } - diff --git a/tests/build.rs b/tests/build.rs index 4bb3fd91351..bc203eef69f 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -3072,6 +3072,40 @@ fn build_virtual_manifest_all_implied() { [..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n")); } +#[test] +fn build_virtual_manifest_one_project() { + let p = project("workspace") + .file("Cargo.toml", r#" + [workspace] + members = ["foo", "bar"] + "#) + .file("foo/Cargo.toml", r#" + [project] + name = "foo" + version = "0.1.0" + "#) + .file("foo/src/lib.rs", r#" + pub fn foo() {} + "#) + .file("bar/Cargo.toml", r#" + [project] + name = "bar" + version = "0.1.0" + "#) + .file("bar/src/lib.rs", r#" + pub fn bar() {} + "#); + + // The order in which foo and bar are built is not guaranteed + assert_that(p.cargo_process("build") + .arg("-p").arg("foo"), + execs().with_status(0) + .with_stderr_does_not_contain("[..] Compiling bar v0.1.0 ([..])") + .with_stderr_contains("[..] Compiling foo v0.1.0 ([..])") + .with_stderr("[..] Compiling [..] v0.1.0 ([..])\n\ + [..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n")); +} + #[test] fn build_all_virtual_manifest_implicit_examples() { let p = project("foo")