Browse Source

Merge gcc-lua-cdecl

Peter Colberg 2 years ago
parent
commit
268f69419e

+ 2
- 0
gcc-lua-cdecl/ffi-cdecl/C.lua.in View File

@@ -1,3 +1,5 @@
1
+package.path = "./?.lua;../?.lua;" .. package.path
2
+
1 3
 local gcc = require("gcc")
2 4
 local cdecl = require("gcc.cdecl")
3 5
 local fficdecl = require("ffi-cdecl")

+ 0
- 7
gcc-lua-cdecl/ffi-cdecl/Makefile View File

@@ -3,13 +3,6 @@ CPPFLAGS =
3 3
 CFLAGS = -Wall -pedantic -O2
4 4
 GCCLUA = $(CURDIR)/../../gcc-lua/gcc/gcclua.so
5 5
 
6
-ifdef LUA_PATH
7
-LUA_PATH := $(CURDIR)/?.lua;$(CURDIR)/../?.lua;$(LUA_PATH)
8
-else
9
-LUA_PATH := $(CURDIR)/?.lua;$(CURDIR)/../?.lua;;
10
-endif
11
-export LUA_PATH
12
-
13 6
 all: C.lua
14 7
 
15 8
 %.lua: %.c %.lua.in

+ 0
- 7
gcc-lua-cdecl/test/Makefile View File

@@ -9,13 +9,6 @@ CFLAGS = -Wall
9 9
 CCOPT = -std=gnu99
10 10
 GCCLUA = $(CURDIR)/../../gcc-lua/gcc/gcclua.so
11 11
 
12
-ifdef LUA_PATH
13
-LUA_PATH := $(CURDIR)/../?.lua;$(CURDIR)/../?/init.lua;$(LUA_PATH)
14
-else
15
-LUA_PATH := $(CURDIR)/../?.lua;$(CURDIR)/../?/init.lua;;
16
-endif
17
-export LUA_PATH
18
-
19 12
 all: array composite enum function pointer scalar variable vector
20 13
 
21 14
 %: %.c %.lua

+ 33
- 27
gcc-lua-cdecl/test/array.lua View File

@@ -4,8 +4,14 @@
4 4
 -- Distributed under the MIT license. (See accompanying file LICENSE.)
5 5
 --
6 6
 
7
+package.path = "../?.lua;" .. package.path
8
+
7 9
 local gcc   = require("gcc")
8 10
 local cdecl = require("gcc.cdecl")
11
+local test  = require("test")
12
+
13
+-- Cache library functions.
14
+local assert_equal = test.assert_equal
9 15
 
10 16
 gcc.set_asm_file_name(gcc.HOST_BIT_BUCKET)
11 17
 
@@ -22,58 +28,58 @@ end)
22 28
 
23 29
 -- array type
24 30
 function test.array_3_of_array_4_of_int(decl)
25
-  assert(cdecl.declare(decl:type()) == "int[3][4]")
26
-  assert(cdecl.declare(decl) == "int array_3_of_array_4_of_int[3][4]")
31
+  assert_equal(cdecl.declare(decl:type()), "int[3][4]")
32
+  assert_equal(cdecl.declare(decl), "int array_3_of_array_4_of_int[3][4]")
27 33
 end
28 34
 
29 35
 function test.array_5_of_ptr_to_int(decl)
30
-  assert(cdecl.declare(decl:type()) == "int *[5]")
31
-  assert(cdecl.declare(decl) == "int *array_5_of_ptr_to_int[5]")
36
+  assert_equal(cdecl.declare(decl:type()), "int *[5]")
37
+  assert_equal(cdecl.declare(decl), "int *array_5_of_ptr_to_int[5]")
32 38
 end
33 39
 
34 40
 function test.ptr_to_array_of_int(decl)
35
-  assert(cdecl.declare(decl:type()) == "int (*)[]")
36
-  assert(cdecl.declare(decl) == "int (*ptr_to_array_of_int)[]")
41
+  assert_equal(cdecl.declare(decl:type()), "int (*)[]")
42
+  assert_equal(cdecl.declare(decl), "int (*ptr_to_array_of_int)[]")
37 43
 end
38 44
 
39 45
 function test.ptr_to_array_4_of_const_restrict_ptr_to_array_5_of_int(decl)
40
-  assert(cdecl.declare(decl:type()) == "int (*const restrict (*)[4])[5]")
41
-  assert(cdecl.declare(decl) == "int (*const restrict (*ptr_to_array_4_of_const_restrict_ptr_to_array_5_of_int)[4])[5]")
46
+  assert_equal(cdecl.declare(decl:type()), "int (*const restrict (*)[4])[5]")
47
+  assert_equal(cdecl.declare(decl), "int (*const restrict (*ptr_to_array_4_of_const_restrict_ptr_to_array_5_of_int)[4])[5]")
42 48
 end
43 49
 
44 50
 function test.array_2_of_const_ptr_to_array_3_of_restrict_ptr_to_volatile_bool(decl)
45
-  assert(cdecl.declare(decl:type()) == "volatile _Bool *restrict (*const[2])[3]")
46
-  assert(cdecl.declare(decl) == "volatile _Bool *restrict (*const array_2_of_const_ptr_to_array_3_of_restrict_ptr_to_volatile_bool[2])[3]")
51
+  assert_equal(cdecl.declare(decl:type()), "volatile _Bool *restrict (*const[2])[3]")
52
+  assert_equal(cdecl.declare(decl), "volatile _Bool *restrict (*const array_2_of_const_ptr_to_array_3_of_restrict_ptr_to_volatile_bool[2])[3]")
47 53
 end
48 54
 
49 55
 -- array type declaration
50 56
 function test.array_3_of_int(decl)
51
-  assert(cdecl.declare(decl:type():name()) == "typedef int array_3_of_int_type[3]")
52
-  assert(cdecl.declare(decl:type()) == "int[3]")
53
-  assert(cdecl.declare(decl) == "int array_3_of_int[3]")
54
-  assert(cdecl.declare(decl:type():name(), function(node)
57
+  assert_equal(cdecl.declare(decl:type():name()), "typedef int array_3_of_int_type[3]")
58
+  assert_equal(cdecl.declare(decl:type()), "int[3]")
59
+  assert_equal(cdecl.declare(decl), "int array_3_of_int[3]")
60
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
55 61
     return node:name():value()
56
-  end) == "typedef int array_3_of_int_type[3]")
57
-  assert(cdecl.declare(decl:type(), function(node)
62
+  end), "typedef int array_3_of_int_type[3]")
63
+  assert_equal(cdecl.declare(decl:type(), function(node)
58 64
     return node:name():value()
59
-  end) == "array_3_of_int_type")
60
-  assert(cdecl.declare(decl, function(node)
65
+  end), "array_3_of_int_type")
66
+  assert_equal(cdecl.declare(decl, function(node)
61 67
     return node:name():value()
62
-  end) == "array_3_of_int_type array_3_of_int")
63
-  assert(cdecl.declare(decl:type():name(), function(node)
68
+  end), "array_3_of_int_type array_3_of_int")
69
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
64 70
     return node:name():value():upper()
65
-  end) == "typedef INT ARRAY_3_OF_INT_TYPE[3]")
66
-  assert(cdecl.declare(decl:type(), function(node)
71
+  end), "typedef INT ARRAY_3_OF_INT_TYPE[3]")
72
+  assert_equal(cdecl.declare(decl:type(), function(node)
67 73
     return node:name():value():upper()
68
-  end) == "ARRAY_3_OF_INT_TYPE")
69
-  assert(cdecl.declare(decl, function(node)
74
+  end), "ARRAY_3_OF_INT_TYPE")
75
+  assert_equal(cdecl.declare(decl, function(node)
70 76
     return node:name():value():upper()
71
-  end) == [[ARRAY_3_OF_INT_TYPE ARRAY_3_OF_INT __asm__("array_3_of_int")]])
77
+  end), [[ARRAY_3_OF_INT_TYPE ARRAY_3_OF_INT __asm__("array_3_of_int")]])
72 78
 end
73 79
 
74 80
 -- C99: flexible array member
75 81
 function test.struct_int_array_of_char(decl)
