Commit 6a02ec4a authored by Ryan Hunt's avatar Ryan Hunt

Commit test expectations

parent b2587edf
......@@ -9,7 +9,7 @@ description = "A tool for generating C bindings to Rust code."
keywords = ["bindings", "ffi", "code-generation"]
categories = ["external-ffi-bindings", "development-tools::ffi"]
repository = "https://github.com/eqrion/cbindgen/"
exclude = ["test.py", "compile-tests/**"]
exclude = ["test.py", "tests/**"]
[badges]
travis-ci = { repository = "eqrion/cbindgen" }
......
......@@ -32,22 +32,22 @@ def gcc(src):
if gcc_bin == None:
gcc_bin = 'gcc'
subprocess.check_output([gcc_bin, "-D", "DEFINED", "-c", src, "-o", "compile-tests/tmp.o"])
os.remove("compile-tests/tmp.o")
subprocess.check_output([gcc_bin, "-D", "DEFINED", "-c", src, "-o", "tests/expectations/tmp.o"])
os.remove("tests/expectations/tmp.o")
def gxx(src):
gxx_bin = os.environ.get('CXX')
if gxx_bin == None:
gxx_bin = 'g++'
subprocess.check_output([gxx_bin, "-D", "DEFINED", "-std=c++11", "-c", src, "-o", "compile-tests/tmp.o"])
os.remove("compile-tests/tmp.o")
subprocess.check_output([gxx_bin, "-D", "DEFINED", "-std=c++11", "-c", src, "-o", "tests/expectations/tmp.o"])
os.remove("tests/expectations/tmp.o")
def run_compile_test(rust_src, leave_output, c):
def run_compile_test(rust_src, c):
if c:
out = rust_src.replace(".rs", ".c")
out = os.path.join('tests/expectations/', os.path.basename(rust_src).replace(".rs", ".c"))
else:
out = rust_src.replace(".rs", ".cpp")
out = os.path.join('tests/expectations/', os.path.basename(rust_src).replace(".rs", ".cpp"))
config = rust_src.replace(".rs", ".toml")
if not os.path.exists(config):
......@@ -61,11 +61,7 @@ def run_compile_test(rust_src, leave_output, c):
else:
gxx(out)
if not leave_output:
os.remove(out)
except subprocess.CalledProcessError:
if not leave_output and os.path.exists(out):
os.remove(out)
return False
return True
......@@ -75,28 +71,30 @@ if not build_cbindgen():
args = sys.argv[1:]
files = [x for x in args if not x.startswith("-")]
flags = [x for x in args if x.startswith("-")]
leave_output = False
c = False
for flag in flags:
if flag == "-l":
leave_output = True
elif flag == "-c":
c = True
tests = []
if len(files) == 0:
tests = glob.glob("compile-tests/*.rs")
tests = glob.glob("tests/rust/*.rs")
else:
tests = files
num_pass = 0
num_fail = 0
# C
for test in tests:
if run_compile_test(test, True):
num_pass += 1
print("Pass - %s" % test)
else:
num_fail += 1
print("Fail - %s" % test)
# C++
for test in tests:
if run_compile_test(test, leave_output, c):
if run_compile_test(test, False):
num_pass += 1
print("Pass - %s" % test)
else:
......
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
enum Status {
Ok = 0,
Err = 1,
};
typedef uint32_t Status;
typedef struct {
int32_t a;
float b;
} Dep;
typedef struct {
int32_t a;
int32_t b;
Dep c;
} Foo_i32;
typedef Foo_i32 IntFoo;
typedef struct {
double a;
double b;
Dep c;
} Foo_f64;
typedef Foo_f64 DoubleFoo;
typedef int32_t Unit;
typedef Status SpecialStatus;
void root(IntFoo x, DoubleFoo y, Unit z, SpecialStatus w);
#include <cstdint>
#include <cstdlib>
extern "C" {
enum class Status : uint32_t {
Ok = 0,
Err = 1,
};
struct Dep {
int32_t a;
float b;
};
struct Foo_i32 {
int32_t a;
int32_t b;
Dep c;
};
typedef Foo_i32 IntFoo;
struct Foo_f64 {
double a;
double b;
Dep c;
};
typedef Foo_f64 DoubleFoo;
typedef int32_t Unit;
typedef Status SpecialStatus;
void root(IntFoo x, DoubleFoo y, Unit z, SpecialStatus w);
} // extern "C"
template<typename X>
struct Foo;
template<>
struct Foo<double> : public Foo_f64 {
};
template<>
struct Foo<int32_t> : public Foo_i32 {
};
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
enum C {
X = 2,
Y = 3,
};
typedef uint32_t C;
typedef struct {
int32_t m0;
} A;
typedef struct {
int32_t x;
float y;
} B;
void root(A x, B y, C z);
#include <cstdint>
#include <cstdlib>
extern "C" {
enum class C : uint32_t {
X = 2,
Y = 3,
};
struct A {
int32_t m0;
bool operator<(const A& other) const {
return m0 < other.m0;
}
bool operator<=(const A& other) const {
return m0 <= other.m0;
}
};
struct B {
int32_t x;
float y;
};
void root(A x, B y, C z);
} // extern "C"
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef void (*A)();
typedef void (*B)();
typedef bool (*C)(int32_t, int32_t);
typedef bool (*(*D)(int32_t))(float);
typedef int32_t (*(*E)())[16];
typedef const int32_t *F;
typedef const int32_t *const *G;
typedef int32_t *const *H;
typedef int32_t (*I)[16];
typedef double (**J)(float);
typedef int32_t K[16];
typedef const int32_t *L[16];
typedef bool (*M[16])(int32_t, int32_t);
typedef void (*N[16])(int32_t, int32_t);
void (*O())();
void root(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n);
#include <cstdint>
#include <cstdlib>
extern "C" {
typedef void (*A)();
typedef void (*B)();
typedef bool (*C)(int32_t, int32_t);
typedef bool (*(*D)(int32_t))(float);
typedef int32_t (*(*E)())[16];
typedef const int32_t *F;
typedef const int32_t *const *G;
typedef int32_t *const *H;
typedef int32_t (*I)[16];
typedef double (**J)(float);
typedef int32_t K[16];
typedef const int32_t *L[16];
typedef bool (*M[16])(int32_t, int32_t);
typedef void (*N[16])(int32_t, int32_t);
void (*O())();
void root(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n);
} // extern "C"
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#if (defined(NOT_DEFINED) || defined(DEFINED))
typedef struct {
int32_t x;
} Foo;
#endif
#if defined(NOT_DEFINED)
typedef struct {
Foo y;
} Bar;
#endif
#if defined(DEFINED)
typedef struct {
Foo z;
} Bar;
#endif
typedef struct {
Bar w;
} Root;
void root(Root a);
#include <cstdint>
#include <cstdlib>
extern "C" {
#if (defined(NOT_DEFINED) || defined(DEFINED))
struct Foo {
int32_t x;
};
#endif
#if defined(NOT_DEFINED)
struct Bar {
Foo y;
};
#endif
#if defined(DEFINED)
struct Bar {
Foo z;
};
#endif
struct Root {
Bar w;
};
void root(Root a);
} // extern "C"
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#if (defined(PLATFORM_WIN) || defined(M_32))
enum BarType {
A = 0,
B = 1,
C = 2,
};
typedef uint32_t BarType;
#endif
#if (defined(PLATFORM_UNIX) && defined(X11))
enum FooType {
A = 0,
B = 1,
C = 2,
};
typedef uint32_t FooType;
#endif
#if (defined(PLATFORM_UNIX) && defined(X11))
typedef struct {
FooType ty;
int32_t x;
float y;
} FooHandle;
#endif
#if (defined(PLATFORM_WIN) || defined(M_32))
typedef struct {
BarType ty;
int32_t x;
float y;
} BarHandle;
#endif
#if (defined(PLATFORM_UNIX) && defined(X11))
void root(FooHandle a);
#endif
#if (defined(PLATFORM_WIN) || defined(M_32))
void root(BarHandle a);
#endif
#include <cstdint>
#include <cstdlib>
extern "C" {
#if (defined(PLATFORM_WIN) || defined(M_32))
enum class BarType : uint32_t {
A = 0,
B = 1,
C = 2,
};
#endif
#if (defined(PLATFORM_UNIX) && defined(X11))
enum class FooType : uint32_t {
A = 0,
B = 1,
C = 2,
};
#endif
#if (defined(PLATFORM_UNIX) && defined(X11))
struct FooHandle {
FooType ty;
int32_t x;
float y;
};
#endif
#if (defined(PLATFORM_WIN) || defined(M_32))
struct BarHandle {
BarType ty;
int32_t x;
float y;
};
#endif
#if (defined(PLATFORM_UNIX) && defined(X11))
void root(FooHandle a);
#endif
#if (defined(PLATFORM_WIN) || defined(M_32))
void root(BarHandle a);
#endif
} // extern "C"
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#define BAR u8"hello world"
#define FOO 10
#define ZOM 3.14
typedef struct {
int32_t x[FOO];
} Foo;
void root(Foo x);
#include <cstdint>
#include <cstdlib>
extern "C" {
static const char* BAR = u8"hello world";
static const int32_t FOO = 10;
static const float ZOM = 3.14;
struct Foo {
int32_t x[FOO];
};
void root(Foo x);
} // extern "C"
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
enum A {
a1 = 0,
a2 = 2,
a3 = 3,
a4 = 5,
};
typedef uint32_t A;
enum B {
b1 = 0,
b2 = 2,
b3 = 3,
b4 = 5,
};
typedef uint16_t B;
enum C {
c1 = 0,
c2 = 2,
c3 = 3,
c4 = 5,
};
typedef uint8_t C;
enum D {
d1 = 0,
d2 = 2,
d3 = 3,
d4 = 5,
};
typedef uintptr_t D;
enum E {
e1 = 0,
e2 = 2,
e3 = 3,
e4 = 5,
};
typedef intptr_t E;
struct Opaque;
typedef struct Opaque Opaque;
void root(Opaque *o, A a, B b, C c, D d, E e);
#include <cstdint>
#include <cstdlib>
extern "C" {
enum class A : uint32_t {
a1 = 0,
a2 = 2,
a3 = 3,
a4 = 5,
};
enum class B : uint16_t {
b1 = 0,
b2 = 2,
b3 = 3,
b4 = 5,
};
enum class C : uint8_t {
c1 = 0,
c2 = 2,
c3 = 3,
c4 = 5,
};
enum class D : uintptr_t {
d1 = 0,
d2 = 2,
d3 = 3,
d4 = 5,
};
enum class E : intptr_t {
e1 = 0,
e2 = 2,
e3 = 3,
e4 = 5,
};
struct Opaque;
void root(Opaque *o, A a, B b, C c, D d, E e);
} // extern "C"
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct {
float _0;
} TypedLength_f32__UnknownUnit;
typedef struct {
float _0;
} TypedLength_f32__LayoutUnit;
typedef struct {
float _0;
} Length_f32;
typedef TypedLength_f32__LayoutUnit LayoutLength;
typedef struct {
float top;
float right;
float bottom;
float left;
} TypedSideOffsets2D_f32__UnknownUnit;
typedef struct {
float top;
float right;
float bottom;
float left;
} TypedSideOffsets2D_f32__LayoutUnit;
typedef struct {
float top;
float right;
float bottom;
float left;
} SideOffsets2D_f32;
typedef TypedSideOffsets2D_f32__LayoutUnit LayoutSideOffsets2D;
typedef struct {
float width;
float height;
} TypedSize2D_f32__UnknownUnit;
typedef struct {
float width;
float height;
} TypedSize2D_f32__LayoutUnit;
typedef struct {
float width;
float height;
} Size2D_f32;
typedef TypedSize2D_f32__LayoutUnit LayoutSize2D;
typedef struct {
float x;
float y;
} TypedPoint2D_f32__UnknownUnit;
typedef struct {
float x;
float y;
} TypedPoint2D_f32__LayoutUnit;
typedef struct {
float x;
float y;
} Point2D_f32;
typedef TypedPoint2D_f32__LayoutUnit LayoutPoint2D;
typedef struct {
TypedPoint2D_f32__UnknownUnit origin;
TypedSize2D_f32__UnknownUnit size;
} TypedRect_f32__UnknownUnit;
typedef struct {
TypedPoint2D_f32__LayoutUnit origin;
TypedSize2D_f32__LayoutUnit size;
} TypedRect_f32__LayoutUnit;
typedef struct {
TypedPoint2D_f32__UnknownUnit origin;
TypedSize2D_f32__UnknownUnit size;
} Rect_f32;
typedef TypedRect_f32__LayoutUnit LayoutRect;
typedef struct {
float m11;
float m12;
float m21;
float m22;
float m31;
float m32;
} TypedTransform2D_f32__UnknownUnit__LayoutUnit;
typedef struct {
float m11;
float m12;
float m21;
float m22;
float m31;
float m32;
} TypedTransform2D_f32__LayoutUnit__UnknownUnit;
void root(TypedLength_f32__UnknownUnit length_a,
TypedLength_f32__LayoutUnit length_b,
Length_f32 length_c,
LayoutLength length_d,
TypedSideOffsets2D_f32__UnknownUnit side_offsets_a,
TypedSideOffsets2D_f32__LayoutUnit side_offsets_b,
SideOffsets2D_f32 side_offsets_c,
LayoutSideOffsets2D side_offsets_d,
TypedSize2D_f32__UnknownUnit size_a,
TypedSize2D_f32__LayoutUnit size_b,
Size2D_f32 size_c,
LayoutSize2D size_d,
TypedPoint2D_f32__UnknownUnit point_a,
TypedPoint2D_f32__LayoutUnit point_b,
Point2D_f32 point_c,
LayoutPoint2D point_d,
TypedRect_f32__UnknownUnit rect_a,
TypedRect_f32__LayoutUnit rect_b,
Rect_f32 rect_c,
LayoutRect rect_d,
TypedTransform2D_f32__UnknownUnit__LayoutUnit transform_a,
TypedTransform2D_f32__LayoutUnit__UnknownUnit transform_b);
#include <cstdint>
#include <cstdlib>