Skip to content

Commit

Permalink
Fail test if generated win_bindings.rs is different
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jul 27, 2023
1 parent 39ce018 commit 69d953e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/win_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,15 @@ fn gen_bindings() -> io::Result<()> {
];

let bindings = windows_bindgen::standalone(&apis);
fs::write("src/offset/local/win_bindings.rs", format!("#![allow(unreachable_pub)]\n{bindings}"))

let path = "src/offset/local/win_bindings.rs";
let existing = fs::read_to_string(path)?;
// Skip the first two lines when comparing:
// - We add `#![allow(unreachable_pub)]` as a first line.
// - Rustfmt removes the empty line after the comment.
if !bindings.lines().skip(2).eq(existing.lines().skip(2)) {
fs::write(path, format!("#![allow(unreachable_pub)]\n{bindings}"))?;
panic!("generated file `{}` is changed.", path);
}
Ok(())
}

0 comments on commit 69d953e

Please sign in to comment.