From 6cc848e9f6c86184030fd4c9bc7c09ce90dd5cf9 Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 4 Jan 2025 05:16:16 +0000 Subject: [PATCH] incremental: add new test cases These cover the fixes from the last few commits. --- test/incremental/change_panic_handler | 74 ++++++++++++++++++++++++++ test/incremental/temporary_parse_error | 18 +++++++ 2 files changed, 92 insertions(+) create mode 100644 test/incremental/change_panic_handler create mode 100644 test/incremental/temporary_parse_error diff --git a/test/incremental/change_panic_handler b/test/incremental/change_panic_handler new file mode 100644 index 0000000000..bab6eab793 --- /dev/null +++ b/test/incremental/change_panic_handler @@ -0,0 +1,74 @@ +#target=x86_64-linux-selfhosted +#target=x86_64-linux-cbe +#target=x86_64-windows-cbe +#update=initial version +#file=main.zig +pub fn main() !u8 { + var a: u8 = undefined; + a = 255; + _ = a + 1; + return 1; +} +pub const Panic = struct { + pub const call = myPanic; + pub const sentinelMismatch = std.debug.FormattedPanic.sentinelMismatch; + pub const unwrapError = std.debug.FormattedPanic.unwrapError; + pub const outOfBounds = std.debug.FormattedPanic.outOfBounds; + pub const startGreaterThanEnd = std.debug.FormattedPanic.startGreaterThanEnd; + pub const inactiveUnionField = std.debug.FormattedPanic.inactiveUnionField; + pub const messages = std.debug.FormattedPanic.messages; +}; +fn myPanic(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { + std.io.getStdOut().writer().print("panic message: {s}\n", .{msg}) catch {}; + std.process.exit(0); +} +const std = @import("std"); +#expect_stdout="panic message: integer overflow\n" + +#update=change the panic handler body +#file=main.zig +pub fn main() !u8 { + var a: u8 = undefined; + a = 255; + _ = a + 1; + return 1; +} +pub const Panic = struct { + pub const call = myPanic; + pub const sentinelMismatch = std.debug.FormattedPanic.sentinelMismatch; + pub const unwrapError = std.debug.FormattedPanic.unwrapError; + pub const outOfBounds = std.debug.FormattedPanic.outOfBounds; + pub const startGreaterThanEnd = std.debug.FormattedPanic.startGreaterThanEnd; + pub const inactiveUnionField = std.debug.FormattedPanic.inactiveUnionField; + pub const messages = std.debug.FormattedPanic.messages; +}; +fn myPanic(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { + std.io.getStdOut().writer().print("new panic message: {s}\n", .{msg}) catch {}; + std.process.exit(0); +} +const std = @import("std"); +#expect_stdout="new panic message: integer overflow\n" + +#update=change the panic handler function value +#file=main.zig +pub fn main() !u8 { + var a: u8 = undefined; + a = 255; + _ = a + 1; + return 1; +} +pub const Panic = struct { + pub const call = myPanicNew; + pub const sentinelMismatch = std.debug.FormattedPanic.sentinelMismatch; + pub const unwrapError = std.debug.FormattedPanic.unwrapError; + pub const outOfBounds = std.debug.FormattedPanic.outOfBounds; + pub const startGreaterThanEnd = std.debug.FormattedPanic.startGreaterThanEnd; + pub const inactiveUnionField = std.debug.FormattedPanic.inactiveUnionField; + pub const messages = std.debug.FormattedPanic.messages; +}; +fn myPanicNew(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { + std.io.getStdOut().writer().print("third panic message: {s}\n", .{msg}) catch {}; + std.process.exit(0); +} +const std = @import("std"); +#expect_stdout="third panic message: integer overflow\n" diff --git a/test/incremental/temporary_parse_error b/test/incremental/temporary_parse_error new file mode 100644 index 0000000000..4668c53b32 --- /dev/null +++ b/test/incremental/temporary_parse_error @@ -0,0 +1,18 @@ +#target=x86_64-linux-selfhosted +#target=x86_64-linux-cbe +#target=x86_64-windows-cbe +#update=initial version +#file=main.zig +const std = @import("std"); +pub fn main() !void {} +#expect_stdout="" + +#update=introduce parse error +#file=main.zig +pub fn main() !void { +#expect_error=ignored + +#update=fix parse error +#file=main.zig +pub fn main() !void {} +#expect_stdout=""