tests: Instead of adding skip_cpp as a feature, make the tests work with C++
This commit is contained in:
@@ -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 @@ 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);
|
||||
|
||||
@@ -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 @@ 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);
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using ManuallyDrop = T;
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using ManuallyDrop = T;
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using MaybeUninit = T;
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using MaybeUninit = T;
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -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 @@ 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);
|
||||
|
||||
@@ -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 @@ 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);
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using ManuallyDrop = T;
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using ManuallyDrop = T;
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -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"
|
||||
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using MaybeUninit = T;
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using MaybeUninit = T;
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -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"
|
||||
@@ -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 @@ 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);
|
||||
|
||||
@@ -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 @@ 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);
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using ManuallyDrop = T;
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using ManuallyDrop = T;
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using MaybeUninit = T;
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using MaybeUninit = T;
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -13,4 +13,4 @@ pub type Foo = NotReprC<Box<i32>>;
|
||||
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>) {}
|
||||
@@ -0,0 +1,11 @@
|
||||
header = """
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using Box = T*;
|
||||
#endif
|
||||
"""
|
||||
[export]
|
||||
exclude = [
|
||||
"Box",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
header = """
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using ManuallyDrop = T;
|
||||
#endif
|
||||
"""
|
||||
[export]
|
||||
exclude = [
|
||||
"ManuallyDrop",
|
||||
]
|
||||
@@ -0,0 +1,10 @@
|
||||
header = """
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
using MaybeUninit = T;
|
||||
#endif
|
||||
"""
|
||||
[export]
|
||||
exclude = [
|
||||
"MaybeUninit",
|
||||
]
|
||||
+11
-19
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user