mirror of
https://github.com/ziglang/zig.git
synced 2025-12-15 02:33:07 +00:00
parent
d6bfa3f639
commit
78b753af9d
@ -3,8 +3,7 @@ const tests = @import("tests.zig");
|
|||||||
pub fn addCases(cases: &tests.CompareOutputContext) {
|
pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||||
cases.addDebugSafety("calling panic",
|
cases.addDebugSafety("calling panic",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
\\ @panic("oh no");
|
\\ @panic("oh no");
|
||||||
@ -13,8 +12,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("out of bounds slice access",
|
cases.addDebugSafety("out of bounds slice access",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
\\ const a = []i32{1, 2, 3, 4};
|
\\ const a = []i32{1, 2, 3, 4};
|
||||||
@ -28,8 +26,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("integer addition overflow",
|
cases.addDebugSafety("integer addition overflow",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -43,8 +40,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("integer subtraction overflow",
|
cases.addDebugSafety("integer subtraction overflow",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -58,8 +54,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("integer multiplication overflow",
|
cases.addDebugSafety("integer multiplication overflow",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -73,8 +68,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("integer negation overflow",
|
cases.addDebugSafety("integer negation overflow",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -88,8 +82,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("signed integer division overflow",
|
cases.addDebugSafety("signed integer division overflow",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -103,8 +96,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("signed shift left overflow",
|
cases.addDebugSafety("signed shift left overflow",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -118,8 +110,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("unsigned shift left overflow",
|
cases.addDebugSafety("unsigned shift left overflow",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -133,8 +124,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("signed shift right overflow",
|
cases.addDebugSafety("signed shift right overflow",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -148,8 +138,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("unsigned shift right overflow",
|
cases.addDebugSafety("unsigned shift right overflow",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -163,8 +152,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("integer division by zero",
|
cases.addDebugSafety("integer division by zero",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -177,8 +165,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("exact division failure",
|
cases.addDebugSafety("exact division failure",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -192,8 +179,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("cast []u8 to bigger slice of wrong size",
|
cases.addDebugSafety("cast []u8 to bigger slice of wrong size",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -207,8 +193,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("value does not fit in shortening cast",
|
cases.addDebugSafety("value does not fit in shortening cast",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -222,8 +207,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("signed integer not fitting in cast to unsigned integer",
|
cases.addDebugSafety("signed integer not fitting in cast to unsigned integer",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -237,8 +221,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("unwrap error",
|
cases.addDebugSafety("unwrap error",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Whatever;
|
\\error Whatever;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
@ -251,8 +234,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("cast integer to error and no code matches",
|
cases.addDebugSafety("cast integer to error and no code matches",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
\\ _ = bar(9999);
|
\\ _ = bar(9999);
|
||||||
@ -264,8 +246,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
|||||||
|
|
||||||
cases.addDebugSafety("@alignCast misaligned",
|
cases.addDebugSafety("@alignCast misaligned",
|
||||||
\\pub fn panic(message: []const u8) -> noreturn {
|
\\pub fn panic(message: []const u8) -> noreturn {
|
||||||
\\ @breakpoint();
|
\\ @import("std").os.exit(126);
|
||||||
\\ while (true) {}
|
|
||||||
\\}
|
\\}
|
||||||
\\error Wrong;
|
\\error Wrong;
|
||||||
\\pub fn main() -> %void {
|
\\pub fn main() -> %void {
|
||||||
|
|||||||
@ -324,23 +324,23 @@ pub const CompareOutputContext = struct {
|
|||||||
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
|
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) {
|
switch (term) {
|
||||||
Term.Exited => |code| {
|
Term.Exited => |code| {
|
||||||
%%io.stderr.printf("\nProgram expected to hit debug trap (signal {}) " ++
|
if (code != expected_exit_code) {
|
||||||
"but exited with return code {}\n", debug_trap_signal, code);
|
%%io.stderr.printf("\nProgram expected to exit with code {} " ++
|
||||||
return error.TestFailed;
|
"but exited with code {}\n", expected_exit_code, code);
|
||||||
},
|
|
||||||
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);
|
|
||||||
return error.TestFailed;
|
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 => {
|
else => {
|
||||||
%%io.stderr.printf("\nProgram expected to hit debug trap (signal {}) " ++
|
%%io.stderr.printf("\nProgram expected to exit with code {}" ++
|
||||||
" but exited in an unexpected way\n", debug_trap_signal);
|
" but exited in an unexpected way\n", expected_exit_code);
|
||||||
return error.TestFailed;
|
return error.TestFailed;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user