authorgravatar for john.schmidt.h@gmail.comJohn Schmidt <john.schmidt.h@gmail.com> 2024-02-08 23:40:03+01:00
committergravatar for john.schmidt.h@gmail.comJohn Schmidt <john.schmidt.h@gmail.com> 2024-02-08 23:49:03+01:00
log7cb227ab678b57dd10b65c1d9c89526a3e47cc2a
tree90108180c74b258c7263f40a8e1ff1555cb0b814
parent0d1baf0c6192c2ad917311f8275cc15b5550f0ac

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

1 files changed, 7 insertions(+), 7 deletions(-)

test/behavior/switch.zig+7-7
...@@ -410,8 +410,8 @@ test "switch on integer with else capturing expr" {...@@ -410,8 +410,8 @@ test "switch on integer with else capturing expr" {
410 var x: i32 = 5;410 var x: i32 = 5;
411 _ = &x;411 _ = &x;
412 switch (x + 10) {412 switch (x + 10) {
413 14 => @panic("fail"),413 14 => return error.TestFailed,
414 16 => @panic("fail"),414 16 => return error.TestFailed,
415 else => |e| try expect(e == 15),415 else => |e| try expect(e == 15),
416 }416 }
417 }417 }
...@@ -522,7 +522,7 @@ test "switch with null and T peer types and inferred result location type" {...@@ -522,7 +522,7 @@ test "switch with null and T peer types and inferred result location type" {
522 else => null,522 else => null,
523 }) |v| {523 }) |v| {
524 _ = v;524 _ = v;
525 @panic("fail");525 return error.TestFailed;
526 }526 }
527 }527 }
528 };528 };
...@@ -548,12 +548,12 @@ test "switch prongs with cases with identical payload types" {...@@ -548,12 +548,12 @@ test "switch prongs with cases with identical payload types" {
548 fn doTheSwitch1(u: Union) !void {548 fn doTheSwitch1(u: Union) !void {
549 switch (u) {549 switch (u) {
550 .A, .C => |e| {550 .A, .C => |e| {
551 try expect(@TypeOf(e) == usize);551 comptime assert(@TypeOf(e) == usize);
552 try expect(e == 8);552 try expect(e == 8);
553 },553 },
554 .B => |e| {554 .B => |e| {
555 _ = e;555 _ = e;
556 @panic("fail");556 return error.TestFailed;
557 },557 },
558 }558 }
559 }559 }
...@@ -561,10 +561,10 @@ test "switch prongs with cases with identical payload types" {...@@ -561,10 +561,10 @@ test "switch prongs with cases with identical payload types" {
561 switch (u) {561 switch (u) {
562 .A, .C => |e| {562 .A, .C => |e| {
563 _ = e;563 _ = e;
564 @panic("fail");564 return error.TestFailed;
565 },565 },
566 .B => |e| {566 .B => |e| {
567 try expect(@TypeOf(e) == isize);567 comptime assert(@TypeOf(e) == isize);
568 try expect(e == -8);568 try expect(e == -8);
569 },569 },
570 }570 }