
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1207 · main · 10 min 04 s
1Étoiles
0Forks
0Issues
| 1 | //! `louise bindgen` on a header with every shape it binds and several it |
| 2 | //! skips: the output is snapshotted, the module must type-check, and the |
| 3 | //! shim must compile without warnings. |
| 4 | |
| 5 | use std::path::Path; |
| 6 | use std::process::Command; |
| 7 | |
| 8 | const HEADER: &str = include_str!("data/kitchen.h"); |
| 9 | |
| 10 | #[test] |
| 11 | fn kitchen_sink() { |
| 12 | let b = louise_bindgen::generate(HEADER, "kitchen.h"); |
| 13 | insta::assert_snapshot!("kitchen.lse", b.louise); |
| 14 | insta::assert_snapshot!("kitchen.c", b.c); |
| 15 | } |
| 16 | |
| 17 | #[test] |
| 18 | fn the_module_type_checks() { |
| 19 | let b = louise_bindgen::generate(HEADER, "kitchen.h"); |
| 20 | let mut db = louise_db::Db::new(); |
| 21 | db.add_module("kitchen", "kitchen.lse", b.louise.clone()); |
| 22 | let analysis = db.analyze(); |
| 23 | let diags: Vec<String> = analysis |
| 24 | .diagnostics |
| 25 | .iter() |
| 26 | .map(|d| format!("[{}] {}", d.code, d.message)) |
| 27 | .collect(); |
| 28 | assert!(diags.is_empty(), "{diags:#?}\n{}", b.louise); |
| 29 | } |
| 30 | |
| 31 | #[test] |
| 32 | fn the_shim_compiles_cleanly() { |
| 33 | if Command::new("cc").arg("--version").output().is_err() { |
| 34 | eprintln!("skipped: no C compiler"); |
| 35 | return; |
| 36 | } |
| 37 | let b = louise_bindgen::generate(HEADER, "kitchen.h"); |
| 38 | let dir = Path::new(env!("CARGO_TARGET_TMPDIR")).join("bindgen"); |
| 39 | std::fs::create_dir_all(&dir).unwrap(); |
| 40 | let shim = dir.join("kitchen_bindings.c"); |
| 41 | std::fs::write(&shim, &b.c).unwrap(); |
| 42 | let here = Path::new(env!("CARGO_MANIFEST_DIR")); |
| 43 | let out = Command::new("cc") |
| 44 | .args(["-std=gnu11", "-fsyntax-only", "-Wall", "-Werror", "-I"]) |
| 45 | .arg(here.join("../../runtime/louise_rt/include")) |
| 46 | .arg("-I") |
| 47 | .arg(here.join("tests/data")) |
| 48 | .arg(&shim) |
| 49 | .output() |
| 50 | .unwrap(); |
| 51 | assert!( |
| 52 | out.status.success(), |
| 53 | "{}", |
| 54 | String::from_utf8_lossy(&out.stderr) |
| 55 | ); |
| 56 | } |