Skip to content

Commit 2ce77d9

Browse files
committed
feat(cargo-codspeed): add test for target.rustflags in config
1 parent 2d80483 commit 2ce77d9

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
[build]
2-
rustflags = ["--cfg", "custom_feature_flag"]
1+
# This will be generated by the test

crates/cargo-codspeed/tests/cargo_config.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1-
use std::process::Command;
1+
use std::{path::PathBuf, process::Command};
22

33
mod helpers;
44
use helpers::*;
55

6-
#[test]
7-
fn test_cargo_config_rustflags() {
6+
const BUILD_RUSTFLAGS: &str = r#"
7+
[build]
8+
rustflags = ["--cfg", "custom_feature_flag"]
9+
"#;
10+
11+
const TARGET_RUSTFLAGS: &str = r#"
12+
[build]
13+
rustflags = ["--cfg", "this_will_be_overridden"]
14+
15+
[target.'cfg(all())']
16+
rustflags = ["--cfg custom_feature_flag"]
17+
"#;
18+
19+
fn build_and_run_cargo_bench_with_config(cargo_config: &str) {
20+
// Create a temporary directory and write the .cargo/config
821
let tmp_dir = setup("tests/cargo_config.in", Project::Simple);
922

23+
let config_path = PathBuf::from(&tmp_dir).join(".cargo").join("config.toml");
24+
std::fs::create_dir_all(config_path.parent().unwrap()).unwrap();
25+
std::fs::write(config_path, cargo_config).unwrap();
26+
1027
// Test that cargo bench works with the custom flag
1128
let output = Command::new("cargo")
1229
.arg("bench")
@@ -33,3 +50,13 @@ fn test_cargo_config_rustflags() {
3350

3451
teardown(tmp_dir);
3552
}
53+
54+
#[test]
55+
fn test_cargo_config_build_rustflags() {
56+
build_and_run_cargo_bench_with_config(BUILD_RUSTFLAGS);
57+
}
58+
59+
#[test]
60+
fn test_cargo_config_target_rustflags() {
61+
build_and_run_cargo_bench_with_config(TARGET_RUSTFLAGS);
62+
}

0 commit comments

Comments
 (0)