fn workspace_manifest() -> String {
let p = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../Cargo.toml");
std::fs::read_to_string(&p).unwrap_or_else(|e| panic!("read {}: {e}", p.display()))
}
fn release_profile(manifest: &str) -> Vec<&str> {
manifest
.lines()
.skip_while(|l| l.trim() != "[profile.release]")
.skip(1)
.take_while(|l| !l.trim_start().starts_with('['))
.collect()
}
#[test]
fn the_release_profile_does_not_abort_on_panic() {
let manifest = workspace_manifest();
let profile = release_profile(&manifest);
assert!(
!profile.is_empty(),
"no [profile.release] section found — has the manifest moved?"
);
for line in &profile {
let code = line.split('#').next().unwrap_or("").trim();
assert!(
!code.starts_with("panic"),
"[profile.release] sets {code:?}. `panic = \"abort\"` disables \
dispatch's catch_unwind AND Drop for StagedOnly in the shipped \
binary, and no cargo test can detect it — see the comment in \
Cargo.toml."
);
}
}
#[test]
fn the_release_profile_reader_finds_the_settings_that_are_there() {
let manifest = workspace_manifest();
let profile = release_profile(&manifest).join("\n");
assert!(
profile.contains("strip") && profile.contains("lto"),
"the section reader did not find the known settings: {profile:?}"
);
}