File: codegen.rs

package info (click to toggle)
rust-coreutils 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 505,620 kB
  • sloc: ansic: 103,594; asm: 28,570; sh: 8,910; python: 5,581; makefile: 472; cpp: 97; javascript: 72
file content (33 lines) | stat: -rw-r--r-- 1,068 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::fs;
use std::process::Command;

use windows_bindgen::bindgen;

#[test]
fn gen_bindings() {
    let output = "src/windows/bindings.rs";
    let existing = fs::read_to_string(output).unwrap();

    bindgen(["--no-deps", "--etc", "tests/bindings.txt"]).unwrap();
    let out = Command::new("rustfmt")
        .arg("--edition=2021")
        .arg(output)
        .output()
        .unwrap();

    dbg!(String::from_utf8(out.stdout).unwrap());
    dbg!(String::from_utf8(out.stderr).unwrap());
    assert!(out.status.success());

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