Debian Codegraph @

debian/rust-vendor/hostname/tests/codegen.rs

raw
1 use std::fs;
2 use std::process::Command;
3
4 use windows_bindgen::bindgen;
5
6 #[test]
7 fn gen_bindings() {
8 let output = "src/windows/bindings.rs";
9 let existing = fs::read_to_string(output).unwrap();
10
11 bindgen(["--no-deps", "--etc", "tests/bindings.txt"]).unwrap();
12 let out = Command::new("rustfmt")
13 .arg("--edition=2021")
14 .arg(output)
15 .output()
16 .unwrap();
17
18 dbg!(String::from_utf8(out.stdout).unwrap());
19 dbg!(String::from_utf8(out.stderr).unwrap());
20 assert!(out.status.success());
21
22 // Check the output is the same as before.
23 // Depending on the git configuration the file may have been checked out with `\r\n` newlines or
24 // with `\n`. Compare line-by-line to ignore this difference.
25 let mut new = fs::read_to_string(output).unwrap();
26 if existing.contains("\r\n") && !new.contains("\r\n") {
27 new = new.replace("\n", "\r\n");
28 } else if !existing.contains("\r\n") && new.contains("\r\n") {
29 new = new.replace("\r\n", "\n");
30 }
31
32 similar_asserts::assert_eq!(existing, new);
33 }