Skip to content

Commit 2ab559c

Browse files
committed
test(add): add test for CARGO_CFG_DEBUG_ASSERTIONS with release profile override
1 parent 884cd77 commit 2ab559c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/testsuite/build_script_env.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,3 +522,35 @@ fn build_script_debug_assertions_override_dev() {
522522
// Dev profile with debug-assertions explicitly disabled
523523
p.cargo("build").run();
524524
}
525+
526+
#[cargo_test]
527+
fn build_script_debug_assertions_override_release() {
528+
// Test that CARGO_CFG_DEBUG_ASSERTIONS respects profile overrides
529+
// Release profile with debug-assertions explicitly ENABLED
530+
let build_rs = r#"
531+
fn main() {
532+
let has_debug_assertions = std::env::var_os("CARGO_CFG_DEBUG_ASSERTIONS").is_some();
533+
assert!(has_debug_assertions, "CARGO_CFG_DEBUG_ASSERTIONS should be set when release profile enables it");
534+
}
535+
"#;
536+
537+
let p = project()
538+
.file(
539+
"Cargo.toml",
540+
r#"
541+
[package]
542+
name = "foo"
543+
version = "0.1.0"
544+
edition = "2024"
545+
546+
[profile.release]
547+
debug-assertions = true
548+
"#,
549+
)
550+
.file("src/lib.rs", r#""#)
551+
.file("build.rs", build_rs)
552+
.build();
553+
554+
// Release profile with debug-assertions explicitly enabled
555+
p.cargo("build --release").run();
556+
}

0 commit comments

Comments
 (0)