authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-16 00:20:51-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-16 00:20:51-04:00
log78b753af9dd9818b9dc848f590330c61b2ca7c3f
tree074dcc9421b3150c63c1e3308f986a571446b8d2
parentd6bfa3f6390cfa0fa745e73640bb1d275a6d673c

fix debug safety tests on windows

See #302

2 files changed, 30 insertions(+), 49 deletions(-)

test/debug_safety.zig+19-38
...@@ -3,8 +3,7 @@ const tests = @import("tests.zig");...@@ -3,8 +3,7 @@ const tests = @import("tests.zig");
3pub fn addCases(cases: &tests.CompareOutputContext) {3pub fn addCases(cases: &tests.CompareOutputContext) {
4 cases.addDebugSafety("calling panic",4 cases.addDebugSafety("calling panic",
5 \\pub fn panic(message: []const u8) -> noreturn {5 \\pub fn panic(message: []const u8) -> noreturn {
6 \\ @breakpoint();6 \\ @import("std").os.exit(126);
7 \\ while (true) {}
8 \\}7 \\}
9 \\pub fn main() -> %void {8 \\pub fn main() -> %void {
10 \\ @panic("oh no");9 \\ @panic("oh no");
...@@ -13,8 +12,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -13,8 +12,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
1312
14 cases.addDebugSafety("out of bounds slice access",13 cases.addDebugSafety("out of bounds slice access",
15 \\pub fn panic(message: []const u8) -> noreturn {14 \\pub fn panic(message: []const u8) -> noreturn {
16 \\ @breakpoint();15 \\ @import("std").os.exit(126);
17 \\ while (true) {}
18 \\}16 \\}
19 \\pub fn main() -> %void {17 \\pub fn main() -> %void {
20 \\ const a = []i32{1, 2, 3, 4};18 \\ const a = []i32{1, 2, 3, 4};
...@@ -28,8 +26,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -28,8 +26,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
2826
29 cases.addDebugSafety("integer addition overflow",27 cases.addDebugSafety("integer addition overflow",
30 \\pub fn panic(message: []const u8) -> noreturn {28 \\pub fn panic(message: []const u8) -> noreturn {
31 \\ @breakpoint();29 \\ @import("std").os.exit(126);
32 \\ while (true) {}
33 \\}30 \\}
34 \\error Whatever;31 \\error Whatever;
35 \\pub fn main() -> %void {32 \\pub fn main() -> %void {
...@@ -43,8 +40,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -43,8 +40,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
4340
44 cases.addDebugSafety("integer subtraction overflow",41 cases.addDebugSafety("integer subtraction overflow",
45 \\pub fn panic(message: []const u8) -> noreturn {42 \\pub fn panic(message: []const u8) -> noreturn {
46 \\ @breakpoint();43 \\ @import("std").os.exit(126);
47 \\ while (true) {}
48 \\}44 \\}
49 \\error Whatever;45 \\error Whatever;
50 \\pub fn main() -> %void {46 \\pub fn main() -> %void {
...@@ -58,8 +54,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -58,8 +54,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
5854
59 cases.addDebugSafety("integer multiplication overflow",55 cases.addDebugSafety("integer multiplication overflow",
60 \\pub fn panic(message: []const u8) -> noreturn {56 \\pub fn panic(message: []const u8) -> noreturn {
61 \\ @breakpoint();57 \\ @import("std").os.exit(126);
62 \\ while (true) {}
63 \\}58 \\}
64 \\error Whatever;59 \\error Whatever;
65 \\pub fn main() -> %void {60 \\pub fn main() -> %void {
...@@ -73,8 +68,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -73,8 +68,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
7368
74 cases.addDebugSafety("integer negation overflow",69 cases.addDebugSafety("integer negation overflow",
75 \\pub fn panic(message: []const u8) -> noreturn {70 \\pub fn panic(message: []const u8) -> noreturn {
76 \\ @breakpoint();71 \\ @import("std").os.exit(126);
77 \\ while (true) {}
78 \\}72 \\}
79 \\error Whatever;73 \\error Whatever;
80 \\pub fn main() -> %void {74 \\pub fn main() -> %void {
...@@ -88,8 +82,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -88,8 +82,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
8882
89 cases.addDebugSafety("signed integer division overflow",83 cases.addDebugSafety("signed integer division overflow",
90 \\pub fn panic(message: []const u8) -> noreturn {84 \\pub fn panic(message: []const u8) -> noreturn {
91 \\ @breakpoint();85 \\ @import("std").os.exit(126);
92 \\ while (true) {}
93 \\}86 \\}
94 \\error Whatever;87 \\error Whatever;
95 \\pub fn main() -> %void {88 \\pub fn main() -> %void {
...@@ -103,8 +96,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -103,8 +96,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
10396
104 cases.addDebugSafety("signed shift left overflow",97 cases.addDebugSafety("signed shift left overflow",
105 \\pub fn panic(message: []const u8) -> noreturn {98 \\pub fn panic(message: []const u8) -> noreturn {
106 \\ @breakpoint();99 \\ @import("std").os.exit(126);
107 \\ while (true) {}
108 \\}100 \\}
109 \\error Whatever;101 \\error Whatever;
110 \\pub fn main() -> %void {102 \\pub fn main() -> %void {
...@@ -118,8 +110,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -118,8 +110,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
118110
119 cases.addDebugSafety("unsigned shift left overflow",111 cases.addDebugSafety("unsigned shift left overflow",
120 \\pub fn panic(message: []const u8) -> noreturn {112 \\pub fn panic(message: []const u8) -> noreturn {
121 \\ @breakpoint();113 \\ @import("std").os.exit(126);
122 \\ while (true) {}
123 \\}114 \\}
124 \\error Whatever;115 \\error Whatever;
125 \\pub fn main() -> %void {116 \\pub fn main() -> %void {
...@@ -133,8 +124,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -133,8 +124,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
133124
134 cases.addDebugSafety("signed shift right overflow",125 cases.addDebugSafety("signed shift right overflow",
135 \\pub fn panic(message: []const u8) -> noreturn {126 \\pub fn panic(message: []const u8) -> noreturn {
136 \\ @breakpoint();127 \\ @import("std").os.exit(126);
137 \\ while (true) {}
138 \\}128 \\}
139 \\error Whatever;129 \\error Whatever;
140 \\pub fn main() -> %void {130 \\pub fn main() -> %void {
...@@ -148,8 +138,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -148,8 +138,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
148138
149 cases.addDebugSafety("unsigned shift right overflow",139 cases.addDebugSafety("unsigned shift right overflow",
150 \\pub fn panic(message: []const u8) -> noreturn {140 \\pub fn panic(message: []const u8) -> noreturn {
151 \\ @breakpoint();141 \\ @import("std").os.exit(126);
152 \\ while (true) {}
153 \\}142 \\}
154 \\error Whatever;143 \\error Whatever;
155 \\pub fn main() -> %void {144 \\pub fn main() -> %void {
...@@ -163,8 +152,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -163,8 +152,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
163152
164 cases.addDebugSafety("integer division by zero",153 cases.addDebugSafety("integer division by zero",
165 \\pub fn panic(message: []const u8) -> noreturn {154 \\pub fn panic(message: []const u8) -> noreturn {
166 \\ @breakpoint();155 \\ @import("std").os.exit(126);
167 \\ while (true) {}
168 \\}156 \\}
169 \\error Whatever;157 \\error Whatever;
170 \\pub fn main() -> %void {158 \\pub fn main() -> %void {
...@@ -177,8 +165,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -177,8 +165,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
177165
178 cases.addDebugSafety("exact division failure",166 cases.addDebugSafety("exact division failure",
179 \\pub fn panic(message: []const u8) -> noreturn {167 \\pub fn panic(message: []const u8) -> noreturn {
180 \\ @breakpoint();168 \\ @import("std").os.exit(126);
181 \\ while (true) {}
182 \\}169 \\}
183 \\error Whatever;170 \\error Whatever;
184 \\pub fn main() -> %void {171 \\pub fn main() -> %void {
...@@ -192,8 +179,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -192,8 +179,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
192179
193 cases.addDebugSafety("cast []u8 to bigger slice of wrong size",180 cases.addDebugSafety("cast []u8 to bigger slice of wrong size",
194 \\pub fn panic(message: []const u8) -> noreturn {181 \\pub fn panic(message: []const u8) -> noreturn {
195 \\ @breakpoint();182 \\ @import("std").os.exit(126);
196 \\ while (true) {}
197 \\}183 \\}
198 \\error Whatever;184 \\error Whatever;
199 \\pub fn main() -> %void {185 \\pub fn main() -> %void {
...@@ -207,8 +193,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -207,8 +193,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
207193
208 cases.addDebugSafety("value does not fit in shortening cast",194 cases.addDebugSafety("value does not fit in shortening cast",
209 \\pub fn panic(message: []const u8) -> noreturn {195 \\pub fn panic(message: []const u8) -> noreturn {
210 \\ @breakpoint();196 \\ @import("std").os.exit(126);
211 \\ while (true) {}
212 \\}197 \\}
213 \\error Whatever;198 \\error Whatever;
214 \\pub fn main() -> %void {199 \\pub fn main() -> %void {
...@@ -222,8 +207,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -222,8 +207,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
222207
223 cases.addDebugSafety("signed integer not fitting in cast to unsigned integer",208 cases.addDebugSafety("signed integer not fitting in cast to unsigned integer",
224 \\pub fn panic(message: []const u8) -> noreturn {209 \\pub fn panic(message: []const u8) -> noreturn {
225 \\ @breakpoint();210 \\ @import("std").os.exit(126);
226 \\ while (true) {}
227 \\}211 \\}
228 \\error Whatever;212 \\error Whatever;
229 \\pub fn main() -> %void {213 \\pub fn main() -> %void {
...@@ -237,8 +221,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -237,8 +221,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
237221
238 cases.addDebugSafety("unwrap error",222 cases.addDebugSafety("unwrap error",
239 \\pub fn panic(message: []const u8) -> noreturn {223 \\pub fn panic(message: []const u8) -> noreturn {
240 \\ @breakpoint();224 \\ @import("std").os.exit(126);
241 \\ while (true) {}
242 \\}225 \\}
243 \\error Whatever;226 \\error Whatever;
244 \\pub fn main() -> %void {227 \\pub fn main() -> %void {
...@@ -251,8 +234,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -251,8 +234,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
251234
252 cases.addDebugSafety("cast integer to error and no code matches",235 cases.addDebugSafety("cast integer to error and no code matches",
253 \\pub fn panic(message: []const u8) -> noreturn {236 \\pub fn panic(message: []const u8) -> noreturn {
254 \\ @breakpoint();237 \\ @import("std").os.exit(126);
255 \\ while (true) {}
256 \\}238 \\}
257 \\pub fn main() -> %void {239 \\pub fn main() -> %void {
258 \\ _ = bar(9999);240 \\ _ = bar(9999);
...@@ -264,8 +246,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -264,8 +246,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
264246
265 cases.addDebugSafety("@alignCast misaligned",247 cases.addDebugSafety("@alignCast misaligned",
266 \\pub fn panic(message: []const u8) -> noreturn {248 \\pub fn panic(message: []const u8) -> noreturn {
267 \\ @breakpoint();249 \\ @import("std").os.exit(126);
268 \\ while (true) {}
269 \\}250 \\}
270 \\error Wrong;251 \\error Wrong;
271 \\pub fn main() -> %void {252 \\pub fn main() -> %void {
test/tests.zig+11-11
...@@ -324,23 +324,23 @@ pub const CompareOutputContext = struct {...@@ -324,23 +324,23 @@ pub const CompareOutputContext = struct {
324 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));324 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
325 };325 };
326326
327 const debug_trap_signal: i32 = 5;327 const expected_exit_code: i32 = 126;
328 switch (term) {328 switch (term) {
329 Term.Exited => |code| {329 Term.Exited => |code| {
330 %%io.stderr.printf("\nProgram expected to hit debug trap (signal {}) " ++330 if (code != expected_exit_code) {
331 "but exited with return code {}\n", debug_trap_signal, code);331 %%io.stderr.printf("\nProgram expected to exit with code {} " ++
332 return error.TestFailed;332 "but exited with code {}\n", expected_exit_code, code);
333 },
334 Term.Signal => |sig| {
335 if (sig != debug_trap_signal) {
336 %%io.stderr.printf("\nProgram expected to hit debug trap (signal {}) " ++
337 "but instead signaled {}\n", debug_trap_signal, sig);
338 return error.TestFailed;333 return error.TestFailed;
339 }334 }
340 },335 },
336 Term.Signal => |sig| {
337 %%io.stderr.printf("\nProgram expected to exit with code {} " ++
338 "but instead signaled {}\n", expected_exit_code, sig);
339 return error.TestFailed;
340 },
341 else => {341 else => {
342 %%io.stderr.printf("\nProgram expected to hit debug trap (signal {}) " ++342 %%io.stderr.printf("\nProgram expected to exit with code {}" ++
343 " but exited in an unexpected way\n", debug_trap_signal);343 " but exited in an unexpected way\n", expected_exit_code);
344 return error.TestFailed;344 return error.TestFailed;
345 },345 },
346 }346 }