fix bad runtime safety test cases

The "slicing operator with sentinel" runtime safety test cases should
all have been compile errors in their current forms. In this commit I
adjust them to use runtime-known slices before triggering the runtime
safety.

Furthermore the test cases did not actually have unique names.
This commit is contained in:
Andrew Kelley 2022-05-12 21:10:01 -07:00
parent 974af5f291
commit 537f905216

View File

@ -95,67 +95,23 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\}
;
cases.addRuntimeSafety("slicing operator with sentinel",
cases.addRuntimeSafety("slice with sentinel out of bounds",
\\const std = @import("std");
++ check_panic_msg ++
\\pub fn main() void {
\\ var buf = [4]u8{'a','b','c',0};
\\ const slice = buf[0..4 :0];
\\ const input: []u8 = &buf;
\\ const slice = input[0..4 :0];
\\ _ = slice;
\\}
);
cases.addRuntimeSafety("slicing operator with sentinel",
\\const std = @import("std");
++ check_panic_msg ++
\\pub fn main() void {
\\ var buf = [4]u8{'a','b','c',0};
\\ const slice = buf[0..:0];
\\ _ = slice;
\\}
);
cases.addRuntimeSafety("slicing operator with sentinel",
cases.addRuntimeSafety("empty slice with sentinel out of bounds",
\\const std = @import("std");
++ check_panic_msg ++
\\pub fn main() void {
\\ var buf_zero = [0]u8{};
\\ const slice = buf_zero[0..0 :0];
\\ _ = slice;
\\}
);
cases.addRuntimeSafety("slicing operator with sentinel",
\\const std = @import("std");
++ check_panic_msg ++
\\pub fn main() void {
\\ var buf_zero = [0]u8{};
\\ const slice = buf_zero[0..:0];
\\ _ = slice;
\\}
);
cases.addRuntimeSafety("slicing operator with sentinel",
\\const std = @import("std");
++ check_panic_msg ++
\\pub fn main() void {
\\ var buf_sentinel = [2:0]u8{'a','b'};
\\ @ptrCast(*[3]u8, &buf_sentinel)[2] = 0;
\\ const slice = buf_sentinel[0..3 :0];
\\ _ = slice;
\\}
);
cases.addRuntimeSafety("slicing operator with sentinel",
\\const std = @import("std");
++ check_panic_msg ++
\\pub fn main() void {
\\ var buf_slice: []const u8 = &[3]u8{ 'a', 'b', 0 };
\\ const slice = buf_slice[0..3 :0];
\\ _ = slice;
\\}
);
cases.addRuntimeSafety("slicing operator with sentinel",
\\const std = @import("std");
++ check_panic_msg ++
\\pub fn main() void {
\\ var buf_slice: []const u8 = &[3]u8{ 'a', 'b', 0 };
\\ const slice = buf_slice[0.. :0];
\\ const input: []u8 = &buf_zero;
\\ const slice = input[0..0 :0];
\\ _ = slice;
\\}
);