Skip to content

Commit f65f230

Browse files
ericseppanenemilio
authored andcommitted
add test for add_derives
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.
1 parent b6109c0 commit f65f230

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

bindgen-integration/build.rs

+11
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ impl ParseCallbacks for MacroCallback {
119119
}
120120
}
121121
}
122+
123+
// Test the "custom derives" capability by adding `PartialEq` to the `Test` struct.
124+
fn add_derives(&self, name: &str) -> Vec<String> {
125+
if name == "Test" {
126+
vec![
127+
"PartialEq".into(),
128+
]
129+
} else {
130+
vec![]
131+
}
132+
}
122133
}
123134

124135
impl Drop for MacroCallback {

bindgen-integration/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,12 @@ fn test_homogeneous_aggregate_float_union() {
267267
assert_eq!([1., 2., 3., 4.], coord.v)
268268
}
269269
}
270+
271+
#[test]
272+
fn test_custom_derive() {
273+
// The `add_derives` callback should have added `#[derive(PartialEq)]`
274+
// to the `Test` struct. If it didn't, this will fail to compile.
275+
let test1 = unsafe { bindings::Test::new(5) };
276+
let test2 = unsafe { bindings::Test::new(6) };
277+
assert_ne!(test1, test2);
278+
}

0 commit comments

Comments
 (0)