use std::fs;
use std::path::PathBuf;
fn runtime_module_path() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../rustcall_julia_macros/src/rt.rs")
}
#[test]
fn runtime_crate_module_matches_the_generator() {
let path = runtime_module_path();
if std::env::var_os("UPDATE_GOLDEN").is_some_and(|value| value == "1") {
fs::write(&path, rustcall_julia_core::codegen::runtime_module_source())
.unwrap_or_else(|error| panic!("failed to update {}: {error}", path.display()));
eprintln!(
"rewrote {}; run `cargo fmt` before committing",
path.display()
);
return;
}
let source = fs::read_to_string(&path)
.unwrap_or_else(|error| panic!("failed to read {}: {error}", path.display()));
let checked_in: syn::File = syn::parse_file(&source)
.unwrap_or_else(|error| panic!("{} is not valid Rust: {error}", path.display()));
let expected: syn::File = syn::parse2(rustcall_julia_core::codegen::panic_hook_items())
.expect("the quiet-hook items are not a valid Rust file");
assert_eq!(
prettyplease::unparse(&checked_in),
prettyplease::unparse(&expected),
"{} and `panic_hook_items()` have drifted apart; regenerate with \
`UPDATE_GOLDEN=1 cargo test`, then `cargo fmt`",
path.display()
);
}
#[test]
fn the_runtime_module_exports_the_symbols_julia_resolves() {
let source = rustcall_julia_core::codegen::runtime_module_source();
for symbol in [
rustcall_julia_core::codegen::INSTALL_PANIC_HOOK_SYMBOL,
rustcall_julia_core::codegen::UNINSTALL_PANIC_HOOK_SYMBOL,
] {
assert!(
source.contains(&format!("pub extern \"C\" fn {symbol}()")),
"the runtime module must export {symbol}"
);
}
assert!(source.contains("pub struct __RustCallBoundary"));
}