use std::path::{Path, PathBuf};
fn reference_header() -> Option<PathBuf> {
let candidates = [
"oracle/quickjs-master/quickjs.h",
"../../oracle/quickjs-master/quickjs.h",
];
candidates
.iter()
.map(PathBuf::from)
.find(|path| path.is_file())
}
fn contract(path: &Path) -> String {
let text = std::fs::read_to_string(path).expect("header is readable");
let start = text
.find("\n#ifndef QUICKJS_H\n")
.unwrap_or_else(|| panic!("{} has no include guard on its own line", path.display()))
+ 1;
text[start..].to_string()
}
#[test]
fn the_shipped_header_matches_the_reference() {
let Some(reference) = reference_header() else {
eprintln!("skipping: no oracle/quickjs-master/quickjs.h on this machine");
return;
};
let ours = contract(Path::new("include/quickjs.h"));
let theirs = contract(&reference);
assert_eq!(
ours, theirs,
"include/quickjs.h has drifted from the reference's header; re-copy everything from \
`#ifndef QUICKJS_H` onward (keep the provenance preamble) and re-run the ABI tests"
);
}
#[test]
fn the_preamble_states_provenance_and_the_verdict_counts() {
let text = std::fs::read_to_string("include/quickjs.h").expect("header is readable");
for needle in ["Provenance", "bellard/quickjs", "MIT", "194", "17", "12"] {
assert!(
text.contains(needle),
"the header preamble no longer mentions {needle:?}"
);
}
let guard = text
.find("\n#ifndef QUICKJS_H\n")
.expect("has a guard on its own line");
assert!(
text[..guard].contains("Provenance"),
"the provenance block has slipped below the include guard"
);
}