test(bench): glob support for package selection

This commit is contained in:
Weihang Lo 2020-10-04 23:29:11 +08:00
parent f1de239450
commit a06ec889f4
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7

View File

@ -1458,6 +1458,55 @@ test bar ... bench: [..] ns/iter (+/- [..])",
.run();
}
#[cargo_test]
fn bench_all_exclude_glob() {
if !is_nightly() {
return;
}
let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.1.0"
[workspace]
members = ["bar", "baz"]
"#,
)
.file("src/main.rs", "fn main() {}")
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
.file(
"bar/src/lib.rs",
r#"
#![feature(test)]
#[cfg(test)]
extern crate test;
#[bench]
pub fn bar(b: &mut test::Bencher) {
b.iter(|| {});
}
"#,
)
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
.file(
"baz/src/lib.rs",
"#[test] pub fn baz() { break_the_build(); }",
)
.build();
p.cargo("bench --workspace --exclude '*z'")
.with_stdout_contains(
"\
running 1 test
test bar ... bench: [..] ns/iter (+/- [..])",
)
.run();
}
#[cargo_test]
fn bench_all_virtual_manifest() {
if !is_nightly() {
@ -1511,6 +1560,59 @@ fn bench_all_virtual_manifest() {
.run();
}
#[cargo_test]
fn bench_virtual_manifest_glob() {
if !is_nightly() {
return;
}
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["bar", "baz"]
"#,
)
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
.file("bar/src/lib.rs", "pub fn bar() { break_the_build(); }")
.file(
"bar/benches/bar.rs",
r#"
#![feature(test)]
extern crate test;
use test::Bencher;
#[bench]
fn bench_bar(_: &mut Bencher) -> () { break_the_build(); }
"#,
)
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
.file("baz/src/lib.rs", "pub fn baz() {}")
.file(
"baz/benches/baz.rs",
r#"
#![feature(test)]
extern crate test;
use test::Bencher;
#[bench]
fn bench_baz(_: &mut Bencher) -> () { () }
"#,
)
.build();
// The order in which bar and baz are built is not guaranteed
p.cargo("bench -p '*z'")
.with_stderr_contains("[RUNNING] target/release/deps/baz-[..][EXE]")
.with_stdout_contains("test bench_baz ... bench: [..]")
.with_stderr_does_not_contain("[RUNNING] target/release/deps/bar-[..][EXE]")
.with_stdout_does_not_contain("test bench_bar ... bench: [..]")
.run();
}
// https://github.com/rust-lang/cargo/issues/4287
#[cargo_test]
fn legacy_bench_name() {