Skip to content

Commit a5c4985

Browse files
committed
chore: add new test to handle RUSTFLAGS env var case
1 parent 2d80483 commit a5c4985

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

crates/cargo-codspeed/tests/cargo_config.in/benches/cargo_config_bench.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ fn bench_failing_without_custom_flag(c: &mut Criterion) {
88
compile_error!(
99
"custom_feature_flag is not enabled - .cargo/config.toml rustflags not applied"
1010
);
11+
12+
#[cfg(rustflags_feature_flag)]
13+
compile_error!("rustflags_feature_flag was set");
1114
})
1215
});
1316
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
fn main() {
22
println!("cargo::rustc-check-cfg=cfg(custom_feature_flag)");
3+
println!("cargo::rustc-check-cfg=cfg(rustflags_feature_flag)");
34
}

crates/cargo-codspeed/tests/cargo_config.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,37 @@ fn test_cargo_config_rustflags() {
3333

3434
teardown(tmp_dir);
3535
}
36+
37+
#[test]
38+
fn test_cargo_config_with_rustflags_env() {
39+
let tmp_dir = setup("tests/cargo_config.in", Project::Simple);
40+
41+
std::env::set_var("RUSTFLAGS", "--cfg rustflags_feature_flag");
42+
43+
let output = Command::new("cargo")
44+
.arg("bench")
45+
.arg("--no-run")
46+
.current_dir(&tmp_dir)
47+
.output()
48+
.expect("Failed to execute cargo bench");
49+
assert!(!output.status.success());
50+
let stdout = String::from_utf8_lossy(&output.stderr);
51+
assert!(
52+
stdout.contains("rustflags_feature_flag was set"),
53+
"Incorrect output: {stdout}"
54+
);
55+
56+
// Test that cargo codspeed build also works with the custom flag
57+
let output = cargo_codspeed(&tmp_dir)
58+
.arg("build")
59+
.output()
60+
.expect("Failed to execute cargo codspeed build");
61+
assert!(!output.status.success());
62+
let stdout = String::from_utf8_lossy(&output.stderr);
63+
assert!(
64+
stdout.contains("rustflags_feature_flag was set"),
65+
"Incorrect output: {stdout}"
66+
);
67+
68+
teardown(tmp_dir);
69+
}

0 commit comments

Comments
 (0)