authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-12 21:10:01-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-12 21:15:41-07:00
log537f9052167a683c922c9815eb9fdce5b0778dc2
treeb81a88655dd056aa006e9cd7d7855cef65b1700c
parent974af5f29101ce8d000359b749f35a2b07c90a32

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.

1 files changed, 6 insertions(+), 50 deletions(-)

test/runtime_safety.zig+6-50
......@@ -95,67 +95,23 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
9595 \\}
9696 ;
9797
98 cases.addRuntimeSafety("slicing operator with sentinel",
98 cases.addRuntimeSafety("slice with sentinel out of bounds",
9999 \\const std = @import("std");
100100 ++ check_panic_msg ++
101101 \\pub fn main() void {
102102 \\ var buf = [4]u8{'a','b','c',0};
103 \\ const slice = buf[0..4 :0];
103 \\ const input: []u8 = &buf;
104 \\ const slice = input[0..4 :0];
104105 \\ _ = slice;
105106 \\}
106107 );
107 cases.addRuntimeSafety("slicing operator with sentinel",
108 \\const std = @import("std");
109 ++ check_panic_msg ++
110 \\pub fn main() void {
111 \\ var buf = [4]u8{'a','b','c',0};
112 \\ const slice = buf[0..:0];
113 \\ _ = slice;
114 \\}
115 );
116 cases.addRuntimeSafety("slicing operator with sentinel",
117 \\const std = @import("std");
118 ++ check_panic_msg ++
119 \\pub fn main() void {
120 \\ var buf_zero = [0]u8{};
121 \\ const slice = buf_zero[0..0 :0];
122 \\ _ = slice;
123 \\}
124 );
125 cases.addRuntimeSafety("slicing operator with sentinel",
108 cases.addRuntimeSafety("empty slice with sentinel out of bounds",
126109 \\const std = @import("std");
127110 ++ check_panic_msg ++
128111 \\pub fn main() void {
129112 \\ var buf_zero = [0]u8{};
130 \\ const slice = buf_zero[0..:0];
131 \\ _ = slice;
132 \\}
133 );
134 cases.addRuntimeSafety("slicing operator with sentinel",
135 \\const std = @import("std");
136 ++ check_panic_msg ++
137 \\pub fn main() void {
138 \\ var buf_sentinel = [2:0]u8{'a','b'};
139 \\ @ptrCast(*[3]u8, &buf_sentinel)[2] = 0;
140 \\ const slice = buf_sentinel[0..3 :0];
141 \\ _ = slice;
142 \\}
143 );
144 cases.addRuntimeSafety("slicing operator with sentinel",
145 \\const std = @import("std");
146 ++ check_panic_msg ++
147 \\pub fn main() void {
148 \\ var buf_slice: []const u8 = &[3]u8{ 'a', 'b', 0 };
149 \\ const slice = buf_slice[0..3 :0];
150 \\ _ = slice;
151 \\}
152 );
153 cases.addRuntimeSafety("slicing operator with sentinel",
154 \\const std = @import("std");
155 ++ check_panic_msg ++
156 \\pub fn main() void {
157 \\ var buf_slice: []const u8 = &[3]u8{ 'a', 'b', 0 };
158 \\ const slice = buf_slice[0.. :0];
113 \\ const input: []u8 = &buf_zero;
114 \\ const slice = input[0..0 :0];
159115 \\ _ = slice;
160116 \\}
161117 );