(path: &str, suffix: &str, src: &str)
| 33 | } |
| 34 | |
| 35 | fn process_expanded(path: &str, suffix: &str, src: &str) -> Result<()> { |
| 36 | let formatted_src = { |
| 37 | let syn_file = syn::parse_file(src).unwrap(); |
| 38 | prettyplease::unparse(&syn_file) |
| 39 | }; |
| 40 | let expanded_path = { |
| 41 | let mut stem = Path::new(path).file_stem().unwrap().to_os_string(); |
| 42 | stem.push(suffix); |
| 43 | Path::new("tests/expanded").join(stem).with_extension("rs") |
| 44 | }; |
| 45 | if std::env::var("BINDGEN_TEST_BLESS").is_ok_and(|val| !val.is_empty()) { |
| 46 | if let Ok(prev) = std::fs::read(&expanded_path) |
| 47 | && prev == formatted_src.as_bytes() |
| 48 | { |
| 49 | return Ok(()); |
| 50 | } |
| 51 | std::fs::write(expanded_path, formatted_src)?; |
| 52 | } else { |
| 53 | match std::fs::read_to_string(&expanded_path) { |
| 54 | Ok(expected) if formatted_src == expected => (), |
| 55 | Ok(expected) => { |
| 56 | bail!( |
| 57 | "checked-in expanded bindings from {expanded_path:?} \ |
| 58 | do not match those generated from {path:?} |
| 59 | \n\ |
| 60 | {diff}\n\ |
| 61 | \n\ |
| 62 | This test assertion can be automatically updated by setting the\n\ |
| 63 | BINDGEN_TEST_BLESS=1 environment variable when running this test.", |
| 64 | diff = similar::TextDiff::from_lines(&expected, &formatted_src) |
| 65 | .unified_diff() |
| 66 | .header("expected", "actual") |
| 67 | ) |
| 68 | } |
| 69 | Err(err) => return Err(err).with_context(|| { |
| 70 | format!( |
| 71 | "failed to read {expanded_path:?}; re-run with BINDGEN_TEST_BLESS=1 to create" |
| 72 | ) |
| 73 | }), |
| 74 | } |
| 75 | } |
| 76 | Ok(()) |
| 77 | } |
| 78 | |
| 79 | #[test] |
| 80 | fn expand_wits() -> Result<()> { |
nothing calls this directly
no test coverage detected