mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
test: refactor mainSimple
added some comments to make it easier for future contributors.
This commit is contained in:
parent
3967e00047
commit
3530308476
1 changed files with 17 additions and 8 deletions
|
|
@ -219,21 +219,30 @@ pub fn log(
|
||||||
/// Simpler main(), exercising fewer language features, so that
|
/// Simpler main(), exercising fewer language features, so that
|
||||||
/// work-in-progress backends can handle it.
|
/// work-in-progress backends can handle it.
|
||||||
pub fn mainSimple() anyerror!void {
|
pub fn mainSimple() anyerror!void {
|
||||||
const enable_print = true;
|
// is the backend capable of printing to stderr?
|
||||||
const print_all = true;
|
const enable_print = switch (builtin.zig_backend) {
|
||||||
const print_summary = false;
|
.stage2_riscv64 => true,
|
||||||
|
else => false,
|
||||||
|
};
|
||||||
|
// is the backend capable of using std.fmt.format to print a summary at the end?
|
||||||
|
const print_summary = switch (builtin.zig_backend) {
|
||||||
|
else => false,
|
||||||
|
};
|
||||||
|
|
||||||
var passed: u64 = 0;
|
var passed: u64 = 0;
|
||||||
var skipped: u64 = 0;
|
var skipped: u64 = 0;
|
||||||
var failed: u64 = 0;
|
var failed: u64 = 0;
|
||||||
const stderr = if (enable_print) std.io.getStdErr() else {};
|
|
||||||
|
// we don't want to bring in File and Writer if the backend doesn't support it
|
||||||
|
const stderr = if (comptime enable_print) std.io.getStdErr() else {};
|
||||||
|
|
||||||
for (builtin.test_functions) |test_fn| {
|
for (builtin.test_functions) |test_fn| {
|
||||||
if (enable_print and print_all) {
|
if (enable_print) {
|
||||||
stderr.writeAll(test_fn.name) catch {};
|
stderr.writeAll(test_fn.name) catch {};
|
||||||
stderr.writeAll("... ") catch {};
|
stderr.writeAll("... ") catch {};
|
||||||
}
|
}
|
||||||
test_fn.func() catch |err| {
|
test_fn.func() catch |err| {
|
||||||
if (enable_print and !print_all) {
|
if (enable_print) {
|
||||||
stderr.writeAll(test_fn.name) catch {};
|
stderr.writeAll(test_fn.name) catch {};
|
||||||
stderr.writeAll("... ") catch {};
|
stderr.writeAll("... ") catch {};
|
||||||
}
|
}
|
||||||
|
|
@ -247,10 +256,10 @@ pub fn mainSimple() anyerror!void {
|
||||||
skipped += 1;
|
skipped += 1;
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if (enable_print and print_all) stderr.writeAll("PASS\n") catch {};
|
if (enable_print) stderr.writeAll("PASS\n") catch {};
|
||||||
passed += 1;
|
passed += 1;
|
||||||
}
|
}
|
||||||
if (print_summary) {
|
if (enable_print and print_summary) {
|
||||||
stderr.writer().print("{} passed, {} skipped, {} failed\n", .{ passed, skipped, failed }) catch {};
|
stderr.writer().print("{} passed, {} skipped, {} failed\n", .{ passed, skipped, failed }) catch {};
|
||||||
}
|
}
|
||||||
if (failed != 0) std.process.exit(1);
|
if (failed != 0) std.process.exit(1);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue