Skip to content

Commit

Permalink
fix debug safety tests on windows
Browse files Browse the repository at this point in the history
See #302
  • Loading branch information
andrewrk committed Oct 16, 2017
1 parent d6bfa3f commit 78b753a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 49 deletions.
57 changes: 19 additions & 38 deletions test/debug_safety.zig
Expand Up @@ -3,8 +3,7 @@ const tests = @import("tests.zig");
pub fn addCases(cases: &tests.CompareOutputContext) {
cases.addDebugSafety("calling panic",
\\pub fn panic(message: []const u8) -> noreturn {
\\ @breakpoint();
\\ while (true) {}
\\ @import("std").os.exit(126);
\\}
\\pub fn main() -> %void {
\\ @panic("oh no");
Expand All @@ -13,8 +12,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

cases.addDebugSafety("@alignCast misaligned",
\\pub fn panic(message: []const u8) -> noreturn {
\\ @breakpoint();
\\ while (true) {}
\\ @import("std").os.exit(126);
\\}
\\error Wrong;
\\pub fn main() -> %void {
Expand Down
22 changes: 11 additions & 11 deletions test/tests.zig
Expand Up @@ -324,23 +324,23 @@ pub const CompareOutputContext = struct {
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
};

const debug_trap_signal: i32 = 5;
const expected_exit_code: i32 = 126;
switch (term) {
Term.Exited => |code| {
%%io.stderr.printf("\nProgram expected to hit debug trap (signal {}) " ++
"but exited with return code {}\n", debug_trap_signal, code);
return error.TestFailed;
},
Term.Signal => |sig| {
if (sig != debug_trap_signal) {
%%io.stderr.printf("\nProgram expected to hit debug trap (signal {}) " ++
"but instead signaled {}\n", debug_trap_signal, sig);
if (code != expected_exit_code) {
%%io.stderr.printf("\nProgram expected to exit with code {} " ++
"but exited with code {}\n", expected_exit_code, code);
return error.TestFailed;
}
},
Term.Signal => |sig| {
%%io.stderr.printf("\nProgram expected to exit with code {} " ++
"but instead signaled {}\n", expected_exit_code, sig);
return error.TestFailed;
},
else => {
%%io.stderr.printf("\nProgram expected to hit debug trap (signal {}) " ++
" but exited in an unexpected way\n", debug_trap_signal);
%%io.stderr.printf("\nProgram expected to exit with code {}" ++
" but exited in an unexpected way\n", expected_exit_code);
return error.TestFailed;
},
}
Expand Down

0 comments on commit 78b753a

Please sign in to comment.