tests: Instead of adding skip_cpp as a feature, make the tests work with C++
diff --git a/tests/expectations/both/box.c b/tests/expectations/both/box.c index 6468f86..fefc734 100644 --- a/tests/expectations/both/box.c +++ b/tests/expectations/both/box.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using Box = T*; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h> @@ -11,6 +17,6 @@ int32_t *number; } MyStruct; -void delete(int32_t *x); +void drop_box(int32_t *x); void root(const Foo *a, const MyStruct *with_box);
diff --git a/tests/expectations/both/box.compat.c b/tests/expectations/both/box.compat.c index 31f5d7a..dcfeb1a 100644 --- a/tests/expectations/both/box.compat.c +++ b/tests/expectations/both/box.compat.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using Box = T*; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h> @@ -15,7 +21,7 @@ extern "C" { #endif // __cplusplus -void delete(int32_t *x); +void drop_box(int32_t *x); void root(const Foo *a, const MyStruct *with_box);
diff --git a/tests/expectations/both/manuallydrop.c b/tests/expectations/both/manuallydrop.c index 8e942fa..c2f72a3 100644 --- a/tests/expectations/both/manuallydrop.c +++ b/tests/expectations/both/manuallydrop.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using ManuallyDrop = T; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h>
diff --git a/tests/expectations/both/manuallydrop.compat.c b/tests/expectations/both/manuallydrop.compat.c index 6eb3444..551f9e7 100644 --- a/tests/expectations/both/manuallydrop.compat.c +++ b/tests/expectations/both/manuallydrop.compat.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using ManuallyDrop = T; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h>
diff --git a/tests/expectations/both/maybeuninit.c b/tests/expectations/both/maybeuninit.c index 8e87f5d..2eb4dd2 100644 --- a/tests/expectations/both/maybeuninit.c +++ b/tests/expectations/both/maybeuninit.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using MaybeUninit = T; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h>
diff --git a/tests/expectations/both/maybeuninit.compat.c b/tests/expectations/both/maybeuninit.compat.c index b3b2fa1..b840faa 100644 --- a/tests/expectations/both/maybeuninit.compat.c +++ b/tests/expectations/both/maybeuninit.compat.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using MaybeUninit = T; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h>
diff --git a/tests/expectations/box.c b/tests/expectations/box.c index 967f4b7..b644789 100644 --- a/tests/expectations/box.c +++ b/tests/expectations/box.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using Box = T*; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h> @@ -11,6 +17,6 @@ int32_t *number; } MyStruct; -void delete(int32_t *x); +void drop_box(int32_t *x); void root(const Foo *a, const MyStruct *with_box);
diff --git a/tests/expectations/box.compat.c b/tests/expectations/box.compat.c index 4a31ac9..290a382 100644 --- a/tests/expectations/box.compat.c +++ b/tests/expectations/box.compat.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using Box = T*; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h> @@ -15,7 +21,7 @@ extern "C" { #endif // __cplusplus -void delete(int32_t *x); +void drop_box(int32_t *x); void root(const Foo *a, const MyStruct *with_box);
diff --git a/tests/expectations/box.cpp b/tests/expectations/box.cpp new file mode 100644 index 0000000..062b107 --- /dev/null +++ b/tests/expectations/box.cpp
@@ -0,0 +1,27 @@ +#ifdef __cplusplus +template <typename T> +using Box = T*; +#endif + + +#include <cstdarg> +#include <cstdint> +#include <cstdlib> +#include <new> + +template<typename T = void> +struct NotReprC; + +using Foo = NotReprC<Box<int32_t>>; + +struct MyStruct { + Box<int32_t> number; +}; + +extern "C" { + +void drop_box(Box<int32_t> x); + +void root(const Foo *a, const MyStruct *with_box); + +} // extern "C"
diff --git a/tests/expectations/manuallydrop.c b/tests/expectations/manuallydrop.c index c4c4c23..c8eb148 100644 --- a/tests/expectations/manuallydrop.c +++ b/tests/expectations/manuallydrop.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using ManuallyDrop = T; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h>
diff --git a/tests/expectations/manuallydrop.compat.c b/tests/expectations/manuallydrop.compat.c index baac99a..3a766d4 100644 --- a/tests/expectations/manuallydrop.compat.c +++ b/tests/expectations/manuallydrop.compat.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using ManuallyDrop = T; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h>
diff --git a/tests/expectations/manuallydrop.cpp b/tests/expectations/manuallydrop.cpp new file mode 100644 index 0000000..a2c0fbf --- /dev/null +++ b/tests/expectations/manuallydrop.cpp
@@ -0,0 +1,32 @@ +#ifdef __cplusplus +template <typename T> +using ManuallyDrop = T; +#endif + + +#include <cstdarg> +#include <cstdint> +#include <cstdlib> +#include <new> + +template<typename T = void> +struct NotReprC; + +struct Point { + int32_t x; + int32_t y; +}; + +using Foo = NotReprC<ManuallyDrop<Point>>; + +struct MyStruct { + ManuallyDrop<Point> point; +}; + +extern "C" { + +void root(const Foo *a, const MyStruct *with_manual_drop); + +void take(ManuallyDrop<Point> with_manual_drop); + +} // extern "C"
diff --git a/tests/expectations/maybeuninit.c b/tests/expectations/maybeuninit.c index df1b889..8120540 100644 --- a/tests/expectations/maybeuninit.c +++ b/tests/expectations/maybeuninit.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using MaybeUninit = T; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h>
diff --git a/tests/expectations/maybeuninit.compat.c b/tests/expectations/maybeuninit.compat.c index 99fadec..8b31d2a 100644 --- a/tests/expectations/maybeuninit.compat.c +++ b/tests/expectations/maybeuninit.compat.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using MaybeUninit = T; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h>
diff --git a/tests/expectations/maybeuninit.cpp b/tests/expectations/maybeuninit.cpp new file mode 100644 index 0000000..2c30c8e --- /dev/null +++ b/tests/expectations/maybeuninit.cpp
@@ -0,0 +1,25 @@ +#ifdef __cplusplus +template <typename T> +using MaybeUninit = T; +#endif + + +#include <cstdarg> +#include <cstdint> +#include <cstdlib> +#include <new> + +template<typename T = void> +struct NotReprC; + +using Foo = NotReprC<MaybeUninit<const int32_t*>>; + +struct MyStruct { + MaybeUninit<const int32_t*> number; +}; + +extern "C" { + +void root(const Foo *a, const MyStruct *with_maybe_uninit); + +} // extern "C"
diff --git a/tests/expectations/tag/box.c b/tests/expectations/tag/box.c index 1667e37..8d2c9ff 100644 --- a/tests/expectations/tag/box.c +++ b/tests/expectations/tag/box.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using Box = T*; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h> @@ -11,6 +17,6 @@ int32_t *number; }; -void delete(int32_t *x); +void drop_box(int32_t *x); void root(const Foo *a, const struct MyStruct *with_box);
diff --git a/tests/expectations/tag/box.compat.c b/tests/expectations/tag/box.compat.c index 3bf1324..ae01678 100644 --- a/tests/expectations/tag/box.compat.c +++ b/tests/expectations/tag/box.compat.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using Box = T*; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h> @@ -15,7 +21,7 @@ extern "C" { #endif // __cplusplus -void delete(int32_t *x); +void drop_box(int32_t *x); void root(const Foo *a, const struct MyStruct *with_box);
diff --git a/tests/expectations/tag/manuallydrop.c b/tests/expectations/tag/manuallydrop.c index 193bfba..8a0f8da 100644 --- a/tests/expectations/tag/manuallydrop.c +++ b/tests/expectations/tag/manuallydrop.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using ManuallyDrop = T; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h>
diff --git a/tests/expectations/tag/manuallydrop.compat.c b/tests/expectations/tag/manuallydrop.compat.c index 55cea1b..113bcb5 100644 --- a/tests/expectations/tag/manuallydrop.compat.c +++ b/tests/expectations/tag/manuallydrop.compat.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using ManuallyDrop = T; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h>
diff --git a/tests/expectations/tag/maybeuninit.c b/tests/expectations/tag/maybeuninit.c index 2461776..56075ed 100644 --- a/tests/expectations/tag/maybeuninit.c +++ b/tests/expectations/tag/maybeuninit.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using MaybeUninit = T; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h>
diff --git a/tests/expectations/tag/maybeuninit.compat.c b/tests/expectations/tag/maybeuninit.compat.c index 4e8cc80..2a75f8b 100644 --- a/tests/expectations/tag/maybeuninit.compat.c +++ b/tests/expectations/tag/maybeuninit.compat.c
@@ -1,3 +1,9 @@ +#ifdef __cplusplus +template <typename T> +using MaybeUninit = T; +#endif + + #include <stdarg.h> #include <stdbool.h> #include <stdint.h>
diff --git a/tests/rust/box.skip_cpp.rs b/tests/rust/box.rs similarity index 83% rename from tests/rust/box.skip_cpp.rs rename to tests/rust/box.rs index 11cc49a..11bc2a9 100644 --- a/tests/rust/box.skip_cpp.rs +++ b/tests/rust/box.rs
@@ -13,4 +13,4 @@ pub extern "C" fn root(a: &Foo, with_box: &MyStruct) {} #[no_mangle] -pub extern "C" fn delete(x: Box<i32>) {} +pub extern "C" fn drop_box(x: Box<i32>) {}
diff --git a/tests/rust/box.toml b/tests/rust/box.toml new file mode 100644 index 0000000..1a303a5 --- /dev/null +++ b/tests/rust/box.toml
@@ -0,0 +1,11 @@ +header = """ +#ifdef __cplusplus +template <typename T> +using Box = T*; +#endif +""" +[export] +exclude = [ + "Box", +] +
diff --git a/tests/rust/manuallydrop.skip_cpp.rs b/tests/rust/manuallydrop.rs similarity index 100% rename from tests/rust/manuallydrop.skip_cpp.rs rename to tests/rust/manuallydrop.rs
diff --git a/tests/rust/manuallydrop.toml b/tests/rust/manuallydrop.toml new file mode 100644 index 0000000..f5353e4 --- /dev/null +++ b/tests/rust/manuallydrop.toml
@@ -0,0 +1,10 @@ +header = """ +#ifdef __cplusplus +template <typename T> +using ManuallyDrop = T; +#endif +""" +[export] +exclude = [ + "ManuallyDrop", +]
diff --git a/tests/rust/maybeuninit.skip_cpp.rs b/tests/rust/maybeuninit.rs similarity index 100% rename from tests/rust/maybeuninit.skip_cpp.rs rename to tests/rust/maybeuninit.rs
diff --git a/tests/rust/maybeuninit.toml b/tests/rust/maybeuninit.toml new file mode 100644 index 0000000..d649cb0 --- /dev/null +++ b/tests/rust/maybeuninit.toml
@@ -0,0 +1,10 @@ +header = """ +#ifdef __cplusplus +template <typename T> +using MaybeUninit = T; +#endif +""" +[export] +exclude = [ + "MaybeUninit", +]
diff --git a/tests/tests.rs b/tests/tests.rs index 0c27b32..0d1df08 100644 --- a/tests/tests.rs +++ b/tests/tests.rs
@@ -130,7 +130,6 @@ } } -const SKIP_CPP_SUFFIX: &'static str = ".skip_cpp"; const SKIP_WARNING_AS_ERROR_SUFFIX: &'static str = ".skip_warning_as_error"; fn run_compile_test( @@ -169,10 +168,8 @@ }; let skip_warning_as_error = name.rfind(SKIP_WARNING_AS_ERROR_SUFFIX).is_some(); - let skip_cpp = name.rfind(SKIP_CPP_SUFFIX).is_some(); let source_file = format!("{}.{}", &name, &ext) - .replace(SKIP_CPP_SUFFIX, "") .replace(SKIP_WARNING_AS_ERROR_SUFFIX, ""); generated_file.push(source_file); @@ -195,7 +192,7 @@ skip_warning_as_error, ); - if language == Language::C && cpp_compat && !skip_cpp { + if language == Language::C && cpp_compat { compile( &generated_file, &tests_path, @@ -228,19 +225,15 @@ } } - let skip_cpp = name.rfind(SKIP_CPP_SUFFIX).is_some(); - - if !skip_cpp { - run_compile_test( - cbindgen_path, - name, - &test, - tmp_dir, - Language::Cxx, - /* cpp_compat = */ false, - None, - ); - } + run_compile_test( + cbindgen_path, + name, + &test, + tmp_dir, + Language::Cxx, + /* cpp_compat = */ false, + None, + ); } macro_rules! test_file {