Commit 34671d9a authored by Johan Anderholm's avatar Johan Anderholm

Modify test to run all three styles for C.

parent 35fa1b54
......@@ -13,7 +13,7 @@ def build_cbindgen():
except subprocess.CalledProcessError:
return False
def cbindgen(path, out, c):
def cbindgen(path, out, c, style):
bin = ["cargo", "run", "--"]
compile = [path, "-o", out]
flags = []
......@@ -21,6 +21,9 @@ def cbindgen(path, out, c):
if c:
flags += ["--lang", "c"]
if style:
flags += ["--style", style]
config = path.replace(".rs", ".toml")
if not os.path.isdir(path) and os.path.exists(config):
flags += ["--config", config]
......@@ -45,7 +48,7 @@ def gxx(src):
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, should_verify, c):
def run_compile_test(rust_src, should_verify, c, style=""):
is_crate = os.path.isdir(rust_src)
test_name = rust_src
......@@ -59,7 +62,8 @@ def run_compile_test(rust_src, should_verify, c):
expectation = False
if c:
out = os.path.join('tests/expectations/', test_name + ".c")
subdir = style if style != "type" else ""
out = os.path.join('tests/expectations/', subdir, test_name + ".c")
verify = 'tests/expectations/__verify__.c'
else:
out = os.path.join('tests/expectations/', test_name + ".cpp")
......@@ -67,7 +71,7 @@ def run_compile_test(rust_src, should_verify, c):
try:
if should_verify:
cbindgen(rust_src, verify, c)
cbindgen(rust_src, verify, c, style)
if c:
gcc(verify)
......@@ -79,7 +83,7 @@ def run_compile_test(rust_src, should_verify, c):
return False
os.remove(verify)
else:
cbindgen(rust_src, out, c)
cbindgen(rust_src, out, c, style)
if c:
gcc(out)
......@@ -118,12 +122,13 @@ num_fail = 0
# C
for test in tests:
if run_compile_test(test, should_verify, True):
num_pass += 1
print("Pass - %s" % test)
else:
num_fail += 1
print("Fail - %s" % test)
for style in ["type", "tag", "both"]:
if run_compile_test(test, should_verify, True, style):
num_pass += 1
print("Pass - %s" % test)
else:
num_fail += 1
print("Fail - %s" % test)
# C++
......
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
enum Status {
Ok,
Err,
};
typedef uint32_t Status;
typedef struct Dep {
int32_t a;
float b;
} Dep;
typedef struct Foo_i32 {
int32_t a;
int32_t b;
Dep c;
} Foo_i32;
typedef Foo_i32 IntFoo;
typedef struct Foo_f64 {
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 <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
enum C {
X = 2,
Y,
};
typedef uint32_t C;
typedef struct A {
int32_t m0;
} A;
typedef struct B {
int32_t x;
float y;
} B;
void root(A x, B y, C z);
#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))(void);
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 <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#if (defined(NOT_DEFINED) || defined(DEFINED))
typedef struct Foo {
int32_t x;
} Foo;
#endif
#if defined(NOT_DEFINED)
typedef struct Bar {
Foo y;
} Bar;
#endif
#if defined(DEFINED)
typedef struct Bar {
Foo z;
} Bar;
#endif
typedef struct Root {
Bar w;
} Root;
void root(Root a);
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#if (defined(PLATFORM_WIN) || defined(M_32))
enum BarType {
A,
B,
C,
};
typedef uint32_t BarType;
#endif
#if (defined(PLATFORM_UNIX) && defined(X11))
enum FooType {
A,
B,
C,
};
typedef uint32_t FooType;
#endif
#if (defined(PLATFORM_UNIX) && defined(X11))
typedef struct FooHandle {
FooType ty;
int32_t x;
float y;
} FooHandle;
#endif
#if (defined(PLATFORM_WIN) || defined(M_32))
typedef struct BarHandle {
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 <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#define FOO 10
#define ZOM 3.14
typedef struct Foo {
int32_t x[FOO];
} Foo;
void root(Foo x);
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct Rect {
float x;
float y;
float w;
float h;
} Rect;
typedef struct Color {
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
} Color;
enum DisplayItem_Tag {
Fill,
Image,
ClearScreen,
};
typedef uint8_t DisplayItem_Tag;
typedef struct Fill_Body {
DisplayItem_Tag tag;
Rect _0;
Color _1;
} Fill_Body;
typedef struct Image_Body {
DisplayItem_Tag tag;
uint32_t id;
Rect bounds;
} Image_Body;
typedef union DisplayItem {
DisplayItem_Tag tag;
Fill_Body fill;
Image_Body image;
} DisplayItem;
bool push_item(DisplayItem item);
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
enum A {
a1 = 0,
a2 = 2,
a3,
a4 = 5,
};
typedef uint32_t A;
enum B {
b1 = 0,
b2 = 2,
b3,
b4 = 5,
};
typedef uint16_t B;
enum C {
c1 = 0,
c2 = 2,
c3,
c4 = 5,
};
typedef uint8_t C;
enum D {
d1 = 0,
d2 = 2,
d3,
d4 = 5,
};
typedef uintptr_t D;
enum E {
e1 = 0,
e2 = 2,
e3,
e4 = 5,
};
typedef intptr_t E;
typedef struct I I;
typedef struct J J;
typedef struct Opaque Opaque;
enum F_Tag {
Foo,
Bar,
Baz,
};
typedef uint8_t F_Tag;
typedef struct Foo_Body {
F_Tag tag;
int16_t _0;
} Foo_Body;
typedef struct Bar_Body {
F_Tag tag;
uint8_t x;
int16_t y;
} Bar_Body;
typedef union F {
F_Tag tag;
Foo_Body foo;
Bar_Body bar;
} F;
typedef enum G_Tag {
G_Foo,
G_Bar,
G_Baz,
} G_Tag;
typedef struct G_Foo_Body {
int16_t _0;
} G_Foo_Body;
typedef struct G_Bar_Body {
uint8_t x;
int16_t y;
} G_Bar_Body;
typedef struct G {
G_Tag tag;
union {
G_Foo_Body foo;
G_Bar_Body bar;
};
} G;
enum H_Tag {
H_Foo,
H_Bar,
H_Baz,
};
typedef uint8_t H_Tag;
typedef struct H_Foo_Body {
int16_t _0;
} H_Foo_Body;
typedef struct H_Bar_Body {
uint8_t x;
int16_t y;
} H_Bar_Body;
typedef struct H {
H_Tag tag;
union {
H_Foo_Body foo;
H_Bar_Body bar;
};
} H;
void root(Opaque *o, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j);
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct TypedLength_f32__UnknownUnit {
float _0;
} TypedLength_f32__UnknownUnit;
typedef struct TypedLength_f32__LayoutUnit {
float _0;
} TypedLength_f32__LayoutUnit;
typedef TypedLength_f32__UnknownUnit Length_f32;
typedef TypedLength_f32__LayoutUnit LayoutLength;
typedef struct TypedSideOffsets2D_f32__UnknownUnit {
float top;
float right;
float bottom;
float left;
} TypedSideOffsets2D_f32__UnknownUnit;
typedef struct TypedSideOffsets2D_f32__LayoutUnit {
float top;
float right;
float bottom;
float left;
} TypedSideOffsets2D_f32__LayoutUnit;
typedef TypedSideOffsets2D_f32__UnknownUnit SideOffsets2D_f32;
typedef TypedSideOffsets2D_f32__LayoutUnit LayoutSideOffsets2D;
typedef struct TypedSize2D_f32__UnknownUnit {
float width;
float height;
} TypedSize2D_f32__UnknownUnit;
typedef struct TypedSize2D_f32__LayoutUnit {
float width;
float height;
} TypedSize2D_f32__LayoutUnit;
typedef TypedSize2D_f32__UnknownUnit Size2D_f32;
typedef TypedSize2D_f32__LayoutUnit LayoutSize2D;
typedef struct TypedPoint2D_f32__UnknownUnit {
float x;
float y;
} TypedPoint2D_f32__UnknownUnit;
typedef struct TypedPoint2D_f32__LayoutUnit {
float x;
float y;
} TypedPoint2D_f32__LayoutUnit;
typedef TypedPoint2D_f32__UnknownUnit Point2D_f32;
typedef TypedPoint2D_f32__LayoutUnit LayoutPoint2D;
typedef struct TypedRect_f32__UnknownUnit {
TypedPoint2D_f32__UnknownUnit origin;
TypedSize2D_f32__UnknownUnit size;
} TypedRect_f32__UnknownUnit;
typedef struct TypedRect_f32__LayoutUnit {
TypedPoint2D_f32__LayoutUnit origin;
TypedSize2D_f32__LayoutUnit size;
} TypedRect_f32__LayoutUnit;
typedef TypedRect_f32__UnknownUnit Rect_f32;
typedef TypedRect_f32__LayoutUnit LayoutRect;
typedef struct TypedTransform2D_f32__UnknownUnit__LayoutUnit {
float m11;
float m12;
float m21;
float m22;
float m31;
float m32;
} TypedTransform2D_f32__UnknownUnit__LayoutUnit;
typedef struct TypedTransform2D_f32__LayoutUnit__UnknownUnit {
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 <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct Foo {
} Foo;
void root(Foo a);
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
void first(void);
void second(void);
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct Normal {
int32_t x;
float y;
} Normal;
extern void bar(Normal a);
extern int32_t foo(void);
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct A {
int32_t x;
float y;
} A;
typedef struct B {
A data;
} B;
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct Foo {
float x;
} Foo;
void root(Foo a);
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct Bar_Bar_f32 Bar_Bar_f32;
typedef struct Bar_Foo_f32 Bar_Foo_f32;
typedef struct Bar_f32 Bar_f32;
typedef struct Foo_i32 {
const int32_t *data;
} Foo_i32;
typedef struct Foo_f32 {
const float *data;
} Foo_f32;
typedef struct Foo_Bar_f32 {
const Bar_f32 *data;
} Foo_Bar_f32;
typedef struct Tuple_Foo_f32_____f32 {
const Foo_f32 *a;
const float *b;
} Tuple_Foo_f32_____f32;
typedef struct Tuple_f32__f32 {
const float *a;
const float *b;
} Tuple_f32__f32;
typedef Tuple_f32__f32 Indirection_f32;
void root(Foo_i32 a,
Foo_f32 b,
Bar_f32 c,
Foo_Bar_f32 d,
Bar_Foo_f32 e,
Bar_Bar_f32 f,
Tuple_Foo_f32_____f32 g,
Indirection_f32 h);
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct A A;
typedef struct B B;
typedef struct List_B {
B *members;
uintptr_t count;
} List_B;
typedef struct List_A {
A *members;
uintptr_t count;
} List_A;
void bar(List_B b);
void foo(List_A a);
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct Bar_Bar_f32 Bar_Bar_f32;
typedef struct Bar_Foo_f32 Bar_Foo_f32;
typedef struct Bar_f32 Bar_f32;
typedef union Foo_i32 {
const int32_t *data;
} Foo_i32;
typedef union Foo_f32 {
const float *data;
} Foo_f32;
typedef union Foo_Bar_f32 {
const Bar_f32 *data;
} Foo_Bar_f32;
typedef union Tuple_Foo_f32_____f32 {
const Foo_f32 *a;
const float *b;
} Tuple_Foo_f32_____f32;
typedef union Tuple_f32__f32 {
const float *a;
const float *b;
} Tuple_f32__f32;
typedef Tuple_f32__f32 Indirection_f32;
void root(Foo_i32 a,
Foo_f32 b,
Bar_f32 c,
Foo_Bar_f32 d,
Bar_Foo_f32 e,
Bar_Bar_f32 f,
Tuple_Foo_f32_____f32 g,
Indirection_f32 h);
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#define C_H 10
enum C_E {
x = 0,
y = 1,
};
typedef uint8_t C_E;
typedef struct C_A C_A;