From 7cb227ab678b57dd10b65c1d9c89526a3e47cc2a Mon Sep 17 00:00:00 2001 From: John Schmidt Date: Thu, 8 Feb 2024 23:40:03 +0100 Subject: [PATCH] Polish a few tests in switch.zig - Return `error.TestFailed` instead of panicing - Use `comptime assert` for type checks so that errors surface at compile time --- test/behavior/switch.zig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/behavior/switch.zig b/test/behavior/switch.zig index fb04bced0a..a0adbb818f 100644 --- a/test/behavior/switch.zig +++ b/test/behavior/switch.zig @@ -410,8 +410,8 @@ test "switch on integer with else capturing expr" { var x: i32 = 5; _ = &x; switch (x + 10) { - 14 => @panic("fail"), - 16 => @panic("fail"), + 14 => return error.TestFailed, + 16 => return error.TestFailed, else => |e| try expect(e == 15), } } @@ -522,7 +522,7 @@ test "switch with null and T peer types and inferred result location type" { else => null, }) |v| { _ = v; - @panic("fail"); + return error.TestFailed; } } }; @@ -548,12 +548,12 @@ test "switch prongs with cases with identical payload types" { fn doTheSwitch1(u: Union) !void { switch (u) { .A, .C => |e| { - try expect(@TypeOf(e) == usize); + comptime assert(@TypeOf(e) == usize); try expect(e == 8); }, .B => |e| { _ = e; - @panic("fail"); + return error.TestFailed; }, } } @@ -561,10 +561,10 @@ test "switch prongs with cases with identical payload types" { switch (u) { .A, .C => |e| { _ = e; - @panic("fail"); + return error.TestFailed; }, .B => |e| { - try expect(@TypeOf(e) == isize); + comptime assert(@TypeOf(e) == isize); try expect(e == -8); }, }