summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTING.md6
-rw-r--r--tests/tests.rs33
2 files changed, 32 insertions, 7 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index ae72afb6..716217e0 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -125,6 +125,12 @@ the expected bindings with `bindgen`'s current output:
$ BINDGEN_OVERWRITE_EXPECTED=1 cargo test
```
+If you set the BINDGEN_TESTS_DIFFTOOL environment variable, `cargo test` will
+execute $BINDGEN_TESTS_DIFFTOOL /path/of/expected/output /path/of/actual/output
+when the expected output differs from the actual output. You can use this to
+hand check differences by setting it to e.g. "meld" (assuming you have meld
+installed).
+
If you're not changing command line arguments, you may want to set
`BINDGEN_DISABLE_ROUNDTRIP_TEST` to avoid a lot of tests for round-tripping of
those.
diff --git a/tests/tests.rs b/tests/tests.rs
index f8419b53..8b5a91f7 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -174,7 +174,7 @@ fn compare_generated_header(
expectation.push(file_name);
expectation.set_extension("rs");
expectation_file = fs::File::open(&expectation).ok();
- looked_at.push(expectation);
+ looked_at.push(expectation.clone());
}
let mut expected = String::new();
@@ -233,14 +233,33 @@ fn compare_generated_header(
}
}
- // Overwrite the expectation with actual output.
- if env::var_os("BINDGEN_OVERWRITE_EXPECTED").is_some() {
- let mut expectation_file =
- fs::File::create(looked_at.last().unwrap())?;
- expectation_file.write_all(actual.as_bytes())?;
+ if let Some(var) = env::var_os("BINDGEN_OVERWRITE_EXPECTED") {
+ if var == "1" {
+ // Overwrite the expectation with actual output.
+ let mut expectation_file =
+ fs::File::create(looked_at.last().unwrap())?;
+ expectation_file.write_all(actual.as_bytes())?;
+ } else if var != "0" && var != "" {
+ panic!("Invalid value of BINDGEN_OVERWRITE_EXPECTED");
+ }
+ }
+
+ if let Some(var) = env::var_os("BINDGEN_TESTS_DIFFTOOL") {
+ //usecase: var = "meld" -> You can hand check differences
+ let filename = match header.components().last() {
+ Some(std::path::Component::Normal(name)) => name,
+ _ => panic!("Why is the header variable so weird?"),
+ };
+ let actual_result_path =
+ PathBuf::from(env::var("OUT_DIR").unwrap()).join(filename);
+ let mut actual_result_file = fs::File::create(&actual_result_path)?;
+ actual_result_file.write_all(actual.as_bytes())?;
+ std::process::Command::new(var)
+ .args(&[looked_at.last().unwrap(), &actual_result_path])
+ .output()?;
}
- return Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation."));
+ return Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation or with BINDGEN_TESTS_DIFFTOOL=meld to do this manually."));
}
if check_roundtrip {