summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Seppanen <eds@reric.net>2021-06-06 15:10:34 -0700
committerEmilio Cobos Álvarez <emilio@crisal.io>2021-07-16 21:23:05 +0200
commitf65f2307f69a85cc7857b88409fe89c2bd2f79b7 (patch)
tree56ffc0d4d78fada533f9b107ff683553d99dfe2c
parentb6109c00fcb13a27e06387ce2ef417a54c24cf3f (diff)
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.
-rw-r--r--bindgen-integration/build.rs11
-rwxr-xr-xbindgen-integration/src/lib.rs9
2 files changed, 20 insertions, 0 deletions
diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs
index b28dcee5..fa0246c4 100644
--- a/bindgen-integration/build.rs
+++ b/bindgen-integration/build.rs
@@ -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 {
diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs
index 4b288afd..f56e7259 100755
--- a/bindgen-integration/src/lib.rs
+++ b/bindgen-integration/src/lib.rs
@@ -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);
+}