Debian Codegraph @

third_party/rust/chrono/tests/win_bindings.rs

raw
1 #![cfg(all(windows, feature = "clock", feature = "std"))]
2
3 use std::fs;
4 use windows_bindgen::bindgen;
5
6 #[test]
7 fn gen_bindings() {
8 let input = "src/offset/local/win_bindings.txt";
9 let output = "src/offset/local/win_bindings.rs";
10 let existing = fs::read_to_string(output).unwrap();
11
12 bindgen(["--no-deps", "--etc", input]);
13
14 // Check the output is the same as before.
15 // Depending on the git configuration the file may have been checked out with `\r\n` newlines or
16 // with `\n`. Compare line-by-line to ignore this difference.
17 let mut new = fs::read_to_string(output).unwrap();
18 if existing.contains("\r\n") && !new.contains("\r\n") {
19 new = new.replace("\n", "\r\n");
20 } else if !existing.contains("\r\n") && new.contains("\r\n") {
21 new = new.replace("\r\n", "\n");
22 }
23
24 similar_asserts::assert_eq!(existing, new);
25 if !new.lines().eq(existing.lines()) {
26 panic!("generated file `{}` is changed.", output);
27 }
28 }