diff --git a/build.zig b/build.zig index cc0405c21a8481fa0d3aa58306615032a5a4fdc6..f8c095e8250f4c48a62a403537d8c3425eb1abc8 100644 --- a/build.zig +++ b/build.zig @@ -138,13 +138,13 @@ pub fn build(b: *Builder) !void { test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes)); test_step.dependOn(tests.addStandaloneTests(b, test_filter, modes)); - test_step.dependOn(tests.addComparePanicTests(b, test_filter, modes)); + test_step.dependOn(tests.addCompareStackTracesTests(b, test_filter, modes)); test_step.dependOn(tests.addCliTests(b, test_filter, modes)); - test_step.dependOn(tests.addCompileErrorTests(b, test_filter, modes)); test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes)); test_step.dependOn(tests.addRuntimeSafetyTests(b, test_filter, modes)); test_step.dependOn(tests.addTranslateCTests(b, test_filter)); test_step.dependOn(tests.addGenHTests(b, test_filter)); + test_step.dependOn(tests.addCompileErrorTests(b, test_filter, modes)); test_step.dependOn(docs_step); } diff --git a/test/compare_panic.zig b/test/compare_panic.zig deleted file mode 100644 index 3c71b9626a97b947e1615cc717b86808fa5aa264..0000000000000000000000000000000000000000 --- a/test/compare_panic.zig +++ /dev/null @@ -1,277 +0,0 @@ -const builtin = @import("builtin"); -const std = @import("std"); -const os = std.os; -const tests = @import("tests.zig"); - -pub fn addCases(cases: *tests.ComparePanicContext) void { - const source_return = - \\const std = @import("std"); - \\ - \\pub fn main() !void { - \\ return error.TheSkyIsFalling; - \\} - ; - const source_try_return = - \\const std = @import("std"); - \\ - \\fn foo() !void { - \\ return error.TheSkyIsFalling; - \\} - \\ - \\pub fn main() !void { - \\ try foo(); - \\} - ; - const source_try_try_return_return = - \\const std = @import("std"); - \\ - \\fn foo() !void { - \\ try bar(); - \\} - \\ - \\fn bar() !void { - \\ return make_error(); - \\} - \\ - \\fn make_error() !void { - \\ return error.TheSkyIsFalling; - \\} - \\ - \\pub fn main() !void { - \\ try foo(); - \\} - ; - switch (builtin.os) { - .linux => { - cases.addCase( - "return", - source_return, - [][]const u8{ - // debug - \\error: TheSkyIsFalling - \\source.zig:4:5: [address] in main (test) - \\ - , - // release-safe - \\error: TheSkyIsFalling - \\source.zig:4:5: [address] in std.special.posixCallMainAndExit (test) - \\ - , - // release-fast - \\error: TheSkyIsFalling - \\ - , - // release-small - \\error: TheSkyIsFalling - \\ - }, - ); - cases.addCase( - "try return", - source_try_return, - [][]const u8{ - // debug - \\error: TheSkyIsFalling - \\source.zig:4:5: [address] in foo (test) - \\source.zig:8:5: [address] in main (test) - \\ - , - // release-safe - \\error: TheSkyIsFalling - \\source.zig:4:5: [address] in std.special.posixCallMainAndExit (test) - \\source.zig:8:5: [address] in std.special.posixCallMainAndExit (test) - \\ - , - // release-fast - \\error: TheSkyIsFalling - \\ - , - // release-small - \\error: TheSkyIsFalling - \\ - }, - ); - cases.addCase( - "try try return return", - source_try_try_return_return, - [][]const u8{ - // debug - \\error: TheSkyIsFalling - \\source.zig:12:5: [address] in make_error (test) - \\source.zig:8:5: [address] in bar (test) - \\source.zig:4:5: [address] in foo (test) - \\source.zig:16:5: [address] in main (test) - \\ - , - // release-safe - \\error: TheSkyIsFalling - \\source.zig:12:5: [address] in std.special.posixCallMainAndExit (test) - \\source.zig:8:5: [address] in std.special.posixCallMainAndExit (test) - \\source.zig:4:5: [address] in std.special.posixCallMainAndExit (test) - \\source.zig:16:5: [address] in std.special.posixCallMainAndExit (test) - \\ - , - // release-fast - \\error: TheSkyIsFalling - \\ - , - // release-small - \\error: TheSkyIsFalling - \\ - }, - ); - }, - .macosx => { - cases.addCase( - "return", - source_return, - [][]const u8{ - // debug - \\error: TheSkyIsFalling - \\source.zig:4:5: [address] in _main.0 (test.o) - \\ - , - // release-safe - \\error: TheSkyIsFalling - \\source.zig:4:5: [address] in _main (test.o) - \\ - , - // release-fast - \\error: TheSkyIsFalling - \\ - , - // release-small - \\error: TheSkyIsFalling - \\ - }, - ); - cases.addCase( - "try return", - source_try_return, - [][]const u8{ - // debug - \\error: TheSkyIsFalling - \\source.zig:4:5: [address] in _foo (test.o) - \\source.zig:8:5: [address] in _main.0 (test.o) - \\ - , - // release-safe - \\error: TheSkyIsFalling - \\source.zig:4:5: [address] in _main (test.o) - \\source.zig:8:5: [address] in _main (test.o) - \\ - , - // release-fast - \\error: TheSkyIsFalling - \\ - , - // release-small - \\error: TheSkyIsFalling - \\ - }, - ); - cases.addCase( - "try try return return", - source_try_try_return_return, - [][]const u8{ - // debug - \\error: TheSkyIsFalling - \\source.zig:12:5: [address] in _make_error (test.o) - \\source.zig:8:5: [address] in _bar (test.o) - \\source.zig:4:5: [address] in _foo (test.o) - \\source.zig:16:5: [address] in _main.0 (test.o) - \\ - , - // release-safe - \\error: TheSkyIsFalling - \\source.zig:12:5: [address] in _main (test.o) - \\source.zig:8:5: [address] in _main (test.o) - \\source.zig:4:5: [address] in _main (test.o) - \\source.zig:16:5: [address] in _main (test.o) - \\ - , - // release-fast - \\error: TheSkyIsFalling - \\ - , - // release-small - \\error: TheSkyIsFalling - \\ - }, - ); - }, - .windows => { - cases.addCase( - "return", - source_return, - [][]const u8{ - // debug - \\error: TheSkyIsFalling - \\source.zig:4:5: [address] in main (test.obj) - \\ - , - // release-safe - // --disabled-- results in segmenetation fault - "" - , - // release-fast - \\error: TheSkyIsFalling - \\ - , - // release-small - \\error: TheSkyIsFalling - \\ - }, - ); - cases.addCase( - "try return", - source_try_return, - [][]const u8{ - // debug - \\error: TheSkyIsFalling - \\source.zig:4:5: [address] in foo (test.obj) - \\source.zig:8:5: [address] in main (test.obj) - \\ - , - // release-safe - // --disabled-- results in segmenetation fault - "" - , - // release-fast - \\error: TheSkyIsFalling - \\ - , - // release-small - \\error: TheSkyIsFalling - \\ - }, - ); - cases.addCase( - "try try return return", - source_try_try_return_return, - [][]const u8{ - // debug - \\error: TheSkyIsFalling - \\source.zig:12:5: [address] in make_error (test.obj) - \\source.zig:8:5: [address] in bar (test.obj) - \\source.zig:4:5: [address] in foo (test.obj) - \\source.zig:16:5: [address] in main (test.obj) - \\ - , - // release-safe - // --disabled-- results in segmenetation fault - "" - , - // release-fast - \\error: TheSkyIsFalling - \\ - , - // release-small - \\error: TheSkyIsFalling - \\ - }, - ); - }, - else => {}, - } -} diff --git a/test/compare_traces.zig b/test/compare_traces.zig new file mode 100644 index 0000000000000000000000000000000000000000..3de0fb680a650aa080064935effc55f90326d491 --- /dev/null +++ b/test/compare_traces.zig @@ -0,0 +1,274 @@ +const builtin = @import("builtin"); +const std = @import("std"); +const os = std.os; +const tests = @import("tests.zig"); + +pub fn addCases(cases: *tests.CompareStackTracesContext) void { + const source_return = + \\const std = @import("std"); + \\ + \\pub fn main() !void { + \\ return error.TheSkyIsFalling; + \\} + ; + const source_try_return = + \\const std = @import("std"); + \\ + \\fn foo() !void { + \\ return error.TheSkyIsFalling; + \\} + \\ + \\pub fn main() !void { + \\ try foo(); + \\} + ; + const source_try_try_return_return = + \\const std = @import("std"); + \\ + \\fn foo() !void { + \\ try bar(); + \\} + \\ + \\fn bar() !void { + \\ return make_error(); + \\} + \\ + \\fn make_error() !void { + \\ return error.TheSkyIsFalling; + \\} + \\ + \\pub fn main() !void { + \\ try foo(); + \\} + ; + switch (builtin.os) { + .linux => { + cases.addCase( + "return", + source_return, + [_][]const u8{ + // debug + \\error: TheSkyIsFalling + \\source.zig:4:5: [address] in main (test) + \\ + , + // release-safe + \\error: TheSkyIsFalling + \\source.zig:4:5: [address] in std.special.posixCallMainAndExit (test) + \\ + , + // release-fast + \\error: TheSkyIsFalling + \\ + , + // release-small + \\error: TheSkyIsFalling + \\ + }, + ); + cases.addCase( + "try return", + source_try_return, + [_][]const u8{ + // debug + \\error: TheSkyIsFalling + \\source.zig:4:5: [address] in foo (test) + \\source.zig:8:5: [address] in main (test) + \\ + , + // release-safe + \\error: TheSkyIsFalling + \\source.zig:4:5: [address] in std.special.posixCallMainAndExit (test) + \\source.zig:8:5: [address] in std.special.posixCallMainAndExit (test) + \\ + , + // release-fast + \\error: TheSkyIsFalling + \\ + , + // release-small + \\error: TheSkyIsFalling + \\ + }, + ); + cases.addCase( + "try try return return", + source_try_try_return_return, + [_][]const u8{ + // debug + \\error: TheSkyIsFalling + \\source.zig:12:5: [address] in make_error (test) + \\source.zig:8:5: [address] in bar (test) + \\source.zig:4:5: [address] in foo (test) + \\source.zig:16:5: [address] in main (test) + \\ + , + // release-safe + \\error: TheSkyIsFalling + \\source.zig:12:5: [address] in std.special.posixCallMainAndExit (test) + \\source.zig:8:5: [address] in std.special.posixCallMainAndExit (test) + \\source.zig:4:5: [address] in std.special.posixCallMainAndExit (test) + \\source.zig:16:5: [address] in std.special.posixCallMainAndExit (test) + \\ + , + // release-fast + \\error: TheSkyIsFalling + \\ + , + // release-small + \\error: TheSkyIsFalling + \\ + }, + ); + }, + .macosx => { + cases.addCase( + "return", + source_return, + [_][]const u8{ + // debug + \\error: TheSkyIsFalling + \\source.zig:4:5: [address] in _main.0 (test.o) + \\ + , + // release-safe + \\error: TheSkyIsFalling + \\source.zig:4:5: [address] in _main (test.o) + \\ + , + // release-fast + \\error: TheSkyIsFalling + \\ + , + // release-small + \\error: TheSkyIsFalling + \\ + }, + ); + cases.addCase( + "try return", + source_try_return, + [_][]const u8{ + // debug + \\error: TheSkyIsFalling + \\source.zig:4:5: [address] in _foo (test.o) + \\source.zig:8:5: [address] in _main.0 (test.o) + \\ + , + // release-safe + \\error: TheSkyIsFalling + \\source.zig:4:5: [address] in _main (test.o) + \\source.zig:8:5: [address] in _main (test.o) + \\ + , + // release-fast + \\error: TheSkyIsFalling + \\ + , + // release-small + \\error: TheSkyIsFalling + \\ + }, + ); + cases.addCase( + "try try return return", + source_try_try_return_return, + [_][]const u8{ + // debug + \\error: TheSkyIsFalling + \\source.zig:12:5: [address] in _make_error (test.o) + \\source.zig:8:5: [address] in _bar (test.o) + \\source.zig:4:5: [address] in _foo (test.o) + \\source.zig:16:5: [address] in _main.0 (test.o) + \\ + , + // release-safe + \\error: TheSkyIsFalling + \\source.zig:12:5: [address] in _main (test.o) + \\source.zig:8:5: [address] in _main (test.o) + \\source.zig:4:5: [address] in _main (test.o) + \\source.zig:16:5: [address] in _main (test.o) + \\ + , + // release-fast + \\error: TheSkyIsFalling + \\ + , + // release-small + \\error: TheSkyIsFalling + \\ + }, + ); + }, + .windows => { + cases.addCase( + "return", + source_return, + [_][]const u8{ + // debug + \\error: TheSkyIsFalling + \\source.zig:4:5: [address] in main (test.obj) + \\ + , + // release-safe + // --disabled-- results in segmenetation fault + "", + // release-fast + \\error: TheSkyIsFalling + \\ + , + // release-small + \\error: TheSkyIsFalling + \\ + }, + ); + cases.addCase( + "try return", + source_try_return, + [_][]const u8{ + // debug + \\error: TheSkyIsFalling + \\source.zig:4:5: [address] in foo (test.obj) + \\source.zig:8:5: [address] in main (test.obj) + \\ + , + // release-safe + // --disabled-- results in segmenetation fault + "", + // release-fast + \\error: TheSkyIsFalling + \\ + , + // release-small + \\error: TheSkyIsFalling + \\ + }, + ); + cases.addCase( + "try try return return", + source_try_try_return_return, + [_][]const u8{ + // debug + \\error: TheSkyIsFalling + \\source.zig:12:5: [address] in make_error (test.obj) + \\source.zig:8:5: [address] in bar (test.obj) + \\source.zig:4:5: [address] in foo (test.obj) + \\source.zig:16:5: [address] in main (test.obj) + \\ + , + // release-safe + // --disabled-- results in segmenetation fault + "", + // release-fast + \\error: TheSkyIsFalling + \\ + , + // release-small + \\error: TheSkyIsFalling + \\ + }, + ); + }, + else => {}, + } +} diff --git a/test/tests.zig b/test/tests.zig index 1bb9e417e5ab41f6f5c0053571726000b0b19953..754407df9a8aaae633b98b275a1923922e103d33 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -16,7 +16,7 @@ const LibExeObjStep = build.LibExeObjStep; const compare_output = @import("compare_output.zig"); const standalone = @import("standalone.zig"); -const compare_panic = @import("compare_panic.zig"); +const compare_panic = @import("compare_traces.zig"); const compile_errors = @import("compile_errors.zig"); const assemble_and_link = @import("assemble_and_link.zig"); const runtime_safety = @import("runtime_safety.zig"); @@ -58,11 +58,11 @@ pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8, modes: return cases.step; } -pub fn addComparePanicTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { - const cases = b.allocator.create(ComparePanicContext) catch unreachable; - cases.* = ComparePanicContext{ +pub fn addCompareStackTracesTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { + const cases = b.allocator.create(CompareStackTracesContext) catch unreachable; + cases.* = CompareStackTracesContext{ .b = b, - .step = b.step("test-compare-panic", "Run the compare panic tests"), + .step = b.step("test-compare-traces", "Run the compare stack traces tests"), .test_index = 0, .test_filter = test_filter, .modes = modes, @@ -565,7 +565,7 @@ pub const CompareOutputContext = struct { } }; -pub const ComparePanicContext = struct { +pub const CompareStackTracesContext = struct { b: *build.Builder, step: *build.Step, test_index: usize, @@ -575,7 +575,7 @@ pub const ComparePanicContext = struct { const Expect = [@typeInfo(Mode).Enum.fields.len][]const u8; pub fn addCase( - self: *ComparePanicContext, + self: *CompareStackTracesContext, name: []const u8, source: []const u8, expect: Expect, @@ -584,14 +584,14 @@ pub const ComparePanicContext = struct { const source_pathname = fs.path.join( b.allocator, - [][]const u8{ b.cache_root, "source.zig" }, + [_][]const u8{ b.cache_root, "source.zig" }, ) catch unreachable; for (self.modes) |mode| { const expect_for_mode = expect[@enumToInt(mode)]; if (expect_for_mode.len == 0) continue; - const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", "compare-panic", name, @tagName(mode)) catch unreachable; + const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", "compare-stack-traces", name, @tagName(mode)) catch unreachable; if (self.test_filter) |filter| { if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; } @@ -616,7 +616,7 @@ pub const ComparePanicContext = struct { const RunAndCompareStep = struct { step: build.Step, - context: *ComparePanicContext, + context: *CompareStackTracesContext, exe: *LibExeObjStep, name: []const u8, mode: Mode, @@ -624,7 +624,7 @@ pub const ComparePanicContext = struct { test_index: usize, pub fn create( - context: *ComparePanicContext, + context: *CompareStackTracesContext, exe: *LibExeObjStep, name: []const u8, mode: Mode, @@ -633,7 +633,7 @@ pub const ComparePanicContext = struct { const allocator = context.b.allocator; const ptr = allocator.create(RunAndCompareStep) catch unreachable; ptr.* = RunAndCompareStep{ - .step = build.Step.init("PanicCompareOutputStep", allocator, make), + .step = build.Step.init("StackTraceCompareOutputStep", allocator, make), .context = context, .exe = exe, .name = name, @@ -718,8 +718,8 @@ pub const ComparePanicContext = struct { var it = mem.separate(bytes, "\n"); process_lines: while (it.next()) |line| { if (line.len == 0) continue; - const delims = []const []const u8{ ":", ":", ":", " in " }; - var marks = []usize{0} ** 4; + const delims = [_][]const u8{ ":", ":", ":", " in " }; + var marks = [_]usize{0} ** 4; // offset search past `[drive]:` on windows var pos: usize = if (builtin.os == .windows) 2 else 0; for (delims) |delim, i| {