Skip to content

Commit d8d63b3

Browse files
committed
test(add): add test for CARGO_CFG_DEBUG_ASSERTIONS with release profile override
1 parent a2277f5 commit d8d63b3

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/testsuite/build_script_env.rs

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

0 commit comments

Comments
 (0)