From 0fee6e39356ae550c8c87f7534ae600385e15df4 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 20 Nov 2023 09:38:30 +0100 Subject: [PATCH] Improve code generation test --- Cargo.toml | 4 ++-- tests/win_bindings.rs | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1cad234834..0e4cb03694 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,6 @@ arbitrary = { version = "1.0.0", features = ["derive"], optional = true } wasm-bindgen = { version = "0.2", optional = true } js-sys = { version = "0.3", optional = true } # contains FFI bindings for the JS Date API - [target.'cfg(windows)'.dependencies] windows-targets = { version = "0.48", optional = true } @@ -56,9 +55,10 @@ iana-time-zone = { version = "0.1.45", optional = true, features = ["fallback"] android-tzdata = { version = "0.1.1", optional = true } [dev-dependencies] +bincode = { version = "1.3.0" } serde_json = { version = "1" } serde_derive = { version = "1", default-features = false } -bincode = { version = "1.3.0" } +similar-asserts = "1.5" [target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dev-dependencies] wasm-bindgen-test = "0.3" diff --git a/tests/win_bindings.rs b/tests/win_bindings.rs index bfb110c38e..4c72bc07ab 100644 --- a/tests/win_bindings.rs +++ b/tests/win_bindings.rs @@ -2,12 +2,13 @@ use std::fs; use windows_bindgen::bindgen; +use similar_asserts::assert_eq; #[test] fn gen_bindings() { let input = "src/offset/local/win_bindings.txt"; let output = "src/offset/local/win_bindings.rs"; - let existing = fs::read_to_string(output).unwrap(); + let existing = fs::read_to_string(output).unwrap().replace("\r\n", "\n"); let log = bindgen(["--etc", input]).unwrap(); eprintln!("{}", log); @@ -15,8 +16,6 @@ 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(); - if !new.lines().eq(existing.lines()) { - panic!("generated file `{}` is changed.", output); - } + let new = fs::read_to_string(output).unwrap().replace("\r\n", "\n"); + assert_eq!(new, existing); }