| 1 |
const std = @import("std"); |
| 2 |
const builtin = @import("builtin"); |
| 3 |
|
| 4 |
pub fn main() !void { |
| 5 |
const out = std.io.getStdOut().writer(); |
| 6 |
var has_failures = false; |
| 7 |
for (builtin.test_functions) |t| { |
| 8 |
std.testing.allocator_instance = .{}; |
| 9 |
|
| 10 |
const name = extractName(t); |
| 11 |
const result = t.func(); |
| 12 |
if (result) |_| { |
| 13 |
try std.fmt.format(out, "[SUCCESS] {s}\n", .{name}); |
| 14 |
} else |err| switch (err) { |
| 15 |
error.SkipZigTest => try std.fmt.format(out, "[SKIP] {s}\n", .{name}), |
| 16 |
else => { |
| 17 |
has_failures = true; |
| 18 |
try std.fmt.format(out, "[FAIL] {s}: {}\n", .{ t.name, err }); |
| 19 |
}, |
| 20 |
} |
| 21 |
|
| 22 |
if (std.testing.allocator_instance.deinit() == .leak) { |
| 23 |
has_failures = true; |
| 24 |
try std.fmt.format(out, "{s} leaked memory\n", .{name}); |
| 25 |
} |
| 26 |
} |
| 27 |
if (has_failures) std.process.exit(1); |
| 28 |
} |
| 29 |
|
| 30 |
fn extractName(t: std.builtin.TestFn) []const u8 { |
| 31 |
const marker = std.mem.lastIndexOf(u8, t.name, ".test.") orelse return t.name; |
| 32 |
return t.name[marker + 6 ..]; |
| 33 |
} |