Skip to content

Commit

Permalink
Improve code generation test
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Nov 20, 2023
1 parent 116f3c5 commit 0fee6e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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"
Expand Down
9 changes: 4 additions & 5 deletions tests/win_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

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);

// 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);
}

0 comments on commit 0fee6e3

Please # to comment.