Skip to content

Commit

Permalink
add test for add_derives
Browse files Browse the repository at this point in the history
This test derives PartialEq for the Test struct, and then attempts to
use that by calling assert_ne! on two Test instances. If the derive
callback doesn't work, no PartialEq will be present and the test will
fail to compile.
  • Loading branch information
ericseppanen authored and emilio committed Jul 16, 2021
1 parent b6109c0 commit f65f230
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bindgen-integration/build.rs
Expand Up @@ -119,6 +119,17 @@ impl ParseCallbacks for MacroCallback {
}
}
}

// Test the "custom derives" capability by adding `PartialEq` to the `Test` struct.
fn add_derives(&self, name: &str) -> Vec<String> {
if name == "Test" {
vec![
"PartialEq".into(),
]
} else {
vec![]
}
}
}

impl Drop for MacroCallback {
Expand Down
9 changes: 9 additions & 0 deletions bindgen-integration/src/lib.rs
Expand Up @@ -267,3 +267,12 @@ fn test_homogeneous_aggregate_float_union() {
assert_eq!([1., 2., 3., 4.], coord.v)
}
}

#[test]
fn test_custom_derive() {
// The `add_derives` callback should have added `#[derive(PartialEq)]`
// to the `Test` struct. If it didn't, this will fail to compile.
let test1 = unsafe { bindings::Test::new(5) };
let test2 = unsafe { bindings::Test::new(6) };
assert_ne!(test1, test2);
}

0 comments on commit f65f230

Please sign in to comment.