Skip to content

Commit 422c564

Browse files
art049GuillaumeLagrange
authored andcommitted
tests(cargo-codspeed): create a testcase for handling rustflags from the cargo config
1 parent 8dffbaf commit 422c564

File tree

6 files changed

+72
-1
lines changed

6 files changed

+72
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
*/target
12
*/Cargo.lock
2-
*/target/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
rustflags = ["--cfg", "custom_feature_flag"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "cargo_config_test"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[dependencies]
8+
codspeed-criterion-compat = { path = "../../../criterion_compat" }
9+
10+
[workspace]
11+
12+
[[bench]]
13+
name = "cargo_config_bench"
14+
harness = false
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion};
2+
3+
fn bench_failing_without_custom_flag(c: &mut Criterion) {
4+
c.bench_function("custom_flag_disabled", |b| {
5+
b.iter(|| {
6+
// This will cause a compilation error if custom_feature_flag is not set
7+
#[cfg(not(custom_feature_flag))]
8+
compile_error!(
9+
"custom_feature_flag is not enabled - .cargo/config.toml rustflags not applied"
10+
);
11+
})
12+
});
13+
}
14+
15+
criterion_group!(benches, bench_failing_without_custom_flag);
16+
17+
criterion_main!(benches);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("cargo::rustc-check-cfg=cfg(custom_feature_flag)");
3+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::process::Command;
2+
3+
mod helpers;
4+
use helpers::*;
5+
6+
#[test]
7+
fn test_cargo_config_rustflags() {
8+
let tmp_dir = setup("tests/cargo_config.in", Project::Simple);
9+
10+
// Test that cargo bench works with the custom flag
11+
let output = Command::new("cargo")
12+
.arg("bench")
13+
.arg("--no-run")
14+
.current_dir(&tmp_dir)
15+
.output()
16+
.expect("Failed to execute cargo bench");
17+
18+
assert!(
19+
output.status.success(),
20+
"cargo codspeed bench should succeed with .cargo/config.toml rustflags",
21+
);
22+
23+
// Test that cargo codspeed build also works with the custom flag
24+
let output = cargo_codspeed(&tmp_dir)
25+
.arg("build")
26+
.output()
27+
.expect("Failed to execute cargo codspeed build");
28+
29+
assert!(
30+
output.status.success(),
31+
"cargo codspeed build should succeed with .cargo/config.toml rustflags",
32+
);
33+
34+
teardown(tmp_dir);
35+
}

0 commit comments

Comments
 (0)