| ... | ... | @@ -219,21 +219,30 @@ pub fn log( |
| 219 | 219 | /// Simpler main(), exercising fewer language features, so that |
| 220 | 220 | /// work-in-progress backends can handle it. |
| 221 | 221 | pub fn mainSimple() anyerror!void { |
| 222 | | const enable_print = true; |
| 223 | | const print_all = true; |
| 224 | | const print_summary = false; |
| 222 | // is the backend capable of printing to stderr? |
| 223 | const enable_print = switch (builtin.zig_backend) { |
| 224 | .stage2_riscv64 => true, |
| 225 | else => false, |
| 226 | }; |
| 227 | // is the backend capable of using std.fmt.format to print a summary at the end? |
| 228 | const print_summary = switch (builtin.zig_backend) { |
| 229 | else => false, |
| 230 | }; |
| 225 | 231 | |
| 226 | 232 | var passed: u64 = 0; |
| 227 | 233 | var skipped: u64 = 0; |
| 228 | 234 | var failed: u64 = 0; |
| 229 | | const stderr = if (enable_print) std.io.getStdErr() else {}; |
| 235 | |
| 236 | // we don't want to bring in File and Writer if the backend doesn't support it |
| 237 | const stderr = if (comptime enable_print) std.io.getStdErr() else {}; |
| 238 | |
| 230 | 239 | for (builtin.test_functions) |test_fn| { |
| 231 | | if (enable_print and print_all) { |
| 240 | if (enable_print) { |
| 232 | 241 | stderr.writeAll(test_fn.name) catch {}; |
| 233 | 242 | stderr.writeAll("... ") catch {}; |
| 234 | 243 | } |
| 235 | 244 | test_fn.func() catch |err| { |
| 236 | | if (enable_print and !print_all) { |
| 245 | if (enable_print) { |
| 237 | 246 | stderr.writeAll(test_fn.name) catch {}; |
| 238 | 247 | stderr.writeAll("... ") catch {}; |
| 239 | 248 | } |
| ... | ... | @@ -247,10 +256,10 @@ pub fn mainSimple() anyerror!void { |
| 247 | 256 | skipped += 1; |
| 248 | 257 | continue; |
| 249 | 258 | }; |
| 250 | | if (enable_print and print_all) stderr.writeAll("PASS\n") catch {}; |
| 259 | if (enable_print) stderr.writeAll("PASS\n") catch {}; |
| 251 | 260 | passed += 1; |
| 252 | 261 | } |
| 253 | | if (print_summary) { |
| 262 | if (enable_print and print_summary) { |
| 254 | 263 | stderr.writer().print("{} passed, {} skipped, {} failed\n", .{ passed, skipped, failed }) catch {}; |
| 255 | 264 | } |
| 256 | 265 | if (failed != 0) std.process.exit(1); |