aboutsummaryrefslogtreecommitdiff
path: root/test/incremental/change_panic_handler
blob: 070384887a21e5d068e0515192a2f05a2a1971d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#target=x86_64-linux-selfhosted
#target=x86_64-windows-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 = std.debug.FullPanic(myPanic);
fn myPanic(msg: []const u8, _: ?usize) noreturn {
    var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
    stdout_writer.interface.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 = std.debug.FullPanic(myPanic);
fn myPanic(msg: []const u8, _: ?usize) noreturn {
    var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
    stdout_writer.interface.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 = std.debug.FullPanic(myPanicNew);
fn myPanicNew(msg: []const u8, _: ?usize) noreturn {
    var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
    stdout_writer.interface.print("third panic message: {s}\n", .{msg}) catch {};
    std.process.exit(0);
}
const std = @import("std");
#expect_stdout="third panic message: integer overflow\n"