use std::path::PathBuf;
use std::process::Command;
fn repo_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
}
#[test]
fn committed_header_matches_a_fresh_cbindgen_run() {
let root = repo_root();
if Command::new("cbindgen").arg("--version").output().is_err() {
eprintln!(
"skipping committed_header_matches_a_fresh_cbindgen_run: \
`cbindgen` not found on PATH (`cargo install cbindgen`)"
);
return;
}
let committed = std::fs::read_to_string(root.join("go/internal/capi/dxpdf.h"))
.expect("go/internal/capi/dxpdf.h is missing — run scripts/generate_capi_header.sh");
let fresh_path = root.join("target").join("capi_header_freshness_check.h");
let status = Command::new("cbindgen")
.current_dir(&root)
.args([
"--config",
"cbindgen.toml",
"--output",
fresh_path.to_str().unwrap(),
"src/capi.rs",
])
.status()
.expect("failed to run cbindgen");
assert!(status.success(), "cbindgen exited with {status:?}");
let fresh = std::fs::read_to_string(&fresh_path).expect("cbindgen did not write its output");
assert_eq!(
committed, fresh,
"go/internal/capi/dxpdf.h is stale — re-run scripts/generate_capi_header.sh and commit the result"
);
}