//! The committed header names exactly the functions the crate exports. #[test] fn header_matches_the_exports() { let root = std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is set by cargo for every test run"); let header = std::fs::read_to_string(format!("{root}/include/cotton_mac_ffi.h")).unwrap(); let source = std::fs::read_to_string(format!("{root}/src/lib.rs")).unwrap(); let exported: Vec<&str> = source .lines() .filter_map(|line| line.trim().strip_prefix("pub unsafe extern \"C\" fn ")) .map(|rest| rest.split('(').next().unwrap()) .collect(); assert_eq!(exported, ["cotton_mac_open", "cotton_mac_call", "cotton_mac_free"]); for (name, signature) in [ ("cotton_mac_open", "char *cotton_mac_open(const char *config_json);"), ("cotton_mac_call", "char *cotton_mac_call(const char *method, const char *args_json);"), ("cotton_mac_free", "void cotton_mac_free(char *ptr);"), ] { assert!(header.contains(signature), "header lacks {name}: {signature}"); } let modulemap = std::fs::read_to_string(format!("{root}/include/module.modulemap")).unwrap(); assert!(modulemap.contains("header \"cotton_mac_ffi.h\"")); assert!(modulemap.contains("link \"cotton_mac_ffi\"")); }