//! `louise bindgen` on a header with every shape it binds and several it //! skips: the output is snapshotted, the module must type-check, and the //! shim must compile without warnings. use std::path::Path; use std::process::Command; const HEADER: &str = include_str!("data/kitchen.h"); #[test] fn kitchen_sink() { let b = louise_bindgen::generate(HEADER, "kitchen.h"); insta::assert_snapshot!("kitchen.lse", b.louise); insta::assert_snapshot!("kitchen.c", b.c); } #[test] fn the_module_type_checks() { let b = louise_bindgen::generate(HEADER, "kitchen.h"); let mut db = louise_db::Db::new(); db.add_module("kitchen", "kitchen.lse", b.louise.clone()); let analysis = db.analyze(); let diags: Vec = analysis .diagnostics .iter() .map(|d| format!("[{}] {}", d.code, d.message)) .collect(); assert!(diags.is_empty(), "{diags:#?}\n{}", b.louise); } #[test] fn the_shim_compiles_cleanly() { if Command::new("cc").arg("--version").output().is_err() { eprintln!("skipped: no C compiler"); return; } let b = louise_bindgen::generate(HEADER, "kitchen.h"); let dir = Path::new(env!("CARGO_TARGET_TMPDIR")).join("bindgen"); std::fs::create_dir_all(&dir).unwrap(); let shim = dir.join("kitchen_bindings.c"); std::fs::write(&shim, &b.c).unwrap(); let here = Path::new(env!("CARGO_MANIFEST_DIR")); let out = Command::new("cc") .args(["-std=gnu11", "-fsyntax-only", "-Wall", "-Werror", "-I"]) .arg(here.join("../../runtime/louise_rt/include")) .arg("-I") .arg(here.join("tests/data")) .arg(&shim) .output() .unwrap(); assert!( out.status.success(), "{}", String::from_utf8_lossy(&out.stderr) ); }