Skip to content

Commit 884cd77

Browse files
committed
test(add): add test for CARGO_CFG_DEBUG_ASSERTIONS with dev profile override
1 parent d17b0c8 commit 884cd77

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

0 commit comments

Comments
 (0)