2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for the `cargo bench` command.
|
|
|
|
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::paths::CargoPathExt;
|
|
|
|
use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, project};
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cargo_bench_simple() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2015-03-26 18:17:44 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
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")
|
2020-09-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo").is_file());
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 21:05:39 +00:00
|
|
|
p.process(&p.bin("foo")).with_stdout("hello\n").run();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.5.0 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test bench_hello ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2017-04-05 18:50:22 +00:00
|
|
|
fn bench_bench_implicit() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2019-07-31 19:46:29 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2017-04-05 18:50:22 +00:00
|
|
|
extern crate test;
|
|
|
|
#[bench] fn run1(_ben: &mut test::Bencher) { }
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() { println!("Hello main!"); }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"tests/other.rs",
|
|
|
|
r#"
|
2017-04-05 18:50:22 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench] fn run3(_ben: &mut test::Bencher) { }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/mybench.rs",
|
|
|
|
r#"
|
2017-04-05 18:50:22 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench] fn run2(_ben: &mut test::Bencher) { }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-04-05 18:50:22 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench --benches")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/release/deps/mybench-[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test run2 ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-04-05 18:50:22 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2017-04-05 18:50:22 +00:00
|
|
|
fn bench_bin_implicit() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-04-05 18:50:22 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2017-04-05 18:50:22 +00:00
|
|
|
extern crate test;
|
|
|
|
#[bench] fn run1(_ben: &mut test::Bencher) { }
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() { println!("Hello main!"); }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"tests/other.rs",
|
|
|
|
r#"
|
2017-04-05 18:50:22 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench] fn run3(_ben: &mut test::Bencher) { }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/mybench.rs",
|
|
|
|
r#"
|
2017-04-05 18:50:22 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench] fn run2(_ben: &mut test::Bencher) { }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-04-05 18:50:22 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench --bins")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test run1 ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-04-05 18:50:22 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn bench_tarname() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"benches/bin1.rs",
|
|
|
|
r#"
|
2015-03-26 18:17:44 +00:00
|
|
|
#![feature(test)]
|
2014-10-28 08:31:34 +00:00
|
|
|
extern crate test;
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench] fn run1(_ben: &mut test::Bencher) { }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/bin2.rs",
|
|
|
|
r#"
|
2015-03-26 18:17:44 +00:00
|
|
|
#![feature(test)]
|
2014-10-28 08:31:34 +00:00
|
|
|
extern crate test;
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench] fn run2(_ben: &mut test::Bencher) { }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-10-28 08:31:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench --bench bin2")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/bin2-[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test run2 ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-28 08:31:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2017-09-30 14:51:42 +00:00
|
|
|
fn bench_multiple_targets() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"benches/bin1.rs",
|
|
|
|
r#"
|
2017-09-30 14:51:42 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench] fn run1(_ben: &mut test::Bencher) { }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/bin2.rs",
|
|
|
|
r#"
|
2017-09-30 14:51:42 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench] fn run2(_ben: &mut test::Bencher) { }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/bin3.rs",
|
|
|
|
r#"
|
2017-09-30 14:51:42 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench] fn run3(_ben: &mut test::Bencher) { }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-09-30 14:51:42 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench --bench bin1 --bench bin2")
|
|
|
|
.with_stdout_contains("test run1 ... bench: [..]")
|
|
|
|
.with_stdout_contains("test run2 ... bench: [..]")
|
|
|
|
.with_stdout_does_not_contain("[..]run3[..]")
|
|
|
|
.run();
|
2017-09-30 14:51:42 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cargo_bench_verbose() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
extern crate test;
|
|
|
|
fn main() {}
|
|
|
|
#[bench] fn bench_hello(_b: &mut test::Bencher) {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench -v hello")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.5.0 ([CWD])
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `rustc [..] src/main.rs [..]`
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `[..]target/release/deps/foo-[..][EXE] hello --bench`",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test bench_hello ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn many_similar_names() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2015-03-26 18:17:44 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate test;
|
|
|
|
pub fn foo() {}
|
|
|
|
#[bench] fn lib_bench(_b: &mut test::Bencher) {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/main.rs",
|
|
|
|
"
|
2015-03-26 18:17:44 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate foo;
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate test;
|
|
|
|
fn main() {}
|
|
|
|
#[bench] fn bin_bench(_b: &mut test::Bencher) { foo::foo() }
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/foo.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate foo;
|
|
|
|
extern crate test;
|
|
|
|
#[bench] fn bench_bench(_b: &mut test::Bencher) { foo::foo() }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 22:11:30 +00:00
|
|
|
p.cargo("bench")
|
|
|
|
.with_stdout_contains("test bin_bench ... bench: 0 ns/iter (+/- 0)")
|
|
|
|
.with_stdout_contains("test lib_bench ... bench: 0 ns/iter (+/- 0)")
|
|
|
|
.with_stdout_contains("test bench_bench ... bench: 0 ns/iter (+/- 0)")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cargo_bench_failing_test() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2015-01-30 21:22:02 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate test;
|
|
|
|
fn hello() -> &'static str {
|
|
|
|
"hello"
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
println!("{}", hello())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_hello(_b: &mut test::Bencher) {
|
|
|
|
assert_eq!(hello(), "nope")
|
2020-09-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo").is_file());
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 21:05:39 +00:00
|
|
|
p.process(&p.bin("foo")).with_stdout("hello\n").run();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-01-22 20:27:50 +00:00
|
|
|
// Force libtest into serial execution so that the test header will be printed.
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench -- --test-threads=1")
|
|
|
|
.with_stdout_contains("test bench_hello ...[..]")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr_contains(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.5.0 ([CWD])[..]
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
2023-07-29 16:12:46 +00:00
|
|
|
.with_stdout_contains("[..]thread '[..]' panicked at[..]")
|
2023-08-14 18:10:17 +00:00
|
|
|
.with_stdout_contains("[..]assertion [..]failed[..]")
|
|
|
|
.with_stdout_contains("[..]left: [..]\"hello\"[..]")
|
|
|
|
.with_stdout_contains("[..]right: [..]\"nope\"[..]")
|
2021-06-16 00:48:05 +00:00
|
|
|
.with_stdout_contains("[..]src/main.rs:15[..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_status(101)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn bench_with_lib_dep() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bin]]
|
|
|
|
name = "baz"
|
|
|
|
path = "src/main.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
extern crate test;
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// extern crate foo;
|
|
|
|
/// fn main() {
|
|
|
|
/// println!("{}", foo::foo());
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
pub fn foo(){}
|
|
|
|
#[bench] fn lib_bench(_b: &mut test::Bencher) {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/main.rs",
|
|
|
|
"
|
2015-03-26 18:17:44 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate foo;
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bin_bench(_b: &mut test::Bencher) {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/release/deps/baz-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test lib_bench ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test bin_bench ... bench: [..]")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn bench_with_deep_lib_dep() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project()
|
|
|
|
.at("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.foo]
|
|
|
|
path = "../foo"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2019-07-31 19:46:29 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate foo;
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate test;
|
|
|
|
#[bench]
|
|
|
|
fn bar_bench(_b: &mut test::Bencher) {
|
|
|
|
foo::foo();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-07-20 11:47:47 +00:00
|
|
|
let _p2 = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2019-07-31 19:46:29 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
pub fn foo() {}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn foo_bench(_b: &mut test::Bencher) {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] bar v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/bar-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test bar_bench ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn external_bench_explicit() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bench]]
|
|
|
|
name = "bench"
|
|
|
|
path = "src/bench.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
extern crate test;
|
|
|
|
pub fn get_hello() -> &'static str { "Hello" }
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn internal_bench(_b: &mut test::Bencher) {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/bench.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
#[allow(unused_extern_crates)]
|
|
|
|
extern crate foo;
|
|
|
|
extern crate test;
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn external_bench(_b: &mut test::Bencher) {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/release/deps/bench-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test internal_bench ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test external_bench ... bench: [..]")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn external_bench_implicit() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
extern crate test;
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
pub fn get_hello() -> &'static str { "Hello" }
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn internal_bench(_b: &mut test::Bencher) {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/external.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
#[allow(unused_extern_crates)]
|
|
|
|
extern crate foo;
|
|
|
|
extern crate test;
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn external_bench(_b: &mut test::Bencher) {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/release/deps/external-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test internal_bench ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test external_bench ... bench: [..]")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2018-04-16 22:19:42 +00:00
|
|
|
fn bench_autodiscover_2015() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-16 22:19:42 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2018-09-05 22:29:22 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
edition = "2015"
|
2020-07-12 14:52:31 +00:00
|
|
|
|
2020-02-28 18:55:18 +00:00
|
|
|
[features]
|
|
|
|
magic = []
|
2018-09-05 22:29:22 +00:00
|
|
|
|
|
|
|
[[bench]]
|
|
|
|
name = "bench_magic"
|
|
|
|
required-features = ["magic"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-04-16 22:19:42 +00:00
|
|
|
.file(
|
|
|
|
"benches/bench_basic.rs",
|
|
|
|
r#"
|
2018-09-05 22:29:22 +00:00
|
|
|
#![feature(test)]
|
|
|
|
#[allow(unused_extern_crates)]
|
|
|
|
extern crate foo;
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_basic(_b: &mut test::Bencher) {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-04-16 22:19:42 +00:00
|
|
|
"benches/bench_magic.rs",
|
|
|
|
r#"
|
2018-09-05 22:29:22 +00:00
|
|
|
#![feature(test)]
|
|
|
|
#[allow(unused_extern_crates)]
|
|
|
|
extern crate foo;
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_magic(_b: &mut test::Bencher) {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-04-16 22:19:42 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench bench_basic")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-04-16 22:19:42 +00:00
|
|
|
"warning: \
|
2018-04-20 21:22:41 +00:00
|
|
|
An explicit [[bench]] section is specified in Cargo.toml which currently
|
|
|
|
disables Cargo from automatically inferring other benchmark targets.
|
|
|
|
This inference behavior will change in the Rust 2018 edition and the following
|
|
|
|
files will be included as a benchmark target:
|
2018-04-16 22:19:42 +00:00
|
|
|
|
2018-04-20 21:21:33 +00:00
|
|
|
* [..]bench_basic.rs
|
2018-04-16 22:19:42 +00:00
|
|
|
|
2018-04-20 21:22:41 +00:00
|
|
|
This is likely to break cargo build or cargo test as these files may not be
|
|
|
|
ready to be compiled as a benchmark target today. You can future-proof yourself
|
2018-04-20 21:23:08 +00:00
|
|
|
and disable this warning by adding `autobenches = false` to your [package]
|
2018-04-20 21:22:41 +00:00
|
|
|
section. You may also move the files to a location where Cargo would not
|
|
|
|
automatically infer them to be a target, such as in subfolders.
|
2018-04-16 22:19:42 +00:00
|
|
|
|
2018-04-20 21:22:41 +00:00
|
|
|
For more information on this warning you can consult
|
|
|
|
https://github.com/rust-lang/cargo/issues/5330
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
|
2018-04-16 22:19:42 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-04-16 22:19:42 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn dont_run_examples() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2020-09-27 00:59:58 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"examples/dont-run-me-i-will-fail.rs",
|
2018-07-25 00:30:32 +00:00
|
|
|
r#"fn main() { panic!("Examples should not be run by 'cargo test'"); }"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn pass_through_command_line() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2015-03-26 18:17:44 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench] fn foo(_b: &mut test::Bencher) {}
|
|
|
|
#[bench] fn bar(_b: &mut test::Bencher) {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench bar")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test bar ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench foo")
|
|
|
|
.with_stderr(
|
2019-06-09 17:32:09 +00:00
|
|
|
"[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test foo ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
|
|
|
// Regression test for running cargo-bench twice with
|
|
|
|
// tests in an rlib
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cargo_bench_twice() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
2018-07-20 17:41:44 +00:00
|
|
|
"src/foo.rs",
|
2018-03-14 15:17:44 +00:00
|
|
|
r#"
|
2014-08-14 15:14:34 +00:00
|
|
|
#![crate_type = "rlib"]
|
2015-03-26 18:17:44 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn dummy_bench(b: &mut test::Bencher) { }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2015-03-22 23:58:11 +00:00
|
|
|
for _ in 0..2 {
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench").run();
|
2014-08-14 15:14:34 +00:00
|
|
|
}
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn lib_bin_same_name() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2019-07-31 19:46:29 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate test;
|
|
|
|
#[bench] fn lib_bench(_b: &mut test::Bencher) {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/main.rs",
|
|
|
|
"
|
2019-07-31 19:46:29 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate foo;
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bin_bench(_b: &mut test::Bencher) {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains_n("test [..] ... bench: [..]", 2)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn lib_with_standard_name() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("syntax", "0.0.1"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2019-07-31 19:46:29 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
/// syntax::foo();
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn foo_bench(_b: &mut test::Bencher) {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/bench.rs",
|
|
|
|
"
|
2015-03-26 18:17:44 +00:00
|
|
|
#![feature(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate syntax;
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench(_b: &mut test::Bencher) { syntax::foo() }
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] syntax v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/syntax-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/release/deps/bench-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test foo_bench ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test bench ... bench: [..]")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn lib_with_standard_name2() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "syntax"
|
|
|
|
bench = false
|
|
|
|
doctest = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "pub fn foo() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
2015-03-26 18:17:44 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate syntax;
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench(_b: &mut test::Bencher) { syntax::foo() }
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] syntax v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/syntax-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test bench ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn bench_dylib() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
crate_type = ["dylib"]
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate bar as the_bar;
|
|
|
|
#[cfg(test)]
|
|
|
|
extern crate test;
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
pub fn bar() { the_bar::baz(); }
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn foo(_b: &mut test::Bencher) {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/bench.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate foo as the_foo;
|
|
|
|
extern crate test;
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn foo(_b: &mut test::Bencher) { the_foo::bar(); }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "bar"
|
|
|
|
crate_type = ["dylib"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/src/lib.rs", "pub fn baz() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench -v")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] bar v0.0.1 ([CWD]/bar)
|
2016-05-11 16:55:43 +00:00
|
|
|
[RUNNING] [..] -C opt-level=3 [..]
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2016-05-11 16:55:43 +00:00
|
|
|
[RUNNING] [..] -C opt-level=3 [..]
|
|
|
|
[RUNNING] [..] -C opt-level=3 [..]
|
|
|
|
[RUNNING] [..] -C opt-level=3 [..]
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `[..]target/release/deps/foo-[..][EXE] --bench`
|
|
|
|
[RUNNING] `[..]target/release/deps/bench-[..][EXE] --bench`",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains_n("test foo ... bench: [..]", 2)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-05-26 21:00:45 +00:00
|
|
|
|
2016-05-26 00:06:25 +00:00
|
|
|
p.root().move_into_the_past();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench -v")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[FRESH] bar v0.0.1 ([CWD]/bar)
|
|
|
|
[FRESH] foo v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `[..]target/release/deps/foo-[..][EXE] --bench`
|
|
|
|
[RUNNING] `[..]target/release/deps/bench-[..][EXE] --bench`",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains_n("test foo ... bench: [..]", 2)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn bench_twice_with_build_cmd() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
build = "build.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("build.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2015-03-26 18:17:44 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2014-08-14 15:14:34 +00:00
|
|
|
extern crate test;
|
|
|
|
#[bench]
|
|
|
|
fn foo(_b: &mut test::Bencher) {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-14 15:14:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test foo ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
|
|
|
.with_stderr(
|
2019-06-09 17:32:09 +00:00
|
|
|
"[FINISHED] bench [optimized] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test foo ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-01-11 02:47:24 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn bench_with_examples() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "6.6.6"
|
|
|
|
authors = []
|
2015-01-11 02:47:24 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[example]]
|
|
|
|
name = "teste1"
|
2015-01-11 02:47:24 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bench]]
|
|
|
|
name = "testb1"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
extern crate test;
|
|
|
|
#[cfg(test)]
|
|
|
|
use test::Bencher;
|
2015-01-11 02:47:24 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
pub fn f1() {
|
|
|
|
println!("f1");
|
|
|
|
}
|
2015-01-11 02:47:24 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
pub fn f2() {}
|
2015-01-11 02:47:24 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn bench_bench1(_b: &mut Bencher) {
|
|
|
|
f2();
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/testb1.rs",
|
|
|
|
"
|
2015-03-26 18:17:44 +00:00
|
|
|
#![feature(test)]
|
2018-07-20 17:41:44 +00:00
|
|
|
extern crate foo;
|
2015-01-11 02:47:24 +00:00
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
use test::Bencher;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_bench2(_b: &mut Bencher) {
|
2018-07-20 17:41:44 +00:00
|
|
|
foo::f2();
|
2015-01-11 02:47:24 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"examples/teste1.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate foo;
|
2015-01-11 02:47:24 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {
|
|
|
|
println!("example1");
|
|
|
|
foo::f1();
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-01-11 02:47:24 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench -v")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v6.6.6 ([CWD])
|
2016-05-11 16:55:43 +00:00
|
|
|
[RUNNING] `rustc [..]`
|
|
|
|
[RUNNING] `rustc [..]`
|
|
|
|
[RUNNING] `rustc [..]`
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2018-09-08 02:42:26 +00:00
|
|
|
[RUNNING] `[CWD]/target/release/deps/foo-[..][EXE] --bench`
|
|
|
|
[RUNNING] `[CWD]/target/release/deps/testb1-[..][EXE] --bench`",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test bench_bench1 ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test bench_bench2 ... bench: [..]")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-03-24 01:01:27 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_a_bench() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.1.0"
|
2015-03-24 01:01:27 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
test = false
|
|
|
|
doctest = false
|
2015-03-24 01:01:27 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bench]]
|
|
|
|
name = "b"
|
|
|
|
test = true
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("benches/b.rs", "#[test] fn foo() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-03-24 01:01:27 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.1.0 ([..])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/b-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test foo ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_bench_no_run() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2016-02-02 10:30:28 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"benches/bbaz.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
2016-02-02 10:30:28 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate test;
|
2016-02-02 10:30:28 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
use test::Bencher;
|
2016-02-02 10:30:28 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn bench_baz(_: &mut Bencher) {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2016-02-02 10:30:28 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench --no-run")
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-07-24 13:01:56 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2019-06-09 17:32:09 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2022-02-02 16:17:09 +00:00
|
|
|
[EXECUTABLE] benches src/lib.rs (target/release/deps/foo-[..][EXE])
|
|
|
|
[EXECUTABLE] benches/bbaz.rs (target/release/deps/bbaz-[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-02-02 10:30:28 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2022-05-24 13:44:54 +00:00
|
|
|
fn test_bench_no_run_emit_json() {
|
|
|
|
let p = project()
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file(
|
|
|
|
"benches/bbaz.rs",
|
|
|
|
r#"
|
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
use test::Bencher;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_baz(_: &mut Bencher) {}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("bench --no-run --message-format json")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2017-07-27 20:44:45 +00:00
|
|
|
fn test_bench_no_fail_fast() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2017-07-27 20:44:45 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
2022-08-28 00:45:11 +00:00
|
|
|
"src/main.rs",
|
2018-03-14 15:17:44 +00:00
|
|
|
r#"
|
2017-07-27 20:44:45 +00:00
|
|
|
#![feature(test)]
|
2017-08-27 05:30:13 +00:00
|
|
|
#[cfg(test)]
|
2017-07-27 20:44:45 +00:00
|
|
|
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())
|
2020-09-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
2022-08-28 00:45:11 +00:00
|
|
|
.file(
|
|
|
|
"benches/b1.rs",
|
|
|
|
r#"
|
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
#[bench]
|
|
|
|
fn b1_fail(_b: &mut test::Bencher) { assert_eq!(1, 2); }
|
|
|
|
"#,
|
|
|
|
)
|
2018-12-08 11:19:47 +00:00
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
|
|
|
|
p.cargo("bench --no-fail-fast -- --test-threads=1")
|
|
|
|
.with_status(101)
|
2022-08-28 00:45:11 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.5.0 [..]
|
|
|
|
[FINISHED] bench [..]
|
|
|
|
[RUNNING] unittests src/main.rs (target/release/deps/foo[..])
|
|
|
|
[ERROR] bench failed, to rerun pass `--bin foo`
|
|
|
|
[RUNNING] benches/b1.rs (target/release/deps/b1[..])
|
|
|
|
[ERROR] bench failed, to rerun pass `--bench b1`
|
|
|
|
[ERROR] 2 targets failed:
|
|
|
|
`--bin foo`
|
|
|
|
`--bench b1`
|
|
|
|
",
|
|
|
|
)
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("running 2 tests")
|
|
|
|
.with_stdout_contains("test bench_hello [..]")
|
|
|
|
.with_stdout_contains("test bench_nope [..]")
|
2022-08-28 00:45:11 +00:00
|
|
|
.with_stdout_contains("test b1_fail [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-07-27 20:44:45 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_bench_multiple_packages() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.1.0"
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.baz]
|
|
|
|
path = "../baz"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
let _bar = project()
|
|
|
|
.at("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "bar"
|
|
|
|
authors = []
|
|
|
|
version = "0.1.0"
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bench]]
|
|
|
|
name = "bbar"
|
|
|
|
test = true
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"benches/bbar.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
use test::Bencher;
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn bench_bar(_b: &mut Bencher) {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
let _baz = project()
|
|
|
|
.at("baz")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "baz"
|
|
|
|
authors = []
|
|
|
|
version = "0.1.0"
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bench]]
|
|
|
|
name = "bbaz"
|
|
|
|
test = true
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"benches/bbaz.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
use test::Bencher;
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn bench_baz(_b: &mut Bencher) {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
|
|
|
|
p.cargo("bench -p bar -p baz")
|
2021-02-21 22:37:42 +00:00
|
|
|
.with_stderr_contains("[RUNNING] [..] (target/release/deps/bbaz-[..][EXE])")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test bench_baz ... bench: [..]")
|
2021-02-21 22:37:42 +00:00
|
|
|
.with_stderr_contains("[RUNNING] [..] (target/release/deps/bbar-[..][EXE])")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test bench_bar ... bench: [..]")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2017-05-02 13:46:30 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2017-05-02 13:46:30 +00:00
|
|
|
fn bench_all_workspace() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2017-05-02 13:46:30 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
2017-05-02 13:46:30 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"benches/foo.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2017-05-02 13:46:30 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
use test::Bencher;
|
2017-05-02 13:46:30 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn bench_foo(_: &mut Bencher) -> () { () }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/benches/bar.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2017-05-02 13:46:30 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
use test::Bencher;
|
2017-05-02 13:46:30 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn bench_bar(_: &mut Bencher) -> () { () }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("bench --workspace")
|
2021-02-21 22:37:42 +00:00
|
|
|
.with_stderr_contains("[RUNNING] [..] (target/release/deps/bar-[..][EXE])")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test bench_bar ... bench: [..]")
|
2021-02-21 22:37:42 +00:00
|
|
|
.with_stderr_contains("[RUNNING] [..] (target/release/deps/foo-[..][EXE])")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test bench_foo ... bench: [..]")
|
|
|
|
.run();
|
2017-07-27 20:44:45 +00:00
|
|
|
}
|
2017-05-26 21:00:45 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2017-07-27 20:44:45 +00:00
|
|
|
fn bench_all_exclude() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2017-07-27 20:44:45 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
extern crate test;
|
2017-07-27 20:44:45 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
pub fn bar(b: &mut test::Bencher) {
|
|
|
|
b.iter(|| {});
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
2018-08-28 09:20:03 +00:00
|
|
|
.file(
|
|
|
|
"baz/src/lib.rs",
|
|
|
|
"#[test] pub fn baz() { break_the_build(); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-07-27 20:44:45 +00:00
|
|
|
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("bench --workspace --exclude baz")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2017-07-27 20:44:45 +00:00
|
|
|
running 1 test
|
2018-03-14 15:17:44 +00:00
|
|
|
test bar ... bench: [..] ns/iter (+/- [..])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2017-05-02 13:46:30 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2020-10-04 15:29:11 +00:00
|
|
|
fn bench_all_exclude_glob() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-10-09 23:44:57 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2020-10-04 15:29:11 +00:00
|
|
|
|
2020-10-09 23:44:57 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
|
|
|
"#,
|
2020-10-04 15:29:11 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2020-10-09 23:44:57 +00:00
|
|
|
#![feature(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
extern crate test;
|
2020-10-04 15:29:11 +00:00
|
|
|
|
2020-10-09 23:44:57 +00:00
|
|
|
#[bench]
|
|
|
|
pub fn bar(b: &mut test::Bencher) {
|
|
|
|
b.iter(|| {});
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-04 15:29:11 +00:00
|
|
|
)
|
|
|
|
.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();
|
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2017-05-26 21:00:45 +00:00
|
|
|
fn bench_all_virtual_manifest() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
2018-07-20 17:41:44 +00:00
|
|
|
"bar/benches/bar.rs",
|
2018-03-14 15:17:44 +00:00
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2017-05-26 21:00:45 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
use test::Bencher;
|
2017-05-26 21:00:45 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn bench_bar(_: &mut Bencher) -> () { () }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("baz/src/lib.rs", "pub fn baz() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
2018-07-20 17:41:44 +00:00
|
|
|
"baz/benches/baz.rs",
|
2018-03-14 15:17:44 +00:00
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2017-05-12 13:44:15 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
use test::Bencher;
|
2017-05-26 21:00:45 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn bench_baz(_: &mut Bencher) -> () { () }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-05-12 13:44:15 +00:00
|
|
|
|
2018-07-20 17:41:44 +00:00
|
|
|
// The order in which bar and baz are built is not guaranteed
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("bench --workspace")
|
2021-02-21 22:37:42 +00:00
|
|
|
.with_stderr_contains("[RUNNING] [..] (target/release/deps/baz-[..][EXE])")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test bench_baz ... bench: [..]")
|
2021-02-21 22:37:42 +00:00
|
|
|
.with_stderr_contains("[RUNNING] [..] (target/release/deps/bar-[..][EXE])")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test bench_bar ... bench: [..]")
|
|
|
|
.run();
|
2017-07-27 20:44:45 +00:00
|
|
|
}
|
2017-05-26 21:00:45 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2020-10-04 15:29:11 +00:00
|
|
|
fn bench_virtual_manifest_glob() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-09 23:44:57 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
|
|
|
"#,
|
2020-10-04 15:29:11 +00:00
|
|
|
)
|
|
|
|
.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#"
|
2020-10-09 23:44:57 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2020-10-04 15:29:11 +00:00
|
|
|
|
2020-10-09 23:44:57 +00:00
|
|
|
use test::Bencher;
|
2020-10-04 15:29:11 +00:00
|
|
|
|
2020-10-09 23:44:57 +00:00
|
|
|
#[bench]
|
|
|
|
fn bench_bar(_: &mut Bencher) -> () { break_the_build(); }
|
|
|
|
"#,
|
2020-10-04 15:29:11 +00:00
|
|
|
)
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
|
|
|
.file("baz/src/lib.rs", "pub fn baz() {}")
|
|
|
|
.file(
|
|
|
|
"baz/benches/baz.rs",
|
|
|
|
r#"
|
2020-10-09 23:44:57 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2020-10-04 15:29:11 +00:00
|
|
|
|
2020-10-09 23:44:57 +00:00
|
|
|
use test::Bencher;
|
2020-10-04 15:29:11 +00:00
|
|
|
|
2020-10-09 23:44:57 +00:00
|
|
|
#[bench]
|
|
|
|
fn bench_baz(_: &mut Bencher) -> () { () }
|
|
|
|
"#,
|
2020-10-04 15:29:11 +00:00
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// The order in which bar and baz are built is not guaranteed
|
|
|
|
p.cargo("bench -p '*z'")
|
2021-02-21 22:37:42 +00:00
|
|
|
.with_stderr_contains("[RUNNING] [..] (target/release/deps/baz-[..][EXE])")
|
2020-10-04 15:29:11 +00:00
|
|
|
.with_stdout_contains("test bench_baz ... bench: [..]")
|
2021-02-21 22:37:42 +00:00
|
|
|
.with_stderr_does_not_contain("[RUNNING] [..] (target/release/deps/bar-[..][EXE])")
|
2020-10-04 15:29:11 +00:00
|
|
|
.with_stdout_does_not_contain("test bench_bar ... bench: [..]")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2017-07-27 20:44:45 +00:00
|
|
|
// https://github.com/rust-lang/cargo/issues/4287
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2017-07-27 20:44:45 +00:00
|
|
|
fn legacy_bench_name() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2017-07-27 20:44:45 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bench]]
|
|
|
|
name = "bench"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "pub fn foo() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/bench.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2017-07-27 20:44:45 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
use test::Bencher;
|
2017-07-27 20:44:45 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn bench_foo(_: &mut Bencher) -> () { () }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-07-27 20:44:45 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
|
|
|
.with_stderr_contains(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-08-02 09:18:48 +00:00
|
|
|
[WARNING] path `[..]src/bench.rs` was erroneously implicitly accepted for benchmark `bench`,
|
2018-03-14 15:17:44 +00:00
|
|
|
please set bench.path in Cargo.toml",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2017-05-12 13:44:15 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2017-05-26 21:00:45 +00:00
|
|
|
fn bench_virtual_manifest_all_implied() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn foo() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
2018-07-20 17:41:44 +00:00
|
|
|
"bar/benches/bar.rs",
|
2018-03-14 15:17:44 +00:00
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
use test::Bencher;
|
|
|
|
#[bench]
|
|
|
|
fn bench_bar(_: &mut Bencher) -> () { () }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("baz/src/lib.rs", "pub fn baz() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
2018-07-20 17:41:44 +00:00
|
|
|
"baz/benches/baz.rs",
|
2018-03-14 15:17:44 +00:00
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
use test::Bencher;
|
|
|
|
#[bench]
|
|
|
|
fn bench_baz(_: &mut Bencher) -> () { () }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-05-02 13:46:30 +00:00
|
|
|
|
2018-07-20 17:41:44 +00:00
|
|
|
// The order in which bar and baz are built is not guaranteed
|
2017-10-20 22:45:51 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
2021-02-21 22:37:42 +00:00
|
|
|
.with_stderr_contains("[RUNNING] [..] (target/release/deps/baz-[..][EXE])")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test bench_baz ... bench: [..]")
|
2021-02-21 22:37:42 +00:00
|
|
|
.with_stderr_contains("[RUNNING] [..] (target/release/deps/bar-[..][EXE])")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test bench_bar ... bench: [..]")
|
|
|
|
.run();
|
2017-07-17 10:10:47 +00:00
|
|
|
}
|
2018-11-30 14:31:01 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
2018-11-30 14:31:01 +00:00
|
|
|
fn json_artifact_includes_executable_for_benchmark() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"benches/benchmark.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
2018-11-30 14:31:01 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
use test::Bencher;
|
2018-11-30 14:31:01 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[bench]
|
|
|
|
fn bench_foo(_: &mut Bencher) -> () { () }
|
|
|
|
"#,
|
2018-11-30 14:31:01 +00:00
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("bench --no-run --message-format=json")
|
2018-12-08 11:19:47 +00:00
|
|
|
.with_json(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
{
|
|
|
|
"executable": "[..]/foo/target/release/deps/benchmark-[..][EXE]",
|
|
|
|
"features": [],
|
|
|
|
"filenames": "{...}",
|
|
|
|
"fresh": false,
|
2024-01-17 14:44:41 +00:00
|
|
|
"package_id": "path+file:///[..]/foo#0.0.1",
|
2020-12-28 13:33:32 +00:00
|
|
|
"manifest_path": "[..]",
|
2020-09-27 00:59:58 +00:00
|
|
|
"profile": "{...}",
|
|
|
|
"reason": "compiler-artifact",
|
|
|
|
"target": {
|
|
|
|
"crate_types": [ "bin" ],
|
|
|
|
"kind": [ "bench" ],
|
2020-11-18 01:54:17 +00:00
|
|
|
"doc": false,
|
2020-09-27 00:59:58 +00:00
|
|
|
"doctest": false,
|
|
|
|
"edition": "2015",
|
|
|
|
"name": "benchmark",
|
|
|
|
"src_path": "[..]/foo/benches/benchmark.rs",
|
|
|
|
"test": false
|
|
|
|
}
|
2018-11-30 14:31:01 +00:00
|
|
|
}
|
2020-04-05 01:54:20 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
{"reason": "build-finished", "success": true}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
2018-11-30 14:31:01 +00:00
|
|
|
.run();
|
|
|
|
}
|
2023-08-11 13:12:59 +00:00
|
|
|
|
2023-08-16 11:47:27 +00:00
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
|
|
|
fn cargo_bench_print_env_verbose() {
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "0.0.1"))
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
#![feature(test)]
|
|
|
|
#[cfg(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")
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
p.cargo("bench -vv")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
|
|
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc[..]`
|
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
|
|
|
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] [CWD]/target/release/deps/foo-[..][EXE] --bench`",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|