From 5d1217c7c0cad9bc433a6a9ff6576d5bda5a53f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 29 Sep 2020 13:26:33 +0200 Subject: [PATCH] tests: Instead of adding skip_cpp as a feature, make the tests work with C++ --- tests/expectations/both/box.c | 8 ++++- tests/expectations/both/box.compat.c | 8 ++++- tests/expectations/both/manuallydrop.c | 6 ++++ tests/expectations/both/manuallydrop.compat.c | 6 ++++ tests/expectations/both/maybeuninit.c | 6 ++++ tests/expectations/both/maybeuninit.compat.c | 6 ++++ tests/expectations/box.c | 8 ++++- tests/expectations/box.compat.c | 8 ++++- tests/expectations/box.cpp | 27 ++++++++++++++++ tests/expectations/manuallydrop.c | 6 ++++ tests/expectations/manuallydrop.compat.c | 6 ++++ tests/expectations/manuallydrop.cpp | 32 +++++++++++++++++++ tests/expectations/maybeuninit.c | 6 ++++ tests/expectations/maybeuninit.compat.c | 6 ++++ tests/expectations/maybeuninit.cpp | 25 +++++++++++++++ tests/expectations/tag/box.c | 8 ++++- tests/expectations/tag/box.compat.c | 8 ++++- tests/expectations/tag/manuallydrop.c | 6 ++++ tests/expectations/tag/manuallydrop.compat.c | 6 ++++ tests/expectations/tag/maybeuninit.c | 6 ++++ tests/expectations/tag/maybeuninit.compat.c | 6 ++++ tests/rust/{box.skip_cpp.rs => box.rs} | 2 +- tests/rust/box.toml | 11 +++++++ ...nuallydrop.skip_cpp.rs => manuallydrop.rs} | 0 tests/rust/manuallydrop.toml | 10 ++++++ ...maybeuninit.skip_cpp.rs => maybeuninit.rs} | 0 tests/rust/maybeuninit.toml | 10 ++++++ tests/tests.rs | 30 +++++++---------- 28 files changed, 241 insertions(+), 26 deletions(-) create mode 100644 tests/expectations/box.cpp create mode 100644 tests/expectations/manuallydrop.cpp create mode 100644 tests/expectations/maybeuninit.cpp rename tests/rust/{box.skip_cpp.rs => box.rs} (83%) create mode 100644 tests/rust/box.toml rename tests/rust/{manuallydrop.skip_cpp.rs => manuallydrop.rs} (100%) create mode 100644 tests/rust/manuallydrop.toml rename tests/rust/{maybeuninit.skip_cpp.rs => maybeuninit.rs} (100%) create mode 100644 tests/rust/maybeuninit.toml 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 +using Box = T*; +#endif + + #include #include #include @@ -11,6 +17,6 @@ typedef struct MyStruct { 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 +using Box = T*; +#endif + + #include #include #include @@ -15,7 +21,7 @@ typedef struct MyStruct { 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 +using ManuallyDrop = T; +#endif + + #include #include #include 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 +using ManuallyDrop = T; +#endif + + #include #include #include 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 +using MaybeUninit = T; +#endif + + #include #include #include 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 +using MaybeUninit = T; +#endif + + #include #include #include 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 +using Box = T*; +#endif + + #include #include #include @@ -11,6 +17,6 @@ typedef struct { 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 +using Box = T*; +#endif + + #include #include #include @@ -15,7 +21,7 @@ typedef struct { 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 +using Box = T*; +#endif + + +#include +#include +#include +#include + +template +struct NotReprC; + +using Foo = NotReprC>; + +struct MyStruct { + Box number; +}; + +extern "C" { + +void drop_box(Box 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 +using ManuallyDrop = T; +#endif + + #include #include #include 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 +using ManuallyDrop = T; +#endif + + #include #include #include 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 +using ManuallyDrop = T; +#endif + + +#include +#include +#include +#include + +template +struct NotReprC; + +struct Point { + int32_t x; + int32_t y; +}; + +using Foo = NotReprC>; + +struct MyStruct { + ManuallyDrop point; +}; + +extern "C" { + +void root(const Foo *a, const MyStruct *with_manual_drop); + +void take(ManuallyDrop 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 +using MaybeUninit = T; +#endif + + #include #include #include 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 +using MaybeUninit = T; +#endif + + #include #include #include 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 +using MaybeUninit = T; +#endif + + +#include +#include +#include +#include + +template +struct NotReprC; + +using Foo = NotReprC>; + +struct MyStruct { + MaybeUninit 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 +using Box = T*; +#endif + + #include #include #include @@ -11,6 +17,6 @@ struct MyStruct { 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 +using Box = T*; +#endif + + #include #include #include @@ -15,7 +21,7 @@ struct MyStruct { 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 +using ManuallyDrop = T; +#endif + + #include #include #include 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 +using ManuallyDrop = T; +#endif + + #include #include #include 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 +using MaybeUninit = T; +#endif + + #include #include #include 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 +using MaybeUninit = T; +#endif + + #include #include #include 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 type Foo = NotReprC>; pub extern "C" fn root(a: &Foo, with_box: &MyStruct) {} #[no_mangle] -pub extern "C" fn delete(x: Box) {} +pub extern "C" fn drop_box(x: Box) {} 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 +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 +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 +using MaybeUninit = T; +#endif +""" +[export] +exclude = [ + "MaybeUninit", +] diff --git a/tests/tests.rs b/tests/tests.rs index 0c27b32..b622468 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -130,7 +130,6 @@ fn compile( } } -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,11 +168,8 @@ fn run_compile_test( }; 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, ""); + let source_file = format!("{}.{}", &name, &ext).replace(SKIP_WARNING_AS_ERROR_SUFFIX, ""); generated_file.push(source_file); @@ -195,7 +191,7 @@ fn run_compile_test( 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 +224,15 @@ fn test_file(cbindgen_path: &'static str, name: &'static str, filename: &'static } } - 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 {