76
-  assert(cdecl.declare(decl:type()) == [[
82
+  assert_equal(cdecl.declare(decl:type()), [[
77 83
 struct {
78 84
   int i;
79 85
   char c[];
@@ -82,7 +88,7 @@ end
82 88
 
83 89
 -- GCC C extension: zero-length array member
84 90
 function test.struct_long_array_of_short(decl)
85
-  assert(cdecl.declare(decl:type()) == [[
91
+  assert_equal(cdecl.declare(decl:type()), [[
86 92
 struct {
87 93
   long int l;
88 94
   short int s[];

+ 58
- 52
gcc-lua-cdecl/test/composite.lua View File

@@ -4,8 +4,14 @@
4 4
 -- Distributed under the MIT license. (See accompanying file LICENSE.)
5 5
 --
6 6
 
7
+package.path = "../?.lua;" .. package.path
8
+
7 9
 local gcc   = require("gcc")
8 10
 local cdecl = require("gcc.cdecl")
11
+local test  = require("test")
12
+
13
+-- Cache library functions.
14
+local assert_equal = test.assert_equal
9 15
 
10 16
 gcc.set_asm_file_name(gcc.HOST_BIT_BUCKET)
11 17
 
@@ -22,78 +28,78 @@ end)
22 28
 
23 29
 -- composite type
24 30
 function test.tagged_struct_decl(decl)
25
-  assert(cdecl.declare(decl) == "struct tagged_struct tagged_struct_decl")
26
-  assert(cdecl.declare(decl, function(node)
31
+  assert_equal(cdecl.declare(decl), "struct tagged_struct tagged_struct_decl")
32
+  assert_equal(cdecl.declare(decl, function(node)
27 33
     return node:name():value()
28
-  end) == "tagged_struct tagged_struct_decl")
29
-  assert(cdecl.declare(decl, function(node)
34
+  end), "tagged_struct tagged_struct_decl")
35
+  assert_equal(cdecl.declare(decl, function(node)
30 36
     return node:name():value():upper()
31
-  end) == [[TAGGED_STRUCT TAGGED_STRUCT_DECL __asm__("tagged_struct_decl")]])
32
-  assert(cdecl.declare(decl:type()) == [[
37
+  end), [[TAGGED_STRUCT TAGGED_STRUCT_DECL __asm__("tagged_struct_decl")]])
38
+  assert_equal(cdecl.declare(decl:type()), [[
33 39
 struct tagged_struct {
34 40
   short int s;
35 41
   int i;
36 42
 }]])
37
-  assert(cdecl.declare(decl:type(), function(node)
43
+  assert_equal(cdecl.declare(decl:type(), function(node)
38 44
     return node:name():value()
39
-  end) == "tagged_struct")
40
-  assert(cdecl.declare(decl:type(), function(node)
45
+  end), "tagged_struct")
46
+  assert_equal(cdecl.declare(decl:type(), function(node)
41 47
     return node:name():value():upper()
42
-  end) == "TAGGED_STRUCT")
43
-  assert(cdecl.declare(decl:type():main_variant()) == [[
48
+  end), "TAGGED_STRUCT")
49
+  assert_equal(cdecl.declare(decl:type():main_variant()), [[
44 50
 struct tagged_struct {
45 51
   short int s;
46 52
   int i;
47 53
 }]])
48
-  assert(cdecl.declare(decl:type():main_variant(), function(node)
54
+  assert_equal(cdecl.declare(decl:type():main_variant(), function(node)
49 55
     return node:name():value()
50
-  end) == [[
56
+  end), [[
51 57
 struct tagged_struct {
52 58
   short int s;
53 59
   int i;
54 60
 }]])
55
-  assert(cdecl.declare(decl:type():main_variant(), function(node)
61
+  assert_equal(cdecl.declare(decl:type():main_variant(), function(node)
56 62
     return node:name():value():upper()
57
-  end) == [[
63
+  end), [[
58 64
 struct TAGGED_STRUCT {
59 65
   SHORT INT S;
60 66
   INT I;
61 67
 }]])
62
-  assert(cdecl.declare(decl:type():name(), function(node)
68
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
63 69
     return node:name():value()
64
-  end) == "typedef struct tagged_struct tagged_struct")
65
-  assert(cdecl.declare(decl:type():name(), function(node)
70
+  end), "typedef struct tagged_struct tagged_struct")
71
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
66 72
     return node:name():value():upper()
67
-  end) == "typedef struct TAGGED_STRUCT TAGGED_STRUCT")
73
+  end), "typedef struct TAGGED_STRUCT TAGGED_STRUCT")
68 74
 end
69 75
 
70 76
 function test.untagged_struct_decl(decl)
71
-  assert(cdecl.declare(decl) == [[
77
+  assert_equal(cdecl.declare(decl), [[
72 78
 struct {
73 79
   short int s;
74 80
   int i;
75 81
 } untagged_struct_decl]])
76
-  assert(cdecl.declare(decl:type()) == [[
82
+  assert_equal(cdecl.declare(decl:type()), [[
77 83
 struct {
78 84
   short int s;
79 85
   int i;
80 86
 }]])
81
-  assert(cdecl.declare(decl:type():main_variant()) == [[
87
+  assert_equal(cdecl.declare(decl:type():main_variant()), [[
82 88
 struct {
83 89
   short int s;
84 90
   int i;
85 91
 }]])
86
-  assert(cdecl.declare(decl:type():main_variant()) == [[
92
+  assert_equal(cdecl.declare(decl:type():main_variant()), [[
87 93
 struct {
88 94
   short int s;
89 95
   int i;
90 96
 }]])
91
-  assert(cdecl.declare(decl:type():name()) == [[
97
+  assert_equal(cdecl.declare(decl:type():name()), [[
92 98
 typedef struct {
93 99
   short int s;
94 100
   int i;
95 101
 } untagged_struct]])
96
-  assert(cdecl.declare(decl:type():name()) == [[
102
+  assert_equal(cdecl.declare(decl:type():name()), [[
97 103
 typedef struct {
98 104
   short int s;
99 105
   int i;
@@ -101,41 +107,41 @@ typedef struct {
101 107
 end
102 108
 
103 109
 function test.empty_struct_decl(decl)
104
-  assert(cdecl.declare(decl) == [[
110
+  assert_equal(cdecl.declare(decl), [[
105 111
 struct {
106 112
 } empty_struct_decl]])
107
-  assert(cdecl.declare(decl:type()) == [[
113
+  assert_equal(cdecl.declare(decl:type()), [[
108 114
 struct {
109 115
 }]])
110
-  assert(cdecl.declare(decl:type():name()) == [[
116
+  assert_equal(cdecl.declare(decl:type():name()), [[
111 117
 typedef struct {
112 118
 } empty_struct]])
113 119
 end
114 120
 
115 121
 -- opaque composite type
116 122
 function test.opaque_union_decl(decl)
117
-  assert(cdecl.declare(decl) == "union opaque_union *opaque_union_decl")
118
-  assert(cdecl.declare(decl:type()) == "union opaque_union *")
119
-  assert(cdecl.declare(decl:type():type()) == "union opaque_union")
123
+  assert_equal(cdecl.declare(decl), "union opaque_union *opaque_union_decl")
124
+  assert_equal(cdecl.declare(decl:type()), "union opaque_union *")
125
+  assert_equal(cdecl.declare(decl:type():type()), "union opaque_union")
120 126
 end
121 127
 
122 128
 -- composite type as function argument
123 129
 function test.ptr_to_func_const_struct_tagged_struct_void_ret_void(decl)
124
-  assert(cdecl.declare(decl) == "void (*ptr_to_func_const_struct_tagged_struct_void_ret_void)(const struct tagged_struct)")
125
-  assert(cdecl.declare(decl:type()) == "void (*)(const struct tagged_struct)")
126
-  assert(cdecl.declare(decl:type():type()) == "void (const struct tagged_struct)")
130
+  assert_equal(cdecl.declare(decl), "void (*ptr_to_func_const_struct_tagged_struct_void_ret_void)(const struct tagged_struct)")
131
+  assert_equal(cdecl.declare(decl:type()), "void (*)(const struct tagged_struct)")
132
+  assert_equal(cdecl.declare(decl:type():type()), "void (const struct tagged_struct)")
127 133
 end
128 134
 
129 135
 function test.ptr_to_func_const_tagged_struct_void_ret_void(decl)
130
-  assert(cdecl.declare(decl) == "void (*ptr_to_func_const_tagged_struct_void_ret_void)(const struct tagged_struct)")
131
-  assert(cdecl.declare(decl:type()) == "void (*)(const struct tagged_struct)")
132
-  assert(cdecl.declare(decl:type():type()) == "void (const struct tagged_struct)")
136
+  assert_equal(cdecl.declare(decl), "void (*ptr_to_func_const_tagged_struct_void_ret_void)(const struct tagged_struct)")
137
+  assert_equal(cdecl.declare(decl:type()), "void (*)(const struct tagged_struct)")
138
+  assert_equal(cdecl.declare(decl:type():type()), "void (const struct tagged_struct)")
133 139
 end
134 140
 
135 141
 -- bitfield
136 142
 function test.bitfield_decl(decl)
137
-  assert(cdecl.declare(decl) == "struct bitfield bitfield_decl")
138
-  assert(cdecl.declare(decl:type()) == [[
143
+  assert_equal(cdecl.declare(decl), "struct bitfield bitfield_decl")
144
+  assert_equal(cdecl.declare(decl:type()), [[
139 145
 struct bitfield {
140 146
   unsigned int unsigned_int_bitfield : 1;
141 147
   int signed_int_bitfield : 2;
@@ -143,7 +149,7 @@ struct bitfield {
143 149
   int : 4;
144 150
   short unsigned int unsigned_short;
145 151
 }]])
146
-  assert(cdecl.declare(decl:type():main_variant()) == [[
152
+  assert_equal(cdecl.declare(decl:type():main_variant()), [[
147 153
 struct bitfield {
148 154
   unsigned int unsigned_int_bitfield : 1;
149 155
   int signed_int_bitfield : 2;
@@ -151,11 +157,11 @@ struct bitfield {
151 157
   int : 4;
152 158
   short unsigned int unsigned_short;
153 159
 }]])
154
-  assert(cdecl.declare(decl:type():name()) == "typedef struct bitfield bitfield_type")
160
+  assert_equal(cdecl.declare(decl:type():name()), "typedef struct bitfield bitfield_type")
155 161
 end
156 162
 
157 163
 function test.nested_bitfield_decl(decl)
158
-  assert(cdecl.declare(decl) == [[
164
+  assert_equal(cdecl.declare(decl), [[
159 165
 struct {
160 166
   unsigned int unsigned_int_bitfield : 1;
161 167
   int signed_int_bitfield : 2;
@@ -163,7 +169,7 @@ struct {
163 169
   int : 4;
164 170
   struct bitfield struct_bitfield;
165 171
 } nested_bitfield_decl]])
166
-  assert(cdecl.declare(decl:type()) == [[
172
+  assert_equal(cdecl.declare(decl:type()), [[
167 173
 struct {
168 174
   unsigned int unsigned_int_bitfield : 1;
169 175
   int signed_int_bitfield : 2;
@@ -171,7 +177,7 @@ struct {
171 177
   int : 4;
172 178
   struct bitfield struct_bitfield;
173 179
 }]])
174
-  assert(cdecl.declare(decl:type():main_variant()) == [[
180
+  assert_equal(cdecl.declare(decl:type():main_variant()), [[
175 181
 struct {
176 182
   unsigned int unsigned_int_bitfield : 1;
177 183
   int signed_int_bitfield : 2;
@@ -179,7 +185,7 @@ struct {
179 185
   int : 4;
180 186
   struct bitfield struct_bitfield;
181 187
 }]])
182
-  assert(cdecl.declare(decl:type():name()) == [[
188
+  assert_equal(cdecl.declare(decl:type():name()), [[
183 189
 typedef struct {
184 190
   unsigned int unsigned_int_bitfield : 1;
185 191
   int signed_int_bitfield : 2;
@@ -187,9 +193,9 @@ typedef struct {
187 193
   int : 4;
188 194
   struct bitfield struct_bitfield;
189 195
 } nested_bitfield_type]])
190
-  assert(cdecl.declare(decl:type():name(), function(node)
196
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
191 197
     return node:name() and node:name():value():upper()
192
-  end) == [[
198
+  end), [[
193 199
 typedef struct {
194 200
   UNSIGNED INT UNSIGNED_INT_BITFIELD : 1;
195 201
   INT SIGNED_INT_BITFIELD : 2;
@@ -201,23 +207,23 @@ end
201 207
 
202 208
 -- GCC C extension: composite type attributes
203 209
 function test.packed_struct_decl(decl)
204
-  assert(cdecl.declare(decl) == "struct packed_struct packed_struct_decl")
205
-  assert(cdecl.declare(decl:type()) == [[
210
+  assert_equal(cdecl.declare(decl), "struct packed_struct packed_struct_decl")
211
+  assert_equal(cdecl.declare(decl:type()), [[
206 212
 struct packed_struct {
207 213
   short int s;
208 214
   int i;
209 215
 } __attribute__((packed))]])
210
-  assert(cdecl.declare(decl:type():main_variant()) == [[
216
+  assert_equal(cdecl.declare(decl:type():main_variant()), [[
211 217
 struct packed_struct {
212 218
   short int s;
213 219
   int i;
214 220
 } __attribute__((packed))]])
215
-  assert(cdecl.declare(decl:type():name()) == "typedef struct packed_struct packed_struct")
221
+  assert_equal(cdecl.declare(decl:type():name()), "typedef struct packed_struct packed_struct")
216 222
 end
217 223
 
218 224
 -- GCC C extension: unnamed anonymous members
219 225
 function test.anon_struct_union(decl)
220
-  assert(cdecl.declare(decl:type()) == [[
226
+  assert_equal(cdecl.declare(decl:type()), [[
221 227
 union {
222 228
   int s[4] __attribute__((aligned(16)));
223 229
   struct {

+ 51
- 45
gcc-lua-cdecl/test/enum.lua View File

@@ -4,8 +4,14 @@
4 4
 -- Distributed under the MIT license. (See accompanying file LICENSE.)
5 5
 --
6 6
 
7
+package.path = "../?.lua;" .. package.path
8
+
7 9
 local gcc   = require("gcc")
8 10
 local cdecl = require("gcc.cdecl")
11
+local test  = require("test")
12
+
13
+-- Cache library functions.
14
+local assert_equal = test.assert_equal
9 15
 
10 16
 gcc.set_asm_file_name(gcc.HOST_BIT_BUCKET)
11 17
 
@@ -22,56 +28,56 @@ end)
22 28
 
23 29
 -- enumeral type
24 30
 function test.tagged_enum(decl)
25
-  assert(cdecl.declare(decl) == "enum interaction tagged_enum")
26
-  assert(cdecl.declare(decl, function(node)
31
+  assert_equal(cdecl.declare(decl), "enum interaction tagged_enum")
32
+  assert_equal(cdecl.declare(decl, function(node)
27 33
     return node:name():value()
28
-  end) == "interaction tagged_enum")
29
-  assert(cdecl.declare(decl, function(node)
34
+  end), "interaction tagged_enum")
35
+  assert_equal(cdecl.declare(decl, function(node)
30 36
     return node:name():value():upper()
31
-  end) == [[INTERACTION TAGGED_ENUM __asm__("tagged_enum")]])
32
-  assert(cdecl.declare(decl:type()) == [[
37
+  end), [[INTERACTION TAGGED_ENUM __asm__("tagged_enum")]])
38
+  assert_equal(cdecl.declare(decl:type()), [[
33 39
 enum interaction {
34 40
   strong = 0,
35 41
   weak = 1,
36 42
   electromagnetic = 2,
37 43
   gravitational = 3,
38 44
 }]])
39
-  assert(cdecl.declare(decl:type(), function(node)
45
+  assert_equal(cdecl.declare(decl:type(), function(node)
40 46
     return node:name():value()
41
-  end) == "interaction")
42
-  assert(cdecl.declare(decl:type(), function(node)
47
+  end), "interaction")
48
+  assert_equal(cdecl.declare(decl:type(), function(node)
43 49
     return node:name():value():upper()
44
-  end) == "INTERACTION")
45
-  assert(cdecl.declare(decl:type():main_variant()) == [[
50
+  end), "INTERACTION")
51
+  assert_equal(cdecl.declare(decl:type():main_variant()), [[
46 52
 enum interaction {
47 53
   strong = 0,
48 54
   weak = 1,
49 55
   electromagnetic = 2,
50 56
   gravitational = 3,
51 57
 }]])
52
-  assert(cdecl.declare(decl:type():main_variant(), function(node)
58
+  assert_equal(cdecl.declare(decl:type():main_variant(), function(node)
53 59
     return node:name():value()
54
-  end) == [[
60
+  end), [[
55 61
 enum interaction {
56 62
   strong = 0,
57 63
   weak = 1,
58 64
   electromagnetic = 2,
59 65
   gravitational = 3,
60 66
 }]])
61
-  assert(cdecl.declare(decl:type():main_variant(), function(node)
67
+  assert_equal(cdecl.declare(decl:type():main_variant(), function(node)
62 68
     return node:name():value():upper()
63
-  end) == [[
69
+  end), [[
64 70
 enum INTERACTION {
65 71
   strong = 0,
66 72
   weak = 1,
67 73
   electromagnetic = 2,
68 74
   gravitational = 3,
69 75
 }]])
70
-  assert(cdecl.declare(decl:type():name()) == "typedef enum interaction interaction")
76
+  assert_equal(cdecl.declare(decl:type():name()), "typedef enum interaction interaction")
71 77
 end
72 78
 
73 79
 function test.untagged_enum(decl)
74
-  assert(cdecl.declare(decl) == [[
80
+  assert_equal(cdecl.declare(decl), [[
75 81
 enum {
76 82
   hydrogen = 1,
77 83
   helim = 2,
@@ -79,10 +85,10 @@ enum {
79 85
   carbon = 6,
80 86
   neon = 10,
81 87
 } untagged_enum]])
82
-  assert(cdecl.declare(decl, function(node)
88
+  assert_equal(cdecl.declare(decl, function(node)
83 89
     return node:name():value()
84
-  end) == "elements untagged_enum")
85
-  assert(cdecl.declare(decl:type()) == [[
90
+  end), "elements untagged_enum")
91
+  assert_equal(cdecl.declare(decl:type()), [[
86 92
 enum {
87 93
   hydrogen = 1,
88 94
   helim = 2,
@@ -90,13 +96,13 @@ enum {
90 96
   carbon = 6,
91 97
   neon = 10,
92 98
 }]])
93
-  assert(cdecl.declare(decl:type(), function(node)
99
+  assert_equal(cdecl.declare(decl:type(), function(node)
94 100
     return node:name():value()
95
-  end) == "elements")
96
-  assert(cdecl.declare(decl:type(), function(node)
101
+  end), "elements")
102
+  assert_equal(cdecl.declare(decl:type(), function(node)
97 103
     return "ELEMENTS"
98
-  end) == "ELEMENTS")
99
-  assert(cdecl.declare(decl:type():main_variant()) == [[
104
+  end), "ELEMENTS")
105
+  assert_equal(cdecl.declare(decl:type():main_variant()), [[
100 106
 enum {
101 107
   hydrogen = 1,
102 108
   helim = 2,
@@ -104,9 +110,9 @@ enum {
104 110
   carbon = 6,
105 111
   neon = 10,
106 112
 }]])
107
-  assert(cdecl.declare(decl:type():main_variant(), function(node)
113
+  assert_equal(cdecl.declare(decl:type():main_variant(), function(node)
108 114
     return node:name() and node:name():value()
109
-  end) == [[
115
+  end), [[
110 116
 enum {
111 117
   hydrogen = 1,
112 118
   helim = 2,
@@ -114,9 +120,9 @@ enum {
114 120
   carbon = 6,
115 121
   neon = 10,
116 122
 }]])
117
-  assert(cdecl.declare(decl:type():main_variant(), function(node)
123
+  assert_equal(cdecl.declare(decl:type():main_variant(), function(node)
118 124
     return "ELEMENTS"
119
-  end) == [[
125
+  end), [[
120 126
 enum ELEMENTS {
121 127
   hydrogen = 1,
122 128
   helim = 2,
@@ -124,7 +130,7 @@ enum ELEMENTS {
124 130
   carbon = 6,
125 131
   neon = 10,
126 132
 }]])
127
-  assert(cdecl.declare(decl:type():name()) == [[
133
+  assert_equal(cdecl.declare(decl:type():name()), [[
128 134
 typedef enum {
129 135
   hydrogen = 1,
130 136
   helim = 2,
@@ -132,9 +138,9 @@ typedef enum {
132 138
   carbon = 6,
133 139
   neon = 10,
134 140
 } elements]])
135
-  assert(cdecl.declare(decl:type():name(), function(node)
141
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
136 142
     return node:name() and node:name():value()
137
-  end) == [[
143
+  end), [[
138 144
 typedef enum {
139 145
   hydrogen = 1,
140 146
   helim = 2,
@@ -142,42 +148,42 @@ typedef enum {
142 148
   carbon = 6,
143 149
   neon = 10,
144 150
 } elements]])
145
-  assert(cdecl.declare(decl:type():name(), function(node)
151
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
146 152
     return "ELEMENTS"
147
-  end) == "typedef enum ELEMENTS ELEMENTS")
153
+  end), "typedef enum ELEMENTS ELEMENTS")
148 154
 end
149 155
 
150 156
 -- enumeral type as function argument
151 157
 function test.ptr_to_func_const_enum_interaction_void_ret_void(decl)
152
-  assert(cdecl.declare(decl) == "void (*ptr_to_func_const_enum_interaction_void_ret_void)(const enum interaction)")
153
-  assert(cdecl.declare(decl:type()) == "void (*)(const enum interaction)")
154
-  assert(cdecl.declare(decl:type():type()) == "void (const enum interaction)")
158
+  assert_equal(cdecl.declare(decl), "void (*ptr_to_func_const_enum_interaction_void_ret_void)(const enum interaction)")
159
+  assert_equal(cdecl.declare(decl:type()), "void (*)(const enum interaction)")
160
+  assert_equal(cdecl.declare(decl:type():type()), "void (const enum interaction)")
155 161
 end
156 162
 
157 163
 function test.ptr_to_func_const_interaction_void_ret_void(decl)
158
-  assert(cdecl.declare(decl) == "void (*ptr_to_func_const_interaction_void_ret_void)(const enum interaction)")
159
-  assert(cdecl.declare(decl:type()) == "void (*)(const enum interaction)")
160
-  assert(cdecl.declare(decl:type():type()) == "void (const enum interaction)")
164
+  assert_equal(cdecl.declare(decl), "void (*ptr_to_func_const_interaction_void_ret_void)(const enum interaction)")
165
+  assert_equal(cdecl.declare(decl:type()), "void (*)(const enum interaction)")
166
+  assert_equal(cdecl.declare(decl:type():type()), "void (const enum interaction)")
161 167
 end
162 168
 
163 169
 -- GCC C extension: enumeral type attributes
164 170
 function test.packed_enum(decl)
165
-  assert(cdecl.declare(decl) == [[
171
+  assert_equal(cdecl.declare(decl), [[
166 172
 enum {
167 173
   FALSE = 0,
168 174
   TRUE = 1,
169 175
 } __attribute__((packed)) packed_enum]])
170
-  assert(cdecl.declare(decl:type()) == [[
176
+  assert_equal(cdecl.declare(decl:type()), [[
171 177
 enum {
172 178
   FALSE = 0,
173 179
   TRUE = 1,
174 180
 } __attribute__((packed))]])
175
-  assert(cdecl.declare(decl:type():name()) == [[
181
+  assert_equal(cdecl.declare(decl:type():name()), [[
176 182
 typedef enum {
177 183
   FALSE = 0,
178 184
   TRUE = 1,
179 185
 } __attribute__((packed)) BOOL]])
180
-  assert(cdecl.declare(decl:type():name(), function(node)
186
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
181 187
     return "BOOL"
182
-  end) == "typedef enum BOOL BOOL")
188
+  end), "typedef enum BOOL BOOL")
183 189
 end

+ 68
- 62
gcc-lua-cdecl/test/function.lua View File

@@ -4,8 +4,14 @@
4 4
 -- Distributed under the MIT license. (See accompanying file LICENSE.)
5 5
 --
6 6
 
7
+package.path = "../?.lua;" .. package.path
8
+
7 9
 local gcc   = require("gcc")
8 10
 local cdecl = require("gcc.cdecl")
11
+local test  = require("test")
12
+
13
+-- Cache library functions.
14
+local assert_equal = test.assert_equal
9 15
 
10 16
 gcc.set_asm_file_name(gcc.HOST_BIT_BUCKET)
11 17
 
@@ -22,98 +28,98 @@ end)
22 28
 
23 29
 -- function type
24 30
 function test.ptr_to_func_int_ret_ptr_to_void(decl)
25
-  assert(cdecl.declare(decl:type()) == "void *(*)(int, ...)")
26
-  assert(cdecl.declare(decl) == "void *(*ptr_to_func_int_ret_ptr_to_void)(int, ...)")
31
+  assert_equal(cdecl.declare(decl:type()), "void *(*)(int, ...)")
32
+  assert_equal(cdecl.declare(decl), "void *(*ptr_to_func_int_ret_ptr_to_void)(int, ...)")
27 33
 end
28 34
 
29 35
 function test.ptr_to_func_int_ret_ptr_to_array_2_of_ptr_to_void(decl)
30
-  assert(cdecl.declare(decl:type()) == "void *(*(*)(int, ...))[2]")
31
-  assert(cdecl.declare(decl) == "void *(*(*ptr_to_func_int_ret_ptr_to_array_2_of_ptr_to_void)(int, ...))[2]")
36
+  assert_equal(cdecl.declare(decl:type()), "void *(*(*)(int, ...))[2]")
37
+  assert_equal(cdecl.declare(decl), "void *(*(*ptr_to_func_int_ret_ptr_to_array_2_of_ptr_to_void)(int, ...))[2]")
32 38
 end
33 39
 
34 40
 function test.ptr_to_func_ret_ptr_to_func_void_ret_ptr_to_array_42_of_ptr_to_func_ptr_to_const_char_ret_float(decl)
35
-  assert(cdecl.declare(decl:type()) == "float (*(*(*(*)())(void))[42])(const char *, ...)")
36
-  assert(cdecl.declare(decl) == "float (*(*(*(*ptr_to_func_ret_ptr_to_func_void_ret_ptr_to_array_42_of_ptr_to_func_ptr_to_const_char_ret_float)())(void))[42])(const char *, ...)")
41
+  assert_equal(cdecl.declare(decl:type()), "float (*(*(*(*)())(void))[42])(const char *, ...)")
42
+  assert_equal(cdecl.declare(decl), "float (*(*(*(*ptr_to_func_ret_ptr_to_func_void_ret_ptr_to_array_42_of_ptr_to_func_ptr_to_const_char_ret_float)())(void))[42])(const char *, ...)")
37 43
 end
38 44
 
39 45
 -- function declaration
40 46
 function test.ptr_to_func_ret_ptr_to_short(decl)
41
-  assert(cdecl.declare(decl:type():type():name()) == "typedef short int *func_ret_ptr_to_short_type()")
42
-  assert(cdecl.declare(decl:type():type()) == "short int *()")
43
-  assert(cdecl.declare(decl:type()) == "short int *(*)()")
44
-  assert(cdecl.declare(decl) == "short int *(*ptr_to_func_ret_ptr_to_short)()")
45
-  assert(cdecl.declare(decl:initial():operand()) == "short int *func_ret_ptr_to_short()")
46
-  assert(cdecl.declare(decl:type():type():name(), function(node)
47
+  assert_equal(cdecl.declare(decl:type():type():name()), "typedef short int *func_ret_ptr_to_short_type()")
48
+  assert_equal(cdecl.declare(decl:type():type()), "short int *()")
49
+  assert_equal(cdecl.declare(decl:type()), "short int *(*)()")
50
+  assert_equal(cdecl.declare(decl), "short int *(*ptr_to_func_ret_ptr_to_short)()")
51
+  assert_equal(cdecl.declare(decl:initial():operand()), "short int *func_ret_ptr_to_short()")
52
+  assert_equal(cdecl.declare(decl:type():type():name(), function(node)
47 53
     return node:name():value()
48
-  end) == "typedef short int *func_ret_ptr_to_short_type()")
49
-  assert(cdecl.declare(decl:type():type(), function(node)
54
+  end), "typedef short int *func_ret_ptr_to_short_type()")
55
+  assert_equal(cdecl.declare(decl:type():type(), function(node)
50 56
     return node:name():value()
51
-  end) == "func_ret_ptr_to_short_type")
52
-  assert(cdecl.declare(decl:type(), function(node)
57
+  end), "func_ret_ptr_to_short_type")
58
+  assert_equal(cdecl.declare(decl:type(), function(node)
53 59
     return node:name():value()
54
-  end) == "func_ret_ptr_to_short_type *")
55
-  assert(cdecl.declare(decl, function(node)
60
+  end), "func_ret_ptr_to_short_type *")
61
+  assert_equal(cdecl.declare(decl, function(node)
56 62
     return node:name():value()
57
-  end) == "func_ret_ptr_to_short_type *ptr_to_func_ret_ptr_to_short")
58
-  assert(cdecl.declare(decl:initial():operand(), function(node)
63
+  end), "func_ret_ptr_to_short_type *ptr_to_func_ret_ptr_to_short")
64
+  assert_equal(cdecl.declare(decl:initial():operand(), function(node)
59 65
     if node == decl:initial():operand() then
60 66
       return node:name():value()
61 67
     end
62
-  end) == "short int *func_ret_ptr_to_short()")
68
+  end), "short int *func_ret_ptr_to_short()")
63 69
 end
64 70
 
65 71
 function test.ptr_to_func_int_ret_void(decl)
66
-  assert(cdecl.declare(decl:type():type():name()) == "typedef void func_int_ret_void_type(int, ...)")
67
-  assert(cdecl.declare(decl:type():type()) == "void (int, ...)")
68
-  assert(cdecl.declare(decl:type()) == "void (*)(int, ...)")
69
-  assert(cdecl.declare(decl) == "void (*ptr_to_func_int_ret_void)(int, ...)")
70
-  assert(cdecl.declare(decl:initial():operand()) == "void func_int_ret_void(int, ...)")
71
-  assert(cdecl.declare(decl:type():type():name(), function(node)
72
+  assert_equal(cdecl.declare(decl:type():type():name()), "typedef void func_int_ret_void_type(int, ...)")
73
+  assert_equal(cdecl.declare(decl:type():type()), "void (int, ...)")
74
+  assert_equal(cdecl.declare(decl:type()), "void (*)(int, ...)")
75
+  assert_equal(cdecl.declare(decl), "void (*ptr_to_func_int_ret_void)(int, ...)")
76
+  assert_equal(cdecl.declare(decl:initial():operand()), "void func_int_ret_void(int, ...)")
77
+  assert_equal(cdecl.declare(decl:type():type():name(), function(node)
72 78
     return node:name():value():upper()
73
-  end) == "typedef VOID FUNC_INT_RET_VOID_TYPE(INT, ...)")
74
-  assert(cdecl.declare(decl:type():type(), function(node)
79
+  end), "typedef VOID FUNC_INT_RET_VOID_TYPE(INT, ...)")
80
+  assert_equal(cdecl.declare(decl:type():type(), function(node)
75 81
     return node:name():value():upper()
76
-  end) == "FUNC_INT_RET_VOID_TYPE")
77
-  assert(cdecl.declare(decl:type(), function(node)
82
+  end), "FUNC_INT_RET_VOID_TYPE")
83
+  assert_equal(cdecl.declare(decl:type(), function(node)
78 84
     return node:name():value():upper()
79
-  end) == "FUNC_INT_RET_VOID_TYPE *")
80
-  assert(cdecl.declare(decl, function(node)
85
+  end), "FUNC_INT_RET_VOID_TYPE *")
86
+  assert_equal(cdecl.declare(decl, function(node)
81 87
     return node:name():value():upper()
82
-  end) == [[FUNC_INT_RET_VOID_TYPE *PTR_TO_FUNC_INT_RET_VOID __asm__("ptr_to_func_int_ret_void")]])
83
-  assert(cdecl.declare(decl:initial():operand(), function(node)
88
+  end), [[FUNC_INT_RET_VOID_TYPE *PTR_TO_FUNC_INT_RET_VOID __asm__("ptr_to_func_int_ret_void")]])
89
+  assert_equal(cdecl.declare(decl:initial():operand(), function(node)
84 90
     if node == decl:initial():operand() then
85 91
       return node:name():value():upper()
86 92
     end
87
-  end) == [[void FUNC_INT_RET_VOID(int, ...) __asm__("func_int_ret_void")]])
93
+  end), [[void FUNC_INT_RET_VOID(int, ...) __asm__("func_int_ret_void")]])
88 94
 end
89 95
 
90 96
 function test.ptr_to_func_char_ptr_to_char_ptr_to_const_char_ret_int(decl)
91
-  assert(cdecl.declare(decl:type():type():name()) == "typedef int func_char_ptr_to_char_ptr_to_const_char_ret_int_type(char *, const char *, ...)")
92
-  assert(cdecl.declare(decl:type():type()) == "int (char *, const char *, ...)")
93
-  assert(cdecl.declare(decl:type()) == "int (*)(char *, const char *, ...)")
94
-  assert(cdecl.declare(decl) == "int (*ptr_to_func_char_ptr_to_char_ptr_to_const_char_ret_int)(char *, const char *, ...)")
95
-  assert(cdecl.declare(decl:initial():operand()) == "int func_char_ptr_to_char_ptr_to_const_char_ret_int(char *, const char *, ...)")
97
+  assert_equal(cdecl.declare(decl:type():type():name()), "typedef int func_char_ptr_to_char_ptr_to_const_char_ret_int_type(char *, const char *, ...)")
98
+  assert_equal(cdecl.declare(decl:type():type()), "int (char *, const char *, ...)")
99
+  assert_equal(cdecl.declare(decl:type()), "int (*)(char *, const char *, ...)")
100
+  assert_equal(cdecl.declare(decl), "int (*ptr_to_func_char_ptr_to_char_ptr_to_const_char_ret_int)(char *, const char *, ...)")
101
+  assert_equal(cdecl.declare(decl:initial():operand()), "int func_char_ptr_to_char_ptr_to_const_char_ret_int(char *, const char *, ...)")
96 102
 end
97 103
 
98 104
 function test.ptr_to_func_int_void_ret_void(decl)
99
-  assert(cdecl.declare(decl:type():type():name()) == "typedef void func_int_void_ret_void_type(int)")
100
-  assert(cdecl.declare(decl:type():type()) == "void (int)")
101
-  assert(cdecl.declare(decl:type()) == "void (*)(int)")
102
-  assert(cdecl.declare(decl) == "void (*ptr_to_func_int_void_ret_void)(int)")
103
-  assert(cdecl.declare(decl:initial():operand()) == "void func_int_void_ret_void(int)")
105
+  assert_equal(cdecl.declare(decl:type():type():name()), "typedef void func_int_void_ret_void_type(int)")
106
+  assert_equal(cdecl.declare(decl:type():type()), "void (int)")
107
+  assert_equal(cdecl.declare(decl:type()), "void (*)(int)")
108
+  assert_equal(cdecl.declare(decl), "void (*ptr_to_func_int_void_ret_void)(int)")
109
+  assert_equal(cdecl.declare(decl:initial():operand()), "void func_int_void_ret_void(int)")
104 110
 end
105 111
 
106 112
 function test.ptr_to_func_void_ret_void(decl)
107
-  assert(cdecl.declare(decl:type():type()) == "void (void)")
108
-  assert(cdecl.declare(decl:type()) == "void (*)(void)")
109
-  assert(cdecl.declare(decl) == "void (*ptr_to_func_void_ret_void)(void)")
110
-  assert(cdecl.declare(decl:initial():operand()) == "void func_void_ret_void(void)")
111
-  assert(cdecl.declare(decl:initial():operand(), function(node)
113
+  assert_equal(cdecl.declare(decl:type():type()), "void (void)")
114
+  assert_equal(cdecl.declare(decl:type()), "void (*)(void)")
115
+  assert_equal(cdecl.declare(decl), "void (*ptr_to_func_void_ret_void)(void)")
116
+  assert_equal(cdecl.declare(decl:initial():operand()), "void func_void_ret_void(void)")
117
+  assert_equal(cdecl.declare(decl:initial():operand(), function(node)
112 118
     if node == decl:initial():operand() then
113 119
       return "function_void_returning_void"
114 120
     end
115
-  end) == [[void function_void_returning_void(void) __asm__("func_void_ret_void")]])
116
-  assert(cdecl.declare(decl:initial():operand():type()) == "void (void)")
121
+  end), [[void function_void_returning_void(void) __asm__("func_void_ret_void")]])
122
+  assert_equal(cdecl.declare(decl:initial():operand():type()), "void (void)")
117 123
 end
118 124
 
119 125
 -- variable-length argument list
@@ -125,15 +131,15 @@ end
125 131
 
126 132
 -- GCC C extension: function declaration attributes
127 133
 function test.ptr_to_func_void_ret_aligned_int(decl)
128
-  assert(cdecl.declare(decl:type():type():type():name()) == "typedef int aligned_int __attribute__((aligned(16)))")
129
-  assert(cdecl.declare(decl:type():type():type()) == "int")
130
-  assert(cdecl.declare(decl) == "int (*ptr_to_func_void_ret_aligned_int)(void)")
131
-  assert(cdecl.declare(decl:initial():operand()) == [[int func_void_ret_aligned_int(void) __attribute__((nothrow, visibility("default")))]])
132
-  assert(cdecl.declare(decl:initial():operand(), function(node)
134
+  assert_equal(cdecl.declare(decl:type():type():type():name()), "typedef int aligned_int __attribute__((aligned(16)))")
135
+  assert_equal(cdecl.declare(decl:type():type():type()), "int")
136
+  assert_equal(cdecl.declare(decl), "int (*ptr_to_func_void_ret_aligned_int)(void)")
137
+  assert_equal(cdecl.declare(decl:initial():operand()), [[int func_void_ret_aligned_int(void) __attribute__((nothrow, visibility("default")))]])
138
+  assert_equal(cdecl.declare(decl:initial():operand(), function(node)
133 139
     return node:name():value()
134
-  end) == [[aligned_int func_void_ret_aligned_int(void) __attribute__((nothrow, visibility("default")))]])
135
-  assert(cdecl.declare(decl:initial():operand():type()) == "int (void)")
136
-  assert(cdecl.declare(decl:initial():operand():type(), function(node)
140
+  end), [[aligned_int func_void_ret_aligned_int(void) __attribute__((nothrow, visibility("default")))]])
141
+  assert_equal(cdecl.declare(decl:initial():operand():type()), "int (void)")
142
+  assert_equal(cdecl.declare(decl:initial():operand():type(), function(node)
137 143
     return node:name():value()
138
-  end) == "aligned_int (void)")
144
+  end), "aligned_int (void)")
139 145
 end

+ 90
- 84
gcc-lua-cdecl/test/pointer.lua View File

@@ -4,8 +4,14 @@
4 4
 -- Distributed under the MIT license. (See accompanying file LICENSE.)
5 5
 --
6 6
 
7
+package.path = "../?.lua;" .. package.path
8
+
7 9
 local gcc   = require("gcc")
8 10
 local cdecl = require("gcc.cdecl")
11
+local test  = require("test")
12
+
13
+-- Cache library functions.
14
+local assert_equal = test.assert_equal
9 15
 
10 16
 gcc.set_asm_file_name(gcc.HOST_BIT_BUCKET)
11 17
 
@@ -22,139 +28,139 @@ end)
22 28
 
23 29
 -- pointer type
24 30
 function test.ptr_to_const_int(decl)
25
-  assert(cdecl.declare(decl:type():type():name()) == "typedef int int_type")
26
-  assert(cdecl.declare(decl:type():type()) == "const int")
27
-  assert(cdecl.declare(decl:type()) == "const int *")
28
-  assert(cdecl.declare(decl) == "const int *ptr_to_const_int")
29
-  assert(cdecl.declare(decl:type():type():name(), function(node)
31
+  assert_equal(cdecl.declare(decl:type():type():name()), "typedef int int_type")
32
+  assert_equal(cdecl.declare(decl:type():type()), "const int")
33
+  assert_equal(cdecl.declare(decl:type()), "const int *")
34
+  assert_equal(cdecl.declare(decl), "const int *ptr_to_const_int")
35
+  assert_equal(cdecl.declare(decl:type():type():name(), function(node)
30 36
     return node:name():value()
31
-  end) == "typedef int int_type")
32
-  assert(cdecl.declare(decl:type():type(), function(node)
37
+  end), "typedef int int_type")
38
+  assert_equal(cdecl.declare(decl:type():type(), function(node)
33 39
     return node:name():value()
34
-  end) == "const int_type")
35
-  assert(cdecl.declare(decl:type(), function(node)
40
+  end), "const int_type")
41
+  assert_equal(cdecl.declare(decl:type(), function(node)
36 42
     return node:name():value()
37
-  end) == "const int_type *")
38
-  assert(cdecl.declare(decl, function(node)
43
+  end), "const int_type *")
44
+  assert_equal(cdecl.declare(decl, function(node)
39 45
     return node:name():value()
40
-  end) == "const int_type *ptr_to_const_int")
46
+  end), "const int_type *ptr_to_const_int")
41 47
 end
42 48
 
43 49
 function test.restrict_ptr_to_const_int(decl)
44
-  assert(cdecl.declare(decl:type():type():name()) == "typedef int int_type")
45
-  assert(cdecl.declare(decl:type():type()) == "const int")
46
-  assert(cdecl.declare(decl:type()) == "const int *restrict")
47
-  assert(cdecl.declare(decl) == "const int *restrict restrict_ptr_to_const_int")
48
-  assert(cdecl.declare(decl:type():type():name(), function(node)
50
+  assert_equal(cdecl.declare(decl:type():type():name()), "typedef int int_type")
51
+  assert_equal(cdecl.declare(decl:type():type()), "const int")
52
+  assert_equal(cdecl.declare(decl:type()), "const int *restrict")
53
+  assert_equal(cdecl.declare(decl), "const int *restrict restrict_ptr_to_const_int")
54
+  assert_equal(cdecl.declare(decl:type():type():name(), function(node)
49 55
     return node:name():value()
50
-  end) == "typedef int int_type")
51
-  assert(cdecl.declare(decl:type():type(), function(node)
56
+  end), "typedef int int_type")
57
+  assert_equal(cdecl.declare(decl:type():type(), function(node)
52 58
     return node:name():value()
53
-  end) == "const int_type")
54
-  assert(cdecl.declare(decl:type(), function(node)
59
+  end), "const int_type")
60
+  assert_equal(cdecl.declare(decl:type(), function(node)
55 61
     return node:name():value()
56
-  end) == "const int_type *restrict")
57
-  assert(cdecl.declare(decl, function(node)
62
+  end), "const int_type *restrict")
63
+  assert_equal(cdecl.declare(decl, function(node)
58 64
     return node:name():value()
59
-  end) == "const int_type *restrict restrict_ptr_to_const_int")
65
+  end), "const int_type *restrict restrict_ptr_to_const_int")
60 66
 end
61 67
 
62 68
 function test.restrict_volatile_ptr_to_const_int(decl)
63
-  assert(cdecl.declare(decl:type():type():name()) == "typedef int int_type")
64
-  assert(cdecl.declare(decl:type():type()) == "const int")
65
-  assert(cdecl.declare(decl:type()) == "const int *restrict volatile")
66
-  assert(cdecl.declare(decl) == "const int *restrict volatile restrict_volatile_ptr_to_const_int")
67
-  assert(cdecl.declare(decl:type():type():name(), function(node)
69
+  assert_equal(cdecl.declare(decl:type():type():name()), "typedef int int_type")
70
+  assert_equal(cdecl.declare(decl:type():type()), "const int")
71
+  assert_equal(cdecl.declare(decl:type()), "const int *restrict volatile")
72
+  assert_equal(cdecl.declare(decl), "const int *restrict volatile restrict_volatile_ptr_to_const_int")
73
+  assert_equal(cdecl.declare(decl:type():type():name(), function(node)
68 74
     return node:name():value()
69
-  end) == "typedef int int_type")
70
-  assert(cdecl.declare(decl:type():type(), function(node)
75
+  end), "typedef int int_type")
76
+  assert_equal(cdecl.declare(decl:type():type(), function(node)
71 77
     return node:name():value()
72
-  end) == "const int_type")
73
-  assert(cdecl.declare(decl:type(), function(node)
78
+  end), "const int_type")
79
+  assert_equal(cdecl.declare(decl:type(), function(node)
74 80
     return node:name():value()
75
-  end) == "const int_type *restrict volatile")
76
-  assert(cdecl.declare(decl, function(node)
81
+  end), "const int_type *restrict volatile")
82
+  assert_equal(cdecl.declare(decl, function(node)
77 83
     return node:name():value()
78
-  end) == "const int_type *restrict volatile restrict_volatile_ptr_to_const_int")
84
+  end), "const int_type *restrict volatile restrict_volatile_ptr_to_const_int")
79 85
 end
80 86
 
81 87
 function test.const_restrict_ptr_to_void(decl)
82
-  assert(cdecl.declare(decl:type()) == "void *const restrict")
83
-  assert(cdecl.declare(decl) == "void *const restrict const_restrict_ptr_to_void")
88
+  assert_equal(cdecl.declare(decl:type()), "void *const restrict")
89
+  assert_equal(cdecl.declare(decl), "void *const restrict const_restrict_ptr_to_void")
84 90
 end
85 91
 
86 92
 function test.const_restrict_ptr_to_ptr_to_ptr_to_ptr_to_void(decl)
87
-  assert(cdecl.declare(decl:type()) == "void ****const restrict")
88
-  assert(cdecl.declare(decl) == "void ****const restrict const_restrict_ptr_to_ptr_to_ptr_to_ptr_to_void")
93
+  assert_equal(cdecl.declare(decl:type()), "void ****const restrict")
94
+  assert_equal(cdecl.declare(decl), "void ****const restrict const_restrict_ptr_to_ptr_to_ptr_to_ptr_to_void")
89 95
 end
90 96
 
91 97
 function test.const_restrict_ptr_to_volatile_ptr_to_complex_double(decl)
92
-  assert(cdecl.declare(decl:type()) == "complex double *volatile *const restrict")
93
-  assert(cdecl.declare(decl) == "complex double *volatile *const restrict const_restrict_ptr_to_volatile_ptr_to_complex_double")
98
+  assert_equal(cdecl.declare(decl:type()), "complex double *volatile *const restrict")
99
+  assert_equal(cdecl.declare(decl), "complex double *volatile *const restrict const_restrict_ptr_to_volatile_ptr_to_complex_double")
94 100
 end
95 101
 
96 102
 -- pointer type declaration
97 103
 function test.ptr_to_ptr_to_const_int(decl)
98
-  assert(cdecl.declare(decl:type():type():name()) == "typedef const int *ptr_to_const_int_type")
99
-  assert(cdecl.declare(decl:type():type()) == "const int *")
100
-  assert(cdecl.declare(decl:type()) == "const int **")
101
-  assert(cdecl.declare(decl) == "const int **ptr_to_ptr_to_const_int")
102
-  assert(cdecl.declare(decl:type():type():name(), function(node)
104
+  assert_equal(cdecl.declare(decl:type():type():name()), "typedef const int *ptr_to_const_int_type")
105
+  assert_equal(cdecl.declare(decl:type():type()), "const int *")
106
+  assert_equal(cdecl.declare(decl:type()), "const int **")
107
+  assert_equal(cdecl.declare(decl), "const int **ptr_to_ptr_to_const_int")
108
+  assert_equal(cdecl.declare(decl:type():type():name(), function(node)
103 109
     return node:name():value()
104
-  end) == "typedef const int_type *ptr_to_const_int_type")
105
-  assert(cdecl.declare(decl:type():type(), function(node)
110
+  end), "typedef const int_type *ptr_to_const_int_type")
111
+  assert_equal(cdecl.declare(decl:type():type(), function(node)
106 112
     return node:name():value()
107
-  end) == "ptr_to_const_int_type")
108
-  assert(cdecl.declare(decl:type(), function(node)
113
+  end), "ptr_to_const_int_type")
114
+  assert_equal(cdecl.declare(decl:type(), function(node)
109 115
     return node:name():value()
110
-  end) == "ptr_to_const_int_type *")
111
-  assert(cdecl.declare(decl, function(node)
116
+  end), "ptr_to_const_int_type *")
117
+  assert_equal(cdecl.declare(decl, function(node)
112 118
     return node:name():value()
113
-  end) == "ptr_to_const_int_type *ptr_to_ptr_to_const_int")
119
+  end), "ptr_to_const_int_type *ptr_to_ptr_to_const_int")
114 120
 end
115 121
 
116 122
 function test.ptr_to_const_restrict_ptr_to_const_int(decl)
117
-  assert(cdecl.declare(decl:type():type():name()) == "typedef const int *ptr_to_const_int_type")
118
-  assert(cdecl.declare(decl:type():type()) == "const int *const restrict")
119
-  assert(cdecl.declare(decl:type()) == "const int *const restrict *")
120
-  assert(cdecl.declare(decl) == "const int *const restrict *ptr_to_const_restrict_ptr_to_const_int")
121
-  assert(cdecl.declare(decl:type():type():name(), function(node)
123
+  assert_equal(cdecl.declare(decl:type():type():name()), "typedef const int *ptr_to_const_int_type")
124
+  assert_equal(cdecl.declare(decl:type():type()), "const int *const restrict")
125
+  assert_equal(cdecl.declare(decl:type()), "const int *const restrict *")
126
+  assert_equal(cdecl.declare(decl), "const int *const restrict *ptr_to_const_restrict_ptr_to_const_int")
127
+  assert_equal(cdecl.declare(decl:type():type():name(), function(node)
122 128
     return node:name():value()
123
-  end) == "typedef const int_type *ptr_to_const_int_type")
124
-  assert(cdecl.declare(decl:type():type(), function(node)
129
+  end), "typedef const int_type *ptr_to_const_int_type")
130
+  assert_equal(cdecl.declare(decl:type():type(), function(node)
125 131
     return node:name():value()
126
-  end) == "const restrict ptr_to_const_int_type")
127
-  assert(cdecl.declare(decl:type(), function(node)
132
+  end), "const restrict ptr_to_const_int_type")
133
+  assert_equal(cdecl.declare(decl:type(), function(node)
128 134
     return node:name():value()
129
-  end) == "const restrict ptr_to_const_int_type *")
130
-  assert(cdecl.declare(decl, function(node)
135
+  end), "const restrict ptr_to_const_int_type *")
136
+  assert_equal(cdecl.declare(decl, function(node)
131 137
     return node:name():value()
132
-  end) == "const restrict ptr_to_const_int_type *ptr_to_const_restrict_ptr_to_const_int")
138
+  end), "const restrict ptr_to_const_int_type *ptr_to_const_restrict_ptr_to_const_int")
133 139
 end
134 140
 
135 141
 function test.ptr_to_volatile_ptr_to_const_restrict_ptr_to_const_int(decl)
136
-  assert(cdecl.declare(decl:type():type():type():name()) == "typedef const int *ptr_to_const_int_type")
137
-  assert(cdecl.declare(decl:type():type():type()) == "const int *const restrict")
138
-  assert(cdecl.declare(decl:type():type():name()) == "typedef const int *const restrict *ptr_to_const_restrict_ptr_to_const_int_type")
139
-  assert(cdecl.declare(decl:type():type()) == "const int *const restrict *volatile")
140
-  assert(cdecl.declare(decl:type()) == "const int *const restrict *volatile *")
141
-  assert(cdecl.declare(decl) == "const int *const restrict *volatile *ptr_to_volatile_ptr_to_const_restrict_ptr_to_const_int")
142
-  assert(cdecl.declare(decl:type():type():type():name(), function(node)
142
+  assert_equal(cdecl.declare(decl:type():type():type():name()), "typedef const int *ptr_to_const_int_type")
143
+  assert_equal(cdecl.declare(decl:type():type():type()), "const int *const restrict")
144
+  assert_equal(cdecl.declare(decl:type():type():name()), "typedef const int *const restrict *ptr_to_const_restrict_ptr_to_const_int_type")
145
+  assert_equal(cdecl.declare(decl:type():type()), "const int *const restrict *volatile")
146
+  assert_equal(cdecl.declare(decl:type()), "const int *const restrict *volatile *")
147
+  assert_equal(cdecl.declare(decl), "const int *const restrict *volatile *ptr_to_volatile_ptr_to_const_restrict_ptr_to_const_int")
148
+  assert_equal(cdecl.declare(decl:type():type():type():name(), function(node)
143 149
     return node:name():value()
144
-  end) == "typedef const int_type *ptr_to_const_int_type")
145
-  assert(cdecl.declare(decl:type():type():type(), function(node)
150
+  end), "typedef const int_type *ptr_to_const_int_type")
151
+  assert_equal(cdecl.declare(decl:type():type():type(), function(node)
146 152
     return node:name():value()
147
-  end) == "const restrict ptr_to_const_int_type")
148
-  assert(cdecl.declare(decl:type():type():name(), function(node)
153
+  end), "const restrict ptr_to_const_int_type")
154
+  assert_equal(cdecl.declare(decl:type():type():name(), function(node)
149 155
     return node:name():value()
150
-  end) == "typedef const restrict ptr_to_const_int_type *ptr_to_const_restrict_ptr_to_const_int_type")
151
-  assert(cdecl.declare(decl:type():type(), function(node)
156
+  end), "typedef const restrict ptr_to_const_int_type *ptr_to_const_restrict_ptr_to_const_int_type")
157
+  assert_equal(cdecl.declare(decl:type():type(), function(node)
152 158
     return node:name():value()
153
-  end) == "volatile ptr_to_const_restrict_ptr_to_const_int_type")
154
-  assert(cdecl.declare(decl:type(), function(node)
159
+  end), "volatile ptr_to_const_restrict_ptr_to_const_int_type")
160
+  assert_equal(cdecl.declare(decl:type(), function(node)
155 161
     return node:name():value()
156
-  end) == "volatile ptr_to_const_restrict_ptr_to_const_int_type *")
157
-  assert(cdecl.declare(decl, function(node)
162
+  end), "volatile ptr_to_const_restrict_ptr_to_const_int_type *")
163
+  assert_equal(cdecl.declare(decl, function(node)
158 164
     return node:name():value()
159
-  end) == "volatile ptr_to_const_restrict_ptr_to_const_int_type *ptr_to_volatile_ptr_to_const_restrict_ptr_to_const_int")
165
+  end), "volatile ptr_to_const_restrict_ptr_to_const_int_type *ptr_to_volatile_ptr_to_const_restrict_ptr_to_const_int")
160 166
 end

+ 94
- 88
gcc-lua-cdecl/test/scalar.lua View File

@@ -4,8 +4,14 @@
4 4
 -- Distributed under the MIT license. (See accompanying file LICENSE.)
5 5
 --
6 6
 
7
+package.path = "../?.lua;" .. package.path
8
+
7 9
 local gcc   = require("gcc")
8 10
 local cdecl = require("gcc.cdecl")
11
+local test  = require("test")
12
+
13
+-- Cache library functions.
14
+local assert_equal = test.assert_equal
9 15
 
10 16
 gcc.set_asm_file_name(gcc.HOST_BIT_BUCKET)
11 17
 
@@ -22,162 +28,162 @@ end)
22 28
 
23 29
 -- scalar type
24 30
 function test.int_scalar(decl)
25
-  assert(cdecl.declare(decl:type()) == "int")
26
-  assert(cdecl.declare(decl) == "int int_scalar")
31
+  assert_equal(cdecl.declare(decl:type()), "int")
32
+  assert_equal(cdecl.declare(decl), "int int_scalar")
27 33
 end
28 34
 
29 35
 function test.const_int_scalar(decl)
30
-  assert(cdecl.declare(decl:type()) == "const int")
31
-  assert(cdecl.declare(decl) == "const int const_int_scalar")
36
+  assert_equal(cdecl.declare(decl:type()), "const int")
37
+  assert_equal(cdecl.declare(decl), "const int const_int_scalar")
32 38
 end
33 39
 
34 40
 function test.volatile_int_scalar(decl)
35
-  assert(cdecl.declare(decl:type()) == "volatile int")
36
-  assert(cdecl.declare(decl) == "volatile int volatile_int_scalar")
41
+  assert_equal(cdecl.declare(decl:type()), "volatile int")
42
+  assert_equal(cdecl.declare(decl), "volatile int volatile_int_scalar")
37 43
 end
38 44
 
39 45
 function test.const_volatile_int_scalar(decl)
40
-  assert(cdecl.declare(decl:type()) == "const volatile int")
41
-  assert(cdecl.declare(decl) == "const volatile int const_volatile_int_scalar")
46
+  assert_equal(cdecl.declare(decl:type()), "const volatile int")
47
+  assert_equal(cdecl.declare(decl), "const volatile int const_volatile_int_scalar")
42 48
 end
43 49
 
44 50
 function test.short_scalar(decl)
45
-  assert(cdecl.declare(decl:type()) == "short int")
46
-  assert(cdecl.declare(decl) == "short int short_scalar")
51
+  assert_equal(cdecl.declare(decl:type()), "short int")
52
+  assert_equal(cdecl.declare(decl), "short int short_scalar")
47 53
 end
48 54
 
49 55
 function test.const_short_scalar(decl)
50
-  assert(cdecl.declare(decl:type()) == "const short int")
51
-  assert(cdecl.declare(decl) == "const short int const_short_scalar")
56
+  assert_equal(cdecl.declare(decl:type()), "const short int")
57
+  assert_equal(cdecl.declare(decl), "const short int const_short_scalar")
52 58
 end
53 59
 
54 60
 function test.volatile_short_scalar(decl)
55
-  assert(cdecl.declare(decl:type()) == "volatile short int")
56
-  assert(cdecl.declare(decl) == "volatile short int volatile_short_scalar")
61
+  assert_equal(cdecl.declare(decl:type()), "volatile short int")
62
+  assert_equal(cdecl.declare(decl), "volatile short int volatile_short_scalar")
57 63
 end
58 64
 
59 65
 function test.const_volatile_short_scalar(decl)
60
-  assert(cdecl.declare(decl:type()) == "const volatile short int")
61
-  assert(cdecl.declare(decl) == "const volatile short int const_volatile_short_scalar")
66
+  assert_equal(cdecl.declare(decl:type()), "const volatile short int")
67
+  assert_equal(cdecl.declare(decl), "const volatile short int const_volatile_short_scalar")
62 68
 end
63 69
 
64 70
 -- scalar type declaration
65 71
 function test.int_type_scalar(decl)
66
-  assert(cdecl.declare(decl:type():name()) == "typedef int int_type")
67
-  assert(cdecl.declare(decl:type()) == "int")
68
-  assert(cdecl.declare(decl) == "int int_type_scalar")
69
-  assert(cdecl.declare(decl:type():name(), function(node)
72
+  assert_equal(cdecl.declare(decl:type():name()), "typedef int int_type")
73
+  assert_equal(cdecl.declare(decl:type()), "int")
74
+  assert_equal(cdecl.declare(decl), "int int_type_scalar")
75
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
70 76
     return node:name():value()
71
-  end) == "typedef int int_type")
72
-  assert(cdecl.declare(decl:type(), function(node)
77
+  end), "typedef int int_type")
78
+  assert_equal(cdecl.declare(decl:type(), function(node)
73 79
     return node:name():value()
74
-  end) == "int_type")
75
-  assert(cdecl.declare(decl, function(node)
80
+  end), "int_type")
81
+  assert_equal(cdecl.declare(decl, function(node)
76 82
     return node:name():value()
77
-  end) == "int_type int_type_scalar")
83
+  end), "int_type int_type_scalar")
78 84
 end
79 85
 
80 86
 function test.const_int_type_scalar(decl)
81
-  assert(cdecl.declare(decl:type():name()) == "typedef int int_type")
82
-  assert(cdecl.declare(decl:type()) == "const int")
83
-  assert(cdecl.declare(decl) == "const int const_int_type_scalar")
84
-  assert(cdecl.declare(decl:type():name(), function(node)
87
+  assert_equal(cdecl.declare(decl:type():name()), "typedef int int_type")
88
+  assert_equal(cdecl.declare(decl:type()), "const int")
89
+  assert_equal(cdecl.declare(decl), "const int const_int_type_scalar")
90
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
85 91
     return node:name():value()
86
-  end) == "typedef int int_type")
87
-  assert(cdecl.declare(decl:type(), function(node)
92
+  end), "typedef int int_type")
93
+  assert_equal(cdecl.declare(decl:type(), function(node)
88 94
     return node:name():value()
89
-  end) == "const int_type")
90
-  assert(cdecl.declare(decl, function(node)
95
+  end), "const int_type")
96
+  assert_equal(cdecl.declare(decl, function(node)
91 97
     return node:name():value()
92
-  end) == "const int_type const_int_type_scalar")
98
+  end), "const int_type const_int_type_scalar")
93 99
 end
94 100
 
95 101
 function test.volatile_int_type_scalar(decl)
96
-  assert(cdecl.declare(decl:type():name()) == "typedef int int_type")
97
-  assert(cdecl.declare(decl:type()) == "volatile int")
98
-  assert(cdecl.declare(decl) == "volatile int volatile_int_type_scalar")
99
-  assert(cdecl.declare(decl:type():name(), function(node)
102
+  assert_equal(cdecl.declare(decl:type():name()), "typedef int int_type")
103
+  assert_equal(cdecl.declare(decl:type()), "volatile int")
104
+  assert_equal(cdecl.declare(decl), "volatile int volatile_int_type_scalar")
105
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
100 106
     return node:name():value()
101
-  end) == "typedef int int_type")
102
-  assert(cdecl.declare(decl:type(), function(node)
107
+  end), "typedef int int_type")
108
+  assert_equal(cdecl.declare(decl:type(), function(node)
103 109
     return node:name():value()
104
-  end) == "volatile int_type")
105
-  assert(cdecl.declare(decl, function(node)
110
+  end), "volatile int_type")
111
+  assert_equal(cdecl.declare(decl, function(node)
106 112
     return node:name():value()
107
-  end) == "volatile int_type volatile_int_type_scalar")
113
+  end), "volatile int_type volatile_int_type_scalar")
108 114
 end
109 115
 
110 116
 function test.volatile_const_int_type_scalar(decl)
111
-  assert(cdecl.declare(decl:type():name()) == "typedef int int_type")
112
-  assert(cdecl.declare(decl:type()) == "const volatile int")
113
-  assert(cdecl.declare(decl) == "const volatile int volatile_const_int_type_scalar")
114
-  assert(cdecl.declare(decl:type():name(), function(node)
117
+  assert_equal(cdecl.declare(decl:type():name()), "typedef int int_type")
118
+  assert_equal(cdecl.declare(decl:type()), "const volatile int")
119
+  assert_equal(cdecl.declare(decl), "const volatile int volatile_const_int_type_scalar")
120
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
115 121
     return node:name():value()
116
-  end) == "typedef int int_type")
117
-  assert(cdecl.declare(decl:type(), function(node)
122
+  end), "typedef int int_type")
123
+  assert_equal(cdecl.declare(decl:type(), function(node)
118 124
     return node:name():value()
119
-  end) == "const volatile int_type")
120
-  assert(cdecl.declare(decl, function(node)
125
+  end), "const volatile int_type")
126
+  assert_equal(cdecl.declare(decl, function(node)
121 127
     return node:name():value()
122
-  end) == "const volatile int_type volatile_const_int_type_scalar")
128
+  end), "const volatile int_type volatile_const_int_type_scalar")
123 129
 end
124 130
 
125 131
 function test.unsigned_long_type_scalar(decl)
126
-  assert(cdecl.declare(decl:type():name()) == "typedef long unsigned int unsigned_long_type")
127
-  assert(cdecl.declare(decl:type()) == "long unsigned int")
128
-  assert(cdecl.declare(decl) == "long unsigned int unsigned_long_type_scalar")
129
-  assert(cdecl.declare(decl:type():name(), function(node)
132
+  assert_equal(cdecl.declare(decl:type():name()), "typedef long unsigned int unsigned_long_type")
133
+  assert_equal(cdecl.declare(decl:type()), "long unsigned int")
134
+  assert_equal(cdecl.declare(decl), "long unsigned int unsigned_long_type_scalar")
135
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
130 136
     return node:name():value()
131
-  end) == "typedef long unsigned int unsigned_long_type")
132
-  assert(cdecl.declare(decl:type(), function(node)
137
+  end), "typedef long unsigned int unsigned_long_type")
138
+  assert_equal(cdecl.declare(decl:type(), function(node)
133 139
     return node:name():value()
134
-  end) == "unsigned_long_type")
135
-  assert(cdecl.declare(decl, function(node)
140
+  end), "unsigned_long_type")
141
+  assert_equal(cdecl.declare(decl, function(node)
136 142
     return node:name():value()
137
-  end) == "unsigned_long_type unsigned_long_type_scalar")
143
+  end), "unsigned_long_type unsigned_long_type_scalar")
138 144
 end
139 145
 
140 146
 function test.const_unsigned_long_type_scalar(decl)
141
-  assert(cdecl.declare(decl:type():name()) == "typedef long unsigned int unsigned_long_type")
142
-  assert(cdecl.declare(decl:type()) == "const long unsigned int")
143
-  assert(cdecl.declare(decl) == "const long unsigned int const_unsigned_long_type_scalar")
144
-  assert(cdecl.declare(decl:type():name(), function(node)
147
+  assert_equal(cdecl.declare(decl:type():name()), "typedef long unsigned int unsigned_long_type")
148
+  assert_equal(cdecl.declare(decl:type()), "const long unsigned int")
149
+  assert_equal(cdecl.declare(decl), "const long unsigned int const_unsigned_long_type_scalar")
150
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
145 151
     return node:name():value()
146
-  end) == "typedef long unsigned int unsigned_long_type")
147
-  assert(cdecl.declare(decl:type(), function(node)
152
+  end), "typedef long unsigned int unsigned_long_type")
153
+  assert_equal(cdecl.declare(decl:type(), function(node)
148 154
     return node:name():value()
149
-  end) == "const unsigned_long_type")
150
-  assert(cdecl.declare(decl, function(node)
155
+  end), "const unsigned_long_type")
156
+  assert_equal(cdecl.declare(decl, function(node)
151 157
     return node:name():value()
152
-  end) == "const unsigned_long_type const_unsigned_long_type_scalar")
158
+  end), "const unsigned_long_type const_unsigned_long_type_scalar")
153 159
 end
154 160
 
155 161
 function test.volatile_unsigned_long_type_scalar(decl)
156
-  assert(cdecl.declare(decl:type():name()) == "typedef long unsigned int unsigned_long_type")
157
-  assert(cdecl.declare(decl:type()) == "volatile long unsigned int")
158
-  assert(cdecl.declare(decl) == "volatile long unsigned int volatile_unsigned_long_type_scalar")
159
-  assert(cdecl.declare(decl:type():name(), function(node)
162
+  assert_equal(cdecl.declare(decl:type():name()), "typedef long unsigned int unsigned_long_type")
163
+  assert_equal(cdecl.declare(decl:type()), "volatile long unsigned int")
164
+  assert_equal(cdecl.declare(decl), "volatile long unsigned int volatile_unsigned_long_type_scalar")
165
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
160 166
     return node:name():value()
161
-  end) == "typedef long unsigned int unsigned_long_type")
162
-  assert(cdecl.declare(decl:type(), function(node)
167
+  end), "typedef long unsigned int unsigned_long_type")
168
+  assert_equal(cdecl.declare(decl:type(), function(node)
163 169
     return node:name():value()
164
-  end) == "volatile unsigned_long_type")
165
-  assert(cdecl.declare(decl, function(node)
170
+  end), "volatile unsigned_long_type")
171
+  assert_equal(cdecl.declare(decl, function(node)
166 172
     return node:name():value()
167
-  end) == "volatile unsigned_long_type volatile_unsigned_long_type_scalar")
173
+  end), "volatile unsigned_long_type volatile_unsigned_long_type_scalar")
168 174
 end
169 175
 
170 176
 function test.volatile_const_unsigned_long_type_scalar(decl)
171
-  assert(cdecl.declare(decl:type():name()) == "typedef long unsigned int unsigned_long_type")
172
-  assert(cdecl.declare(decl:type()) == "const volatile long unsigned int")
173
-  assert(cdecl.declare(decl) == "const volatile long unsigned int volatile_const_unsigned_long_type_scalar")
174
-  assert(cdecl.declare(decl:type():name(), function(node)
177
+  assert_equal(cdecl.declare(decl:type():name()), "typedef long unsigned int unsigned_long_type")
178
+  assert_equal(cdecl.declare(decl:type()), "const volatile long unsigned int")
179
+  assert_equal(cdecl.declare(decl), "const volatile long unsigned int volatile_const_unsigned_long_type_scalar")
180
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
175 181
     return node:name():value()
176
-  end) == "typedef long unsigned int unsigned_long_type")
177
-  assert(cdecl.declare(decl:type(), function(node)
182
+  end), "typedef long unsigned int unsigned_long_type")
183
+  assert_equal(cdecl.declare(decl:type(), function(node)
178 184
     return node:name():value()
179
-  end) == "const volatile unsigned_long_type")
180
-  assert(cdecl.declare(decl, function(node)
185
+  end), "const volatile unsigned_long_type")
186
+  assert_equal(cdecl.declare(decl, function(node)
181 187
     return node:name():value()
182
-  end) == "const volatile unsigned_long_type volatile_const_unsigned_long_type_scalar")
188
+  end), "const volatile unsigned_long_type volatile_const_unsigned_long_type_scalar")
183 189
 end

+ 17
- 0
gcc-lua-cdecl/test/test.lua View File

@@ -0,0 +1,17 @@
1
+--
2
+-- Testing tools.
3
+-- Copyright © 2013–2015 Peter Colberg.
4
+-- Distributed under the MIT license. (See accompanying file LICENSE.)
5
+--
6
+
7
+local _M = {}
8
+
9
+-- Raises an error unless the given values compare equal.
10
+function _M.assert_equal(a, b)
11
+  if a == b then return end
12
+  if type(a) == "string" then a = ("%q"):format(a) end
13
+  if type(b) == "string" then b = ("%q"):format(b) end
14
+  error(("assertion failed [%s != %s]"):format(a, b), 2)
15
+end
16
+
17
+return _M

+ 13
- 7
gcc-lua-cdecl/test/variable.lua View File

@@ -4,8 +4,14 @@
4 4
 -- Distributed under the MIT license. (See accompanying file LICENSE.)
5 5
 --
6 6
 
7
+package.path = "../?.lua;" .. package.path
8
+
7 9
 local gcc   = require("gcc")
8 10
 local cdecl = require("gcc.cdecl")
11
+local test  = require("test")
12
+
13
+-- Cache library functions.
14
+local assert_equal = test.assert_equal
9 15
 
10 16
 gcc.set_asm_file_name(gcc.HOST_BIT_BUCKET)
11 17
 
@@ -22,20 +28,20 @@ end)
22 28
 
23 29
 -- GCC C extension: variable declaration attributes
24 30
 function test.ptr_to_extern_aligned_volatile_short(decl)
25
-  assert(cdecl.declare(decl) == "volatile short int *ptr_to_extern_aligned_volatile_short")
26
-  assert(cdecl.declare(decl, function(node)
31
+  assert_equal(cdecl.declare(decl), "volatile short int *ptr_to_extern_aligned_volatile_short")
32
+  assert_equal(cdecl.declare(decl, function(node)
27 33
     if node == decl then
28 34
       return "pointer_to_extern_aligned_volatile_short"
29 35
     end
30
-  end) == [[volatile short int *pointer_to_extern_aligned_volatile_short __asm__("ptr_to_extern_aligned_volatile_short")]])
31
-  assert(cdecl.declare(decl:initial():operand()) == "extern volatile short int extern_aligned_volatile_short __attribute__((weak, aligned(32)))")
32
-  assert(cdecl.declare(decl:initial():operand(), function(node)
36
+  end), [[volatile short int *pointer_to_extern_aligned_volatile_short __asm__("ptr_to_extern_aligned_volatile_short")]])
37
+  assert_equal(cdecl.declare(decl:initial():operand()), "extern volatile short int extern_aligned_volatile_short __attribute__((weak, aligned(32)))")
38
+  assert_equal(cdecl.declare(decl:initial():operand(), function(node)
33 39
     if node == decl:initial():operand() then
34 40
       return "extern_aligned_volatile_short_int"
35 41
     end
36
-  end) == [[extern volatile short int extern_aligned_volatile_short_int __asm__("extern_aligned_volatile_short") __attribute__((weak, aligned(32)))]])
42
+  end), [[extern volatile short int extern_aligned_volatile_short_int __asm__("extern_aligned_volatile_short") __attribute__((weak, aligned(32)))]])
37 43
 end
38 44
 
39 45
 function test.extern_aligned_volatile_short(decl)
40
-  assert(cdecl.declare(decl) == "extern volatile short int extern_aligned_volatile_short __attribute__((weak, aligned(32)))")
46
+  assert_equal(cdecl.declare(decl), "extern volatile short int extern_aligned_volatile_short __attribute__((weak, aligned(32)))")
41 47
 end

+ 28
- 22
gcc-lua-cdecl/test/vector.lua View File

@@ -4,8 +4,14 @@
4 4
 -- Distributed under the MIT license. (See accompanying file LICENSE.)
5 5
 --
6 6
 
7
+package.path = "../?.lua;" .. package.path
8
+
7 9
 local gcc   = require("gcc")
8 10
 local cdecl = require("gcc.cdecl")
11
+local test  = require("test")
12
+
13
+-- Cache library functions.
14
+local assert_equal = test.assert_equal
9 15
 
10 16
 gcc.set_asm_file_name(gcc.HOST_BIT_BUCKET)
11 17
 
@@ -22,42 +28,42 @@ end)
22 28
 
23 29
 -- vector type
24 30
 function test.int2_vector(decl)
25
-  assert(cdecl.declare(decl:type()) == "int __attribute__((vector_size(8)))")
26
-  assert(cdecl.declare(decl) == "int __attribute__((vector_size(8))) int2_vector")
31
+  assert_equal(cdecl.declare(decl:type()), "int __attribute__((vector_size(8)))")
32
+  assert_equal(cdecl.declare(decl), "int __attribute__((vector_size(8))) int2_vector")
27 33
 end
28 34
 
29 35
 function test.double4_vector(decl)
30
-  assert(cdecl.declare(decl:type()) == "double __attribute__((vector_size(32)))")
31
-  assert(cdecl.declare(decl) == "double __attribute__((vector_size(32))) double4_vector")
36
+  assert_equal(cdecl.declare(decl:type()), "double __attribute__((vector_size(32)))")
37
+  assert_equal(cdecl.declare(decl), "double __attribute__((vector_size(32))) double4_vector")
32 38
 end
33 39
 
34 40
 -- vector type declaration
35 41
 function test.const_int2_type_vector(decl)
36
-  assert(cdecl.declare(decl:type():name()) == "typedef int __attribute__((vector_size(8))) int2_type")
37
-  assert(cdecl.declare(decl:type()) == "const int __attribute__((vector_size(8)))")
38
-  assert(cdecl.declare(decl) == "const int __attribute__((vector_size(8))) const_int2_type_vector")
39
-  assert(cdecl.declare(decl:type():name(), function(node)
42
+  assert_equal(cdecl.declare(decl:type():name()), "typedef int __attribute__((vector_size(8))) int2_type")
43
+  assert_equal(cdecl.declare(decl:type()), "const int __attribute__((vector_size(8)))")
44
+  assert_equal(cdecl.declare(decl), "const int __attribute__((vector_size(8))) const_int2_type_vector")
45
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
40 46
     return node:name():value()
41
-  end) == "typedef int __attribute__((vector_size(8))) int2_type")
42
-  assert(cdecl.declare(decl:type(), function(node)
47
+  end), "typedef int __attribute__((vector_size(8))) int2_type")
48
+  assert_equal(cdecl.declare(decl:type(), function(node)
43 49
     return node:name():value()
44
-  end) == "const int2_type")
45
-  assert(cdecl.declare(decl, function(node)
50
+  end), "const int2_type")
51
+  assert_equal(cdecl.declare(decl, function(node)
46 52
     return node:name():value()
47
-  end) == "const int2_type const_int2_type_vector")
53
+  end), "const int2_type const_int2_type_vector")
48 54
 end
49 55
 
50 56
 function test.const_volatile_unsigned_short8_type_vector(decl)
51
-  assert(cdecl.declare(decl:type():name()) == "typedef short unsigned int __attribute__((vector_size(16))) unsigned_short8_type")
52
-  assert(cdecl.declare(decl:type()) == "const volatile short unsigned int __attribute__((vector_size(16)))")
53
-  assert(cdecl.declare(decl) == "const volatile short unsigned int __attribute__((vector_size(16))) const_volatile_unsigned_short8_type_vector")
54
-  assert(cdecl.declare(decl:type():name(), function(node)
57
+  assert_equal(cdecl.declare(decl:type():name()), "typedef short unsigned int __attribute__((vector_size(16))) unsigned_short8_type")
58
+  assert_equal(cdecl.declare(decl:type()), "const volatile short unsigned int __attribute__((vector_size(16)))")
59
+  assert_equal(cdecl.declare(decl), "const volatile short unsigned int __attribute__((vector_size(16))) const_volatile_unsigned_short8_type_vector")
60
+  assert_equal(cdecl.declare(decl:type():name(), function(node)
55 61
     return node:name():value()
56
-  end) == "typedef short unsigned int __attribute__((vector_size(16))) unsigned_short8_type")
57
-  assert(cdecl.declare(decl:type(), function(node)
62
+  end), "typedef short unsigned int __attribute__((vector_size(16))) unsigned_short8_type")
63
+  assert_equal(cdecl.declare(decl:type(), function(node)
58 64
     return node:name():value()
59
-  end) == "const volatile unsigned_short8_type")
60
-  assert(cdecl.declare(decl, function(node)
65
+  end), "const volatile unsigned_short8_type")
66
+  assert_equal(cdecl.declare(decl, function(node)
61 67
     return node:name():value()
62
-  end) == "const volatile unsigned_short8_type const_volatile_unsigned_short8_type_vector")
68
+  end), "const volatile unsigned_short8_type const_volatile_unsigned_short8_type_vector")
63 69
 end

Loading…
Cancel
Save