Skip to content

Commit a2277f5

Browse files
committed
test(add): add test for CARGO_CFG_DEBUG_ASSERTIONS with dev profile override
1 parent 875c0fb commit a2277f5

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
@@ -492,3 +492,36 @@ fn build_script_debug_assertions_release() {
492492
p.cargo("build --release")
493493
.run();
494494
}
495+
496+
#[cargo_test]
497+
fn build_script_debug_assertions_override_dev() {
498+
// Test that CARGO_CFG_DEBUG_ASSERTIONS respects profile overrides
499+
// Dev profile with debug-assertions explicitly DISABLED
500+
let build_rs = r#"
501+
fn main() {
502+
let has_debug_assertions = std::env::var_os("CARGO_CFG_DEBUG_ASSERTIONS").is_some();
503+
assert!(!has_debug_assertions, "CARGO_CFG_DEBUG_ASSERTIONS should NOT be set when dev profile disables it");
504+
}
505+
"#;
506+
507+
let p = project()
508+
.file(
509+
"Cargo.toml",
510+
r#"
511+
[package]
512+
name = "foo"
513+
version = "0.1.0"
514+
edition = "2024"
515+
516+
[profile.dev]
517+
debug-assertions = false
518+
"#,
519+
)
520+
.file("src/lib.rs", r#""#)
521+
.file("build.rs", build_rs)
522+
.build();
523+
524+
// Dev profile with debug-assertions explicitly disabled
525+
p.cargo("build")
526+
.run();
527+
}

0 commit comments

Comments
 (0)