@@ -18,7 +18,6 @@ main: (args) -> int = {
1818 "Expected at least (min_args)$ arguments. Received (args.ssize()-1)$\n",
1919 );
2020
21- // this_exe_path := fs::path(args[0]).canonical();
2221 ctx: testing_context = (
2322 args[1],
2423 fs::path(args[2]).canonical(),
@@ -30,15 +29,6 @@ main: (args) -> int = {
3029 _ = ctx.unformatted_compiler_args.emplace_back(args[i]);
3130 }
3231
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-
4232 assert(
4333 ctx.cppfront.is_regular_file(),
4434 "Path to cppfront executable must be a regular file\n",
@@ -47,14 +37,18 @@ main: (args) -> int = {
4737 ext :== ".cpp2";
4838
4939 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+
5045 if !path_to_test.is_directory() {
5146 assert(
5247 path_to_test.extension() == ext,
5348 "For one-shot testing, the path must point to a (ext)$ file\n",
5449 );
5550 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);
5852 } else {
5953 results: std::vector<std::pair<fs::path, std::future<test_result>>> = ();
6054 // Collect all tests...
@@ -68,15 +62,14 @@ main: (args) -> int = {
6862 results.end(),
6963 : (lhs, rhs) -> _ = lhs.first.filename() < rhs.first.filename(),
7064 );
71- // Launch each test
65+ // Launch them all (you better have a good scheduler!)
7266 for results do (inout r) {
7367 r.second = std::async(test_one, ctx, r.first);
7468 }
75- // Collect and display the results
69+ // Wait each task and display its result
7670 for results do (inout r) {
7771 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);
8073 }
8174 }
8275
@@ -92,18 +85,17 @@ testing_context: @struct type = {
9285 // override_files: bool; // TODO
9386}
9487
95- test_result: @enum type = {
96- fail_unknown;
88+ test_result: @flag_enum type = {
9789 first_run;
9890 lowered_output_mismatch;
9991 cppfront_output_mismatch;
10092 compiler_output_mismatch;
101- compiler_output_exists_when_it_shouldnt;
93+ compiler_output_exists_when_it_shouldnt; // or viceversa
10294 test_exe_output_mismatch;
103- test_exe_output_exists_when_it_shouldnt;
104- ok;
95+ test_exe_output_exists_when_it_shouldnt; // or viceversa
10596
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);
10799}
108100
109101test_one: (
@@ -139,9 +131,7 @@ test_one: (
139131 executable_filepath := compile(ctx, ins, source_fn);
140132 if executable_filepath.empty() { return ins.result; }
141133
142- if execute(ins, executable_filepath) && !ins.result.is_first_run() {
143- ins.result = test_result::ok;
144- }
134+ execute(ins, executable_filepath);
145135
146136 return ins.result;
147137}
@@ -175,32 +165,23 @@ transpile: (ctx: testing_context, inout ins: testing_instance) -> fs::path = {
175165
176166 (: std::ofstream = (cppfront_output_filepath)) << launch_result.output;
177167
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);
187170
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+ }
193175
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+ }
198180 }
199181
200182 if lowered_output_filepath.exists() {
201- return lowered_output_filepath.filename() ;
183+ return lowered_output_fn ;
202184 } else {
203- if !ins.result.is_first_run() { ins.result = test_result::ok; }
204185 return ();
205186 }
206187}
@@ -214,6 +195,7 @@ compile: (
214195
215196 // NOTE: We always want this to be run with result's path so compiler
216197 // error output matches.
198+ // TODO: Review since execution can continue with a wrong source file atm
217199 source_file: const = ins.result_dir / source_fn;
218200
219201 compiler_args: std::vector<std::string> = ();
@@ -223,7 +205,6 @@ compile: (
223205 arg*.replace_all("{include_dir}", ctx.include_dir.string());
224206 arg*.replace_all("{exe_out}", compiler_exe_out_path.string());
225207 }
226- // std::cout << "compiler_args: (compiler_args)$\n";
227208
228209 launch_result := launch_program(
229210 ins.work_dir,
@@ -238,41 +219,30 @@ compile: (
238219 (: std::ofstream = (compiler_output_filepath)) << launch_result.output;
239220 }
240221
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() {
250223 assert(ins.output_dir* != ins.result_dir);
251224
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;
261232 }
262233 }
263234
264235 if compiler_exe_out_path.exists() {
265236 return compiler_exe_out_path;
266237 } else {
267- if !ins.result.is_first_run() { ins.result = test_result::ok; }
268238 return ();
269239 }
270240}
271241
272242execute: (
273243 inout ins: testing_instance,
274244 executable_filepath: fs::path,
275- ) -> bool = {
245+ ) = {
276246 test_exe_output_fn :== "03-executable.output";
277247 test_exe_output_filepath: const = ins.output_dir* / test_exe_output_fn;
278248
@@ -286,24 +256,18 @@ execute: (
286256 (: std::ofstream = (test_exe_output_filepath)) << cmd_result.output;
287257 }
288258
289- if ins.result.is_first_run() { return true; }
290-
291- if !cmd_result.output.empty() {
259+ if !ins.result.is_first_run() {
292260 assert(ins.output_dir* != ins.result_dir);
293261
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;
303269 }
304270 }
305-
306- return true;
307271}
308272
309273replace_all: (
@@ -326,25 +290,3 @@ read_file: (fp: fs::path) -> std::string = {
326290 while f.read(bd, b.size()) { _ = out.append(bd, 0, f.gcount()); }
327291 return out;
328292}
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