| ... | ... | @@ -1,6 +1,75 @@ |
| 1 | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | |
| 3 | 3 | pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 4 | { |
| 5 | const check_panic_msg = |
| 6 | \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { |
| 7 | \\ if (std.mem.eql(u8, message, "index out of bounds")) { |
| 8 | \\ std.process.exit(126); // good |
| 9 | \\ } |
| 10 | \\ std.process.exit(0); // test failed |
| 11 | \\} |
| 12 | ; |
| 13 | |
| 14 | cases.addRuntimeSafety("slicing operator with sentinel", |
| 15 | \\const std = @import("std"); |
| 16 | ++ check_panic_msg ++ |
| 17 | \\pub fn main() void { |
| 18 | \\ var buf = [4]u8{'a','b','c',0}; |
| 19 | \\ const slice = buf[0..4 :0]; |
| 20 | \\} |
| 21 | ); |
| 22 | cases.addRuntimeSafety("slicing operator with sentinel", |
| 23 | \\const std = @import("std"); |
| 24 | ++ check_panic_msg ++ |
| 25 | \\pub fn main() void { |
| 26 | \\ var buf = [4]u8{'a','b','c',0}; |
| 27 | \\ const slice = buf[0..:0]; |
| 28 | \\} |
| 29 | ); |
| 30 | cases.addRuntimeSafety("slicing operator with sentinel", |
| 31 | \\const std = @import("std"); |
| 32 | ++ check_panic_msg ++ |
| 33 | \\pub fn main() void { |
| 34 | \\ var buf_zero = [0]u8{}; |
| 35 | \\ const slice = buf_zero[0..0 :0]; |
| 36 | \\} |
| 37 | ); |
| 38 | cases.addRuntimeSafety("slicing operator with sentinel", |
| 39 | \\const std = @import("std"); |
| 40 | ++ check_panic_msg ++ |
| 41 | \\pub fn main() void { |
| 42 | \\ var buf_zero = [0]u8{}; |
| 43 | \\ const slice = buf_zero[0..:0]; |
| 44 | \\} |
| 45 | ); |
| 46 | cases.addRuntimeSafety("slicing operator with sentinel", |
| 47 | \\const std = @import("std"); |
| 48 | ++ check_panic_msg ++ |
| 49 | \\pub fn main() void { |
| 50 | \\ var buf_sentinel = [2:0]u8{'a','b'}; |
| 51 | \\ @ptrCast(*[3]u8, &buf_sentinel)[2] = 0; |
| 52 | \\ const slice = buf_sentinel[0..3 :0]; |
| 53 | \\} |
| 54 | ); |
| 55 | cases.addRuntimeSafety("slicing operator with sentinel", |
| 56 | \\const std = @import("std"); |
| 57 | ++ check_panic_msg ++ |
| 58 | \\pub fn main() void { |
| 59 | \\ var buf_slice: []u8 = &[3]u8{ 'a', 'b', 0 }; |
| 60 | \\ const slice = buf_slice[0..3 :0]; |
| 61 | \\} |
| 62 | ); |
| 63 | cases.addRuntimeSafety("slicing operator with sentinel", |
| 64 | \\const std = @import("std"); |
| 65 | ++ check_panic_msg ++ |
| 66 | \\pub fn main() void { |
| 67 | \\ var buf_slice: []u8 = &[3]u8{ 'a', 'b', 0 }; |
| 68 | \\ const slice = buf_slice[0.. :0]; |
| 69 | \\} |
| 70 | ); |
| 71 | } |
| 72 | |
| 4 | 73 | cases.addRuntimeSafety("shift left by huge amount", |
| 5 | 74 | \\const std = @import("std"); |
| 6 | 75 | \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { |