Skip to content

Commit ee5e6e3

Browse files
committed
test(add): add test for CARGO_CFG_DEBUG_ASSERTIONS with build override for debug and release profiles
1 parent cf9c97e commit ee5e6e3

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/testsuite/build_script_env.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,40 @@ fn build_script_debug_assertions_override_release() {
554554
// Release profile with debug-assertions explicitly enabled
555555
p.cargo("check --release").run();
556556
}
557+
558+
#[cargo_test]
559+
fn build_script_debug_assertions_build_override() {
560+
let build_rs = r#"
561+
fn main() {
562+
let profile = std::env::var("PROFILE").unwrap();
563+
if profile == "debug" {
564+
assert!(!cfg!(debug_assertions));
565+
} else if profile == "release" {
566+
assert!(cfg!(debug_assertions));
567+
}
568+
}
569+
"#;
570+
571+
let p = project()
572+
.file(
573+
"Cargo.toml",
574+
r#"
575+
[package]
576+
name = "foo"
577+
version = "0.1.0"
578+
edition = "2024"
579+
580+
[profile.dev.build-override]
581+
debug-assertions = false
582+
583+
[profile.release.build-override]
584+
debug-assertions = true
585+
"#,
586+
)
587+
.file("src/lib.rs", r#""#)
588+
.file("build.rs", build_rs)
589+
.build();
590+
591+
p.cargo("check").run();
592+
p.cargo("check --release").run();
593+
}

0 commit comments

Comments
 (0)