2017-10-31 01:47:55 -07:00
|
|
|
const std = @import("std");
|
|
|
|
const io = std.io;
|
2017-05-01 10:12:38 -07:00
|
|
|
const builtin = @import("builtin");
|
2016-02-03 17:02:01 -08:00
|
|
|
|
2019-10-17 18:46:41 -07:00
|
|
|
pub fn main() anyerror!void {
|
2019-12-12 15:27:17 -08:00
|
|
|
const test_fn_list = builtin.test_functions;
|
2018-07-21 20:43:43 -07:00
|
|
|
var ok_count: usize = 0;
|
|
|
|
var skip_count: usize = 0;
|
2019-10-17 18:46:41 -07:00
|
|
|
var progress = std.Progress{};
|
|
|
|
const root_node = progress.start("Test", test_fn_list.len) catch |err| switch (err) {
|
|
|
|
// TODO still run tests in this case
|
|
|
|
error.TimerUnsupported => @panic("timer unsupported"),
|
|
|
|
};
|
2016-02-03 17:02:01 -08:00
|
|
|
|
2019-10-17 18:46:41 -07:00
|
|
|
for (test_fn_list) |test_fn, i| {
|
2020-01-29 19:22:01 -08:00
|
|
|
std.testing.base_allocator_instance.reset();
|
2020-01-29 11:18:04 -08:00
|
|
|
|
2019-10-17 18:46:41 -07:00
|
|
|
var test_node = root_node.start(test_fn.name, null);
|
|
|
|
test_node.activate();
|
2019-10-21 16:01:08 -07:00
|
|
|
progress.refresh();
|
2019-12-12 15:27:17 -08:00
|
|
|
if (progress.terminal == null) {
|
|
|
|
std.debug.warn("{}/{} {}...", .{ i + 1, test_fn_list.len, test_fn.name });
|
|
|
|
}
|
2018-07-21 20:43:43 -07:00
|
|
|
if (test_fn.func()) |_| {
|
|
|
|
ok_count += 1;
|
2019-10-17 18:46:41 -07:00
|
|
|
test_node.end();
|
2020-01-29 22:14:17 -08:00
|
|
|
std.testing.allocator_instance.validate() catch |err| switch (err) {
|
|
|
|
error.Leak => std.debug.panic("", .{}),
|
|
|
|
else => std.debug.panic("error.{}", .{@errorName(err)}),
|
|
|
|
};
|
2019-12-08 19:53:51 -08:00
|
|
|
if (progress.terminal == null) std.debug.warn("OK\n", .{});
|
2018-07-21 20:43:43 -07:00
|
|
|
} else |err| switch (err) {
|
|
|
|
error.SkipZigTest => {
|
|
|
|
skip_count += 1;
|
2019-10-17 18:46:41 -07:00
|
|
|
test_node.end();
|
2019-12-08 19:53:51 -08:00
|
|
|
progress.log("{}...SKIP\n", .{test_fn.name});
|
|
|
|
if (progress.terminal == null) std.debug.warn("SKIP\n", .{});
|
2018-07-21 20:43:43 -07:00
|
|
|
},
|
2019-10-21 15:35:14 -07:00
|
|
|
else => {
|
2019-12-08 19:53:51 -08:00
|
|
|
progress.log("", .{});
|
2019-10-21 15:35:14 -07:00
|
|
|
return err;
|
|
|
|
},
|
2018-07-21 20:43:43 -07:00
|
|
|
}
|
|
|
|
}
|
2019-10-17 18:46:41 -07:00
|
|
|
root_node.end();
|
2019-10-21 19:20:45 -07:00
|
|
|
if (ok_count == test_fn_list.len) {
|
2019-12-08 19:53:51 -08:00
|
|
|
std.debug.warn("All {} tests passed.\n", .{ok_count});
|
2019-10-21 19:20:45 -07:00
|
|
|
} else {
|
2019-12-08 19:53:51 -08:00
|
|
|
std.debug.warn("{} passed; {} skipped.\n", .{ ok_count, skip_count });
|
2016-02-03 17:02:01 -08:00
|
|
|
}
|
|
|
|
}
|