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.
diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs
index b28dcee..fa0246c 100644
--- a/bindgen-integration/build.rs
+++ b/bindgen-integration/build.rs
@@ -119,6 +119,17 @@
}
}
}
+
+ // 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 {
diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs
index 4b288af..f56e725 100755
--- a/bindgen-integration/src/lib.rs
+++ b/bindgen-integration/src/lib.rs
@@ -267,3 +267,12 @@
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);
+}