@@ -18,7 +18,6 @@ main: (args) -> int = {
18
18
"Expected at least (min_args)$ arguments. Received (args.ssize()-1)$\n",
19
19
);
20
20
21
- // this_exe_path := fs::path(args[0]).canonical();
22
21
ctx: testing_context = (
23
22
args[1],
24
23
fs::path(args[2]).canonical(),
@@ -30,15 +29,6 @@ main: (args) -> int = {
30
29
_ = ctx.unformatted_compiler_args.emplace_back(args[i]);
31
30
}
32
31
33
- // TODO: Remove this and all other debug prints (grep std::cout)
34
- std::cout << "ctx.target: (ctx.target)$\n";
35
- std::cout << "ctx.cppfront: (ctx.cppfront.string())$\n";
36
- std::cout << "path_to_test: (path_to_test.string())$\n";
37
- std::cout << "ctx.compiler: (ctx.compiler.string())$\n";
38
- std::cout << "ctx.include_dir: (ctx.include_dir.string())$\n";
39
- std::cout << "ctx.unformatted_compiler_args: (ctx.unformatted_compiler_args)$\n";
40
- std::cout << '\n';
41
-
42
32
assert(
43
33
ctx.cppfront.is_regular_file(),
44
34
"Path to cppfront executable must be a regular file\n",
@@ -47,14 +37,18 @@ main: (args) -> int = {
47
37
ext :== ".cpp2";
48
38
49
39
exit_status := EXIT_SUCCESS;
40
+ process_test_result := :(test_full_path: fs::path, result: test_result) = {
41
+ std::cout << "(test_full_path.filename().string())$: (result)$\n";
42
+ if !result.is_ok() { exit_status&$* = EXIT_FAILURE; }
43
+ };
44
+
50
45
if !path_to_test.is_directory() {
51
46
assert(
52
47
path_to_test.extension() == ext,
53
48
"For one-shot testing, the path must point to a (ext)$ file\n",
54
49
);
55
50
tr := test_one(ctx, path_to_test);
56
- std::cout << "(path_to_test.filename())$: (tr.to_string())$\n";
57
- if tr != test_result::ok { exit_status = EXIT_FAILURE; }
51
+ process_test_result(path_to_test, tr);
58
52
} else {
59
53
results: std::vector<std::pair<fs::path, std::future<test_result>>> = ();
60
54
// Collect all tests...
@@ -68,15 +62,14 @@ main: (args) -> int = {
68
62
results.end(),
69
63
: (lhs, rhs) -> _ = lhs.first.filename() < rhs.first.filename(),
70
64
);
71
- // Launch each test
65
+ // Launch them all (you better have a good scheduler!)
72
66
for results do (inout r) {
73
67
r.second = std::async(test_one, ctx, r.first);
74
68
}
75
- // Collect and display the results
69
+ // Wait each task and display its result
76
70
for results do (inout r) {
77
71
tr := r.second.get();
78
- std::cout << "(r.first.filename().string())$: (tr.to_string())$\n";
79
- if tr != test_result::ok { exit_status = EXIT_FAILURE; }
72
+ process_test_result(r.first, tr);
80
73
}
81
74
}
82
75
@@ -92,18 +85,17 @@ testing_context: @struct type = {
92
85
// override_files: bool; // TODO
93
86
}
94
87
95
- test_result: @enum type = {
96
- fail_unknown;
88
+ test_result: @flag_enum type = {
97
89
first_run;
98
90
lowered_output_mismatch;
99
91
cppfront_output_mismatch;
100
92
compiler_output_mismatch;
101
- compiler_output_exists_when_it_shouldnt;
93
+ compiler_output_exists_when_it_shouldnt; // or viceversa
102
94
test_exe_output_mismatch;
103
- test_exe_output_exists_when_it_shouldnt;
104
- ok;
95
+ test_exe_output_exists_when_it_shouldnt; // or viceversa
105
96
106
- is_first_run: (this) -> bool = this == first_run;
97
+ is_ok: (this) -> bool == this == none;
98
+ is_first_run: (this) -> bool == has(first_run);
107
99
}
108
100
109
101
test_one: (
@@ -139,9 +131,7 @@ test_one: (
139
131
executable_filepath := compile(ctx, ins, source_fn);
140
132
if executable_filepath.empty() { return ins.result; }
141
133
142
- if execute(ins, executable_filepath) && !ins.result.is_first_run() {
143
- ins.result = test_result::ok;
144
- }
134
+ execute(ins, executable_filepath);
145
135
146
136
return ins.result;
147
137
}
@@ -175,32 +165,23 @@ transpile: (ctx: testing_context, inout ins: testing_instance) -> fs::path = {
175
165
176
166
(: std::ofstream = (cppfront_output_filepath)) << launch_result.output;
177
167
178
- if ins.result.is_first_run() {
179
- if lowered_output_filepath.exists() {
180
- return lowered_output_filepath.filename();
181
- } else {
182
- return ();
183
- }
184
- }
185
-
186
- assert(ins.output_dir* != ins.result_dir);
168
+ if !ins.result.is_first_run() {
169
+ assert(ins.output_dir* != ins.result_dir);
187
170
188
- if (ins.result_dir / lowered_output_fn).read_file() !=
189
- lowered_output_filepath.read_file() {
190
- ins.result = test_result::lowered_output_mismatch;
191
- return ();
192
- }
171
+ if (ins.result_dir / lowered_output_fn).read_file() !=
172
+ lowered_output_filepath.read_file() {
173
+ ins.result |= test_result::lowered_output_mismatch;
174
+ }
193
175
194
- if (ins.result_dir / cppfront_output_fn).read_file() !=
195
- cppfront_output_filepath.read_file() {
196
- ins.result = test_result::cppfront_output_mismatch;
197
- return ();
176
+ if (ins.result_dir / cppfront_output_fn).read_file() !=
177
+ cppfront_output_filepath.read_file() {
178
+ ins.result | = test_result::cppfront_output_mismatch;
179
+ }
198
180
}
199
181
200
182
if lowered_output_filepath.exists() {
201
- return lowered_output_filepath.filename() ;
183
+ return lowered_output_fn ;
202
184
} else {
203
- if !ins.result.is_first_run() { ins.result = test_result::ok; }
204
185
return ();
205
186
}
206
187
}
@@ -214,6 +195,7 @@ compile: (
214
195
215
196
// NOTE: We always want this to be run with result's path so compiler
216
197
// error output matches.
198
+ // TODO: Review since execution can continue with a wrong source file atm
217
199
source_file: const = ins.result_dir / source_fn;
218
200
219
201
compiler_args: std::vector<std::string> = ();
@@ -223,7 +205,6 @@ compile: (
223
205
arg*.replace_all("{include_dir}", ctx.include_dir.string());
224
206
arg*.replace_all("{exe_out}", compiler_exe_out_path.string());
225
207
}
226
- // std::cout << "compiler_args: (compiler_args)$\n";
227
208
228
209
launch_result := launch_program(
229
210
ins.work_dir,
@@ -238,41 +219,30 @@ compile: (
238
219
(: std::ofstream = (compiler_output_filepath)) << launch_result.output;
239
220
}
240
221
241
- if ins.result.is_first_run() {
242
- if compiler_exe_out_path.exists() {
243
- return compiler_exe_out_path;
244
- } else {
245
- return ();
246
- }
247
- }
248
-
249
- if !launch_result.output.empty() {
222
+ if !ins.result.is_first_run() {
250
223
assert(ins.output_dir* != ins.result_dir);
251
224
252
- if (ins.result_dir / compiler_output_fn).read_file() !=
253
- compiler_output_filepath.read_file() {
254
- ins.result = test_result::compiler_output_mismatch;
255
- return ();
256
- }
257
- } else {
258
- if compiler_output_filepath.exists() {
259
- ins.result = test_result::compiler_output_exists_when_it_shouldnt;
260
- return ();
225
+ if !launch_result.output.empty() {
226
+ if (ins.result_dir / compiler_output_fn).read_file() !=
227
+ compiler_output_filepath.read_file() {
228
+ ins.result |= test_result::compiler_output_mismatch;
229
+ }
230
+ } else if compiler_output_filepath.exists() {
231
+ ins.result |= test_result::compiler_output_exists_when_it_shouldnt;
261
232
}
262
233
}
263
234
264
235
if compiler_exe_out_path.exists() {
265
236
return compiler_exe_out_path;
266
237
} else {
267
- if !ins.result.is_first_run() { ins.result = test_result::ok; }
268
238
return ();
269
239
}
270
240
}
271
241
272
242
execute: (
273
243
inout ins: testing_instance,
274
244
executable_filepath: fs::path,
275
- ) -> bool = {
245
+ ) = {
276
246
test_exe_output_fn :== "03-executable.output";
277
247
test_exe_output_filepath: const = ins.output_dir* / test_exe_output_fn;
278
248
@@ -286,24 +256,18 @@ execute: (
286
256
(: std::ofstream = (test_exe_output_filepath)) << cmd_result.output;
287
257
}
288
258
289
- if ins.result.is_first_run() { return true; }
290
-
291
- if !cmd_result.output.empty() {
259
+ if !ins.result.is_first_run() {
292
260
assert(ins.output_dir* != ins.result_dir);
293
261
294
- if (ins.result_dir / test_exe_output_fn).read_file() !=
295
- test_exe_output_filepath.read_file() {
296
- ins.result = test_result::test_exe_output_mismatch;
297
- return false;
298
- }
299
- } else {
300
- if test_exe_output_filepath.exists() {
301
- ins.result = test_result::test_exe_output_exists_when_it_shouldnt;
302
- return false;
262
+ if !cmd_result.output.empty() {
263
+ if (ins.result_dir / test_exe_output_fn).read_file() !=
264
+ test_exe_output_filepath.read_file() {
265
+ ins.result |= test_result::test_exe_output_mismatch;
266
+ }
267
+ } else if test_exe_output_filepath.exists() {
268
+ ins.result |= test_result::test_exe_output_exists_when_it_shouldnt;
303
269
}
304
270
}
305
-
306
- return true;
307
271
}
308
272
309
273
replace_all: (
@@ -326,25 +290,3 @@ read_file: (fp: fs::path) -> std::string = {
326
290
while f.read(bd, b.size()) { _ = out.append(bd, 0, f.gcount()); }
327
291
return out;
328
292
}
329
-
330
- cpp2: namespace = { // TODO: remove later
331
-
332
- to_string: (p: fs::path) -> std::string = {
333
- return p.string();
334
- }
335
-
336
- to_string: (vsv: std::vector<std::string_view>) -> std::string = {
337
- ret: std::string = "size==(vsv.size())$ content=>(";
338
- for vsv do (sv) _ = ret.append(sv).append(", ");
339
- _ = ret.append(")");
340
- return ret;
341
- }
342
-
343
- to_string: (vs: std::vector<std::string>) -> std::string = {
344
- ret: std::string = "size==(vs.size())$ content=>(";
345
- for vs do (s) _ = ret.append(s).append(", ");
346
- _ = ret.append(")");
347
- return ret;
348
- }
349
-
350
- }
0 commit comments