#![allow(clippy::unwrap_used)]
use std::path::Path;
fn profile_lines(manifest: &str, name: &str) -> Vec<String> {
let header = format!("[profile.{name}]");
manifest
.lines()
.skip_while(|l| l.trim() != header)
.skip(1)
.take_while(|l| !l.trim_start().starts_with('['))
.map(|l| l.trim().to_owned())
.collect()
}
#[test]
fn no_profile_sets_panic_abort() {
let manifest =
std::fs::read_to_string(Path::new(env!("CARGO_MANIFEST_DIR")).join("../Cargo.toml"))
.unwrap();
let release = profile_lines(&manifest, "release");
assert!(
release.iter().any(|l| l.starts_with("lto")),
"the release table was found: {release:?}"
);
for name in ["release", "bench", "dev", "test"] {
let abort = profile_lines(&manifest, name)
.into_iter()
.any(|l| l.replace(' ', "") == "panic=\"abort\"");
assert!(!abort, "[profile.{name}] sets panic = \"abort\"");
}
}