| ... | @@ -219,21 +219,30 @@ pub fn log( | ... | @@ -219,21 +219,30 @@ pub fn log( |
| 219 | /// Simpler main(), exercising fewer language features, so that | 219 | /// Simpler main(), exercising fewer language features, so that |
| 220 | /// work-in-progress backends can handle it. | 220 | /// work-in-progress backends can handle it. |
| 221 | pub fn mainSimple() anyerror!void { | 221 | pub fn mainSimple() anyerror!void { |
| 222 | const enable_print = true; | 222 | // is the backend capable of printing to stderr? |
| 223 | const print_all = true; | 223 | const enable_print = switch (builtin.zig_backend) { |
| 224 | const print_summary = false; | 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 | var passed: u64 = 0; | 232 | var passed: u64 = 0; |
| 227 | var skipped: u64 = 0; | 233 | var skipped: u64 = 0; |
| 228 | var failed: u64 = 0; | 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 | for (builtin.test_functions) |test_fn| { | 239 | for (builtin.test_functions) |test_fn| { |
| 231 | if (enable_print and print_all) { | 240 | if (enable_print) { |
| 232 | stderr.writeAll(test_fn.name) catch {}; | 241 | stderr.writeAll(test_fn.name) catch {}; |
| 233 | stderr.writeAll("... ") catch {}; | 242 | stderr.writeAll("... ") catch {}; |
| 234 | } | 243 | } |
| 235 | test_fn.func() catch |err| { | 244 | test_fn.func() catch |err| { |
| 236 | if (enable_print and !print_all) { | 245 | if (enable_print) { |
| 237 | stderr.writeAll(test_fn.name) catch {}; | 246 | stderr.writeAll(test_fn.name) catch {}; |
| 238 | stderr.writeAll("... ") catch {}; | 247 | stderr.writeAll("... ") catch {}; |
| 239 | } | 248 | } |
| ... | @@ -247,10 +256,10 @@ pub fn mainSimple() anyerror!void { | ... | @@ -247,10 +256,10 @@ pub fn mainSimple() anyerror!void { |
| 247 | skipped += 1; | 256 | skipped += 1; |
| 248 | continue; | 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 | passed += 1; | 260 | passed += 1; |
| 252 | } | 261 | } |
| 253 | if (print_summary) { | 262 | if (enable_print and print_summary) { |
| 254 | stderr.writer().print("{} passed, {} skipped, {} failed\n", .{ passed, skipped, failed }) catch {}; | 263 | stderr.writer().print("{} passed, {} skipped, {} failed\n", .{ passed, skipped, failed }) catch {}; |
| 255 | } | 264 | } |
| 256 | if (failed != 0) std.process.exit(1); | 265 | if (failed != 0) std.process.exit(1); |