From df574ccf8655726dc204142e7bcfb36770426257 Mon Sep 17 00:00:00 2001 From: kristopher tate Date: Sun, 22 Jul 2018 02:20:03 +0900 Subject: [PATCH 1/4] std.special.test_runner.zig: make tests skippable; tracking issue #1274; tests can be skipped by returnning `error.skip` : --- std/special/test_runner.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/std/special/test_runner.zig b/std/special/test_runner.zig index 76a54a5018..46ed7e23e9 100644 --- a/std/special/test_runner.zig +++ b/std/special/test_runner.zig @@ -8,7 +8,13 @@ pub fn main() !void { for (test_fn_list) |test_fn, i| { warn("Test {}/{} {}...", i + 1, test_fn_list.len, test_fn.name); - try test_fn.func(); + test_fn.func() catch |err| { + if (err == error.skip) { + warn("SKIPPED\n"); + continue; + } + return err; + }; warn("OK\n"); } From bc411af4ffb07fa0e8d713c300c2badd1116acff Mon Sep 17 00:00:00 2001 From: kristopher tate Date: Sun, 22 Jul 2018 02:21:52 +0900 Subject: [PATCH 2/4] std.event.tcp: SKIP test instead of OKing test; tracking issue #1274 ; --- std/event/tcp.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/event/tcp.zig b/std/event/tcp.zig index 5151ecf934..27eab9f0bb 100644 --- a/std/event/tcp.zig +++ b/std/event/tcp.zig @@ -125,7 +125,7 @@ pub async fn connect(loop: *Loop, _address: *const std.net.Address) !std.os.File test "listen on a port, send bytes, receive bytes" { if (builtin.os != builtin.Os.linux) { // TODO build abstractions for other operating systems - return; + return error.skip; } const MyServer = struct { tcp_server: Server, From c5c053b6fdde911edd0b488c29fbef0e2aa0a904 Mon Sep 17 00:00:00 2001 From: kristopher tate Date: Sun, 22 Jul 2018 03:11:55 +0900 Subject: [PATCH 3/4] std.event.tcp: add switch statement in preparation for building-out abstractions; depends on issue #1274 ; --- std/event/tcp.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/std/event/tcp.zig b/std/event/tcp.zig index 27eab9f0bb..1542538082 100644 --- a/std/event/tcp.zig +++ b/std/event/tcp.zig @@ -123,10 +123,17 @@ pub async fn connect(loop: *Loop, _address: *const std.net.Address) !std.os.File } test "listen on a port, send bytes, receive bytes" { - if (builtin.os != builtin.Os.linux) { - // TODO build abstractions for other operating systems + // TODO build abstractions for other operating systems + const skip_test: bool = switch (builtin.os) { + builtin.Os.linux => false, + //builtin.Os.macosx, builtin.Os.ios => false, + else => true, + }; + + if (skip_test == true) { return error.skip; } + const MyServer = struct { tcp_server: Server, From 4d9964a457084d41ba2995082d0e25b195757751 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 21 Jul 2018 23:43:43 -0400 Subject: [PATCH 4/4] rename error.skip to error.SkipZigTest also print stats at the end of test runner --- std/event/tcp.zig | 12 +++--------- std/special/test_runner.zig | 26 +++++++++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/std/event/tcp.zig b/std/event/tcp.zig index 1542538082..416a8c07dc 100644 --- a/std/event/tcp.zig +++ b/std/event/tcp.zig @@ -123,15 +123,9 @@ pub async fn connect(loop: *Loop, _address: *const std.net.Address) !std.os.File } test "listen on a port, send bytes, receive bytes" { - // TODO build abstractions for other operating systems - const skip_test: bool = switch (builtin.os) { - builtin.Os.linux => false, - //builtin.Os.macosx, builtin.Os.ios => false, - else => true, - }; - - if (skip_test == true) { - return error.skip; + if (builtin.os != builtin.Os.linux) { + // TODO build abstractions for other operating systems + return error.SkipZigTest; } const MyServer = struct { diff --git a/std/special/test_runner.zig b/std/special/test_runner.zig index 46ed7e23e9..857739e82d 100644 --- a/std/special/test_runner.zig +++ b/std/special/test_runner.zig @@ -5,17 +5,25 @@ const test_fn_list = builtin.__zig_test_fn_slice; const warn = std.debug.warn; pub fn main() !void { + var ok_count: usize = 0; + var skip_count: usize = 0; for (test_fn_list) |test_fn, i| { warn("Test {}/{} {}...", i + 1, test_fn_list.len, test_fn.name); - test_fn.func() catch |err| { - if (err == error.skip) { - warn("SKIPPED\n"); - continue; - } - return err; - }; - - warn("OK\n"); + if (test_fn.func()) |_| { + ok_count += 1; + warn("OK\n"); + } else |err| switch (err) { + error.SkipZigTest => { + skip_count += 1; + warn("SKIP\n"); + }, + else => return err, + } + } + if (ok_count == test_fn_list.len) { + warn("All tests passed.\n"); + } else { + warn("{} passed; {} skipped.\n", ok_count, skip_count); } }