Use similar-asserts to show bindgen diff

This commit is contained in:
Dirkjan Ochtman 2025-02-24 13:47:36 +01:00
parent d0f8b599b7
commit bf1973ccc7
2 changed files with 9 additions and 1 deletions

View File

@ -63,6 +63,7 @@ android-tzdata = { version = "0.1.1", optional = true }
[dev-dependencies]
serde_json = { version = "1" }
serde_derive = { version = "1", default-features = false }
similar-asserts = { version = "1.6.1" }
bincode = { version = "1.3.0" }
[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dev-dependencies]

View File

@ -14,7 +14,14 @@ fn gen_bindings() {
// Check the output is the same as before.
// Depending on the git configuration the file may have been checked out with `\r\n` newlines or
// with `\n`. Compare line-by-line to ignore this difference.
let new = fs::read_to_string(output).unwrap();
let mut new = fs::read_to_string(output).unwrap();
if existing.contains("\r\n") && !new.contains("\r\n") {
new = new.replace("\n", "\r\n");
} else if !existing.contains("\r\n") && new.contains("\r\n") {
new = new.replace("\r\n", "\n");
}
similar_asserts::assert_eq!(existing, new);
if !new.lines().eq(existing.lines()) {
panic!("generated file `{}` is changed.", output);
}