Skip to content

Commit f479ffb

Browse files
committed
test: add tests for all-features and no-default-features
1 parent 837d489 commit f479ffb

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

crates/cargo-codspeed/tests/features.in/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ codspeed = { path = "../../../codspeed" }
1010
codspeed-bencher-compat = { path = "../../../bencher_compat" }
1111

1212
[features]
13+
default = ["default_feature"]
1314
sample_feature = []
15+
default_feature = []
1416

1517
[workspace]
1618

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
use codspeed::codspeed::black_box;
22
use codspeed_bencher_compat::{benchmark_group, benchmark_main, Bencher};
33

4+
#[cfg(feature = "default_feature")]
5+
pub fn with_default_feature(bench: &mut Bencher) {
6+
bench.iter(|| (0..100).fold(0, |x, y| black_box(x + y)))
7+
}
8+
9+
#[cfg(not(feature = "default_feature"))]
10+
pub fn without_default_feature(bench: &mut Bencher) {
11+
bench.iter(|| (0..100).fold(0, |x, y| black_box(x + y)))
12+
}
13+
414
#[cfg(not(feature = "sample_feature"))]
515
pub fn without_feature(bench: &mut Bencher) {
616
bench.iter(|| (0..100).fold(0, |x, y| black_box(x + y)))
717
}
8-
#[cfg(not(feature = "sample_feature"))]
9-
benchmark_group!(benches, without_feature);
1018

1119
#[cfg(feature = "sample_feature")]
1220
pub fn with_feature(bench: &mut Bencher) {
1321
bench.iter(|| (0..100).fold(0, |x, y| black_box(x + y)))
1422
}
23+
1524
#[cfg(feature = "sample_feature")]
16-
benchmark_group!(benches, with_feature);
25+
benchmark_group!(sample_benches, with_feature);
26+
#[cfg(not(feature = "sample_feature"))]
27+
benchmark_group!(sample_benches, without_feature);
28+
29+
#[cfg(feature = "default_feature")]
30+
benchmark_group!(default_benches, with_default_feature);
31+
#[cfg(not(feature = "default_feature"))]
32+
benchmark_group!(default_benches, without_default_feature);
1733

18-
benchmark_main!(benches);
34+
benchmark_main!(sample_benches, default_benches);

crates/cargo-codspeed/tests/features.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,40 @@ fn test_with_feature() {
3737
.stdout(contains("without_feature").not());
3838
teardown(dir);
3939
}
40+
41+
#[test]
42+
fn test_no_default_features() {
43+
let dir = setup(DIR, Project::Features);
44+
cargo_codspeed(&dir)
45+
.arg("build")
46+
.arg("--no-default-features")
47+
.assert()
48+
.success();
49+
cargo_codspeed(&dir)
50+
.arg("run")
51+
.assert()
52+
.success()
53+
.stderr(contains("Finished running 1 benchmark suite(s)"))
54+
.stdout(contains("with_default_feature").not())
55+
.stdout(contains("without_default_feature"));
56+
57+
teardown(dir);
58+
}
59+
60+
#[test]
61+
fn test_all_features() {
62+
let dir = setup(DIR, Project::Features);
63+
cargo_codspeed(&dir)
64+
.arg("build")
65+
.arg("--all-features")
66+
.assert()
67+
.success();
68+
cargo_codspeed(&dir)
69+
.arg("run")
70+
.assert()
71+
.success()
72+
.stderr(contains("Finished running 1 benchmark suite(s)"))
73+
.stdout(contains("with_feature"))
74+
.stdout(contains("with_default_feature"));
75+
teardown(dir);
76+
}

0 commit comments

Comments
 (0)