Skip to content

Commit 78b753a

Browse files
committed
fix debug safety tests on windows
See #302
1 parent d6bfa3f commit 78b753a

2 files changed

Lines changed: 30 additions & 49 deletions

File tree

test/debug_safety.zig

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ const tests = @import("tests.zig");
33
pub fn addCases(cases: &tests.CompareOutputContext) {
44
cases.addDebugSafety("calling panic",
55
\\pub fn panic(message: []const u8) -> noreturn {
6-
\\ @breakpoint();
7-
\\ while (true) {}
6+
\\ @import("std").os.exit(126);
87
\\}
98
\\pub fn main() -> %void {
109
\\ @panic("oh no");
@@ -13,8 +12,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
1312

1413
cases.addDebugSafety("out of bounds slice access",
1514
\\pub fn panic(message: []const u8) -> noreturn {
16-
\\ @breakpoint();
17-
\\ while (true) {}
15+
\\ @import("std").os.exit(126);
1816
\\}
1917
\\pub fn main() -> %void {
2018
\\ const a = []i32{1, 2, 3, 4};
@@ -28,8 +26,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
2826

2927
cases.addDebugSafety("integer addition overflow",
3028
\\pub fn panic(message: []const u8) -> noreturn {
31-
\\ @breakpoint();
32-
\\ while (true) {}
29+
\\ @import("std").os.exit(126);
3330
\\}
3431
\\error Whatever;
3532
\\pub fn main() -> %void {
@@ -43,8 +40,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
4340

4441
cases.addDebugSafety("integer subtraction overflow",
4542
\\pub fn panic(message: []const u8) -> noreturn {
46-
\\ @breakpoint();
47-
\\ while (true) {}
43+
\\ @import("std").os.exit(126);
4844
\\}
4945
\\error Whatever;
5046
\\pub fn main() -> %void {
@@ -58,8 +54,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
5854

5955
cases.addDebugSafety("integer multiplication overflow",
6056
\\pub fn panic(message: []const u8) -> noreturn {
61-
\\ @breakpoint();
62-
\\ while (true) {}
57+
\\ @import("std").os.exit(126);
6358
\\}
6459
\\error Whatever;
6560
\\pub fn main() -> %void {
@@ -73,8 +68,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
7368

7469
cases.addDebugSafety("integer negation overflow",
7570
\\pub fn panic(message: []const u8) -> noreturn {
76-
\\ @breakpoint();
77-
\\ while (true) {}
71+
\\ @import("std").os.exit(126);
7872
\\}
7973
\\error Whatever;
8074
\\pub fn main() -> %void {
@@ -88,8 +82,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
8882

8983
cases.addDebugSafety("signed integer division overflow",
9084
\\pub fn panic(message: []const u8) -> noreturn {
91-
\\ @breakpoint();
92-
\\ while (true) {}
85+
\\ @import("std").os.exit(126);
9386
\\}
9487
\\error Whatever;
9588
\\pub fn main() -> %void {
@@ -103,8 +96,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
10396

10497
cases.addDebugSafety("signed shift left overflow",
10598
\\pub fn panic(message: []const u8) -> noreturn {
106-
\\ @breakpoint();
107-
\\ while (true) {}
99+
\\ @import("std").os.exit(126);
108100
\\}
109101
\\error Whatever;
110102
\\pub fn main() -> %void {
@@ -118,8 +110,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
118110

119111
cases.addDebugSafety("unsigned shift left overflow",
120112
\\pub fn panic(message: []const u8) -> noreturn {
121-
\\ @breakpoint();
122-
\\ while (true) {}
113+
\\ @import("std").os.exit(126);
123114
\\}
124115
\\error Whatever;
125116
\\pub fn main() -> %void {
@@ -133,8 +124,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
133124

134125
cases.addDebugSafety("signed shift right overflow",
135126
\\pub fn panic(message: []const u8) -> noreturn {
136-
\\ @breakpoint();
137-
\\ while (true) {}
127+
\\ @import("std").os.exit(126);
138128
\\}
139129
\\error Whatever;
140130
\\pub fn main() -> %void {
@@ -148,8 +138,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
148138

149139
cases.addDebugSafety("unsigned shift right overflow",
150140
\\pub fn panic(message: []const u8) -> noreturn {
151-
\\ @breakpoint();
152-
\\ while (true) {}
141+
\\ @import("std").os.exit(126);
153142
\\}
154143
\\error Whatever;
155144
\\pub fn main() -> %void {
@@ -163,8 +152,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
163152

164153
cases.addDebugSafety("integer division by zero",
165154
\\pub fn panic(message: []const u8) -> noreturn {
166-
\\ @breakpoint();
167-
\\ while (true) {}
155+
\\ @import("std").os.exit(126);
168156
\\}
169157
\\error Whatever;
170158
\\pub fn main() -> %void {
@@ -177,8 +165,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
177165

178166
cases.addDebugSafety("exact division failure",
179167
\\pub fn panic(message: []const u8) -> noreturn {
180-
\\ @breakpoint();
181-
\\ while (true) {}
168+
\\ @import("std").os.exit(126);
182169
\\}
183170
\\error Whatever;
184171
\\pub fn main() -> %void {
@@ -192,8 +179,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
192179

193180
cases.addDebugSafety("cast []u8 to bigger slice of wrong size",
194181
\\pub fn panic(message: []const u8) -> noreturn {
195-
\\ @breakpoint();
196-
\\ while (true) {}
182+
\\ @import("std").os.exit(126);
197183
\\}
198184
\\error Whatever;
199185
\\pub fn main() -> %void {
@@ -207,8 +193,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
207193

208194
cases.addDebugSafety("value does not fit in shortening cast",
209195
\\pub fn panic(message: []const u8) -> noreturn {
210-
\\ @breakpoint();
211-
\\ while (true) {}
196+
\\ @import("std").os.exit(126);
212197
\\}
213198
\\error Whatever;
214199
\\pub fn main() -> %void {
@@ -222,8 +207,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
222207

223208
cases.addDebugSafety("signed integer not fitting in cast to unsigned integer",
224209
\\pub fn panic(message: []const u8) -> noreturn {
225-
\\ @breakpoint();
226-
\\ while (true) {}
210+
\\ @import("std").os.exit(126);
227211
\\}
228212
\\error Whatever;
229213
\\pub fn main() -> %void {
@@ -237,8 +221,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
237221

238222
cases.addDebugSafety("unwrap error",
239223
\\pub fn panic(message: []const u8) -> noreturn {
240-
\\ @breakpoint();
241-
\\ while (true) {}
224+
\\ @import("std").os.exit(126);
242225
\\}
243226
\\error Whatever;
244227
\\pub fn main() -> %void {
@@ -251,8 +234,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
251234

252235
cases.addDebugSafety("cast integer to error and no code matches",
253236
\\pub fn panic(message: []const u8) -> noreturn {
254-
\\ @breakpoint();
255-
\\ while (true) {}
237+
\\ @import("std").os.exit(126);
256238
\\}
257239
\\pub fn main() -> %void {
258240
\\ _ = bar(9999);
@@ -264,8 +246,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
264246

265247
cases.addDebugSafety("@alignCast misaligned",
266248
\\pub fn panic(message: []const u8) -> noreturn {
267-
\\ @breakpoint();
268-
\\ while (true) {}
249+
\\ @import("std").os.exit(126);
269250
\\}
270251
\\error Wrong;
271252
\\pub fn main() -> %void {

test/tests.zig

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -324,23 +324,23 @@ pub const CompareOutputContext = struct {
324324
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
325325
};
326326

327-
const debug_trap_signal: i32 = 5;
327+
const expected_exit_code: i32 = 126;
328328
switch (term) {
329329
Term.Exited => |code| {
330-
%%io.stderr.printf("\nProgram expected to hit debug trap (signal {}) " ++
331-
"but exited with return code {}\n", debug_trap_signal, code);
332-
return error.TestFailed;
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);
330+
if (code != expected_exit_code) {
331+
%%io.stderr.printf("\nProgram expected to exit with code {} " ++
332+
"but exited with code {}\n", expected_exit_code, code);
338333
return error.TestFailed;
339334
}
340335
},
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+
},
341341
else => {
342-
%%io.stderr.printf("\nProgram expected to hit debug trap (signal {}) " ++
343-
" but exited in an unexpected way\n", debug_trap_signal);
342+
%%io.stderr.printf("\nProgram expected to exit with code {}" ++
343+
" but exited in an unexpected way\n", expected_exit_code);
344344
return error.TestFailed;
345345
},
346346
}

0 commit comments

Comments
 (0)