Browse Source

Print values when equality assertion fails

Peter Colberg 2 years ago
parent
commit
d8e4a63184
9 changed files with 436 additions and 387 deletions
  1. 31
    27
      test/array.lua
  2. 56
    52
      test/composite.lua
  3. 49
    45
      test/enum.lua
  4. 66
    62
      test/function.lua
  5. 88
    84
      test/pointer.lua
  6. 92
    88
      test/scalar.lua
  7. 17
    0
      test/test.lua
  8. 11
    7
      test/variable.lua
  9. 26
    22
      test/vector.lua

+ 31
- 27
test/array.lua View File

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

+ 56
- 52
test/composite.lua View File

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

+ 49
- 45
test/enum.lua View File

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

+ 66
- 62
test/function.lua View File

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

+ 88
- 84
test/pointer.lua View File

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

+ 92
- 88
test/scalar.lua View File

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

+ 17
- 0
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

+ 11
- 7
test/variable.lua View File

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

+ 26
- 22
test/vector.lua View File

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

Loading…
Cancel
Save