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
|
|
|
|
2020-02-06 14:56:40 -08:00
|
|
|
pub const io_mode: io.Mode = builtin.test_io_mode;
|
2020-02-05 13:53:29 -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
|
|
|
|
2020-02-06 14:56:40 -08:00
|
|
|
var async_frame_buffer: []align(std.Target.stack_align) u8 = undefined;
|
|
|
|
// TODO this is on the next line (using `undefined` above) because otherwise zig incorrectly
|
|
|
|
// ignores the alignment of the slice.
|
|
|
|
async_frame_buffer = &[_]u8{};
|
|
|
|
|
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 });
|
|
|
|
}
|
2020-02-06 14:56:40 -08:00
|
|
|
const result = if (test_fn.async_frame_size) |size| switch (io_mode) {
|
|
|
|
.evented => blk: {
|
|
|
|
if (async_frame_buffer.len < size) {
|
|
|
|
std.heap.page_allocator.free(async_frame_buffer);
|
|
|
|
async_frame_buffer = try std.heap.page_allocator.alignedAlloc(u8, std.Target.stack_align, size);
|
|
|
|
}
|
2020-05-04 08:49:27 -07:00
|
|
|
const casted_fn = @ptrCast(fn () callconv(.Async) anyerror!void, test_fn.func);
|
2020-02-06 14:56:40 -08:00
|
|
|
break :blk await @asyncCall(async_frame_buffer, {}, casted_fn);
|
|
|
|
},
|
|
|
|
.blocking => {
|
|
|
|
skip_count += 1;
|
|
|
|
test_node.end();
|
|
|
|
progress.log("{}...SKIP (async test)\n", .{test_fn.name});
|
|
|
|
if (progress.terminal == null) std.debug.warn("SKIP (async test)\n", .{});
|
|
|
|
continue;
|
|
|
|
},
|
|
|
|
} else test_fn.func();
|
|
|
|
if (result) |_| {
|
2018-07-21 20:43:43 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|