diff --git a/src-self-hosted/test.zig b/src-self-hosted/test.zig index 78bdcddf71..4cf72ce481 100644 --- a/src-self-hosted/test.zig +++ b/src-self-hosted/test.zig @@ -6,8 +6,7 @@ const zir = @import("zir.zig"); const Package = @import("Package.zig"); test "self-hosted" { - var ctx: TestContext = undefined; - try ctx.init(); + var ctx = TestContext.init(); defer ctx.deinit(); try @import("stage2_tests").addCases(&ctx); @@ -93,10 +92,11 @@ pub const TestContext = struct { name: []const u8, /// The platform the ZIR targets. For non-native platforms, an emulator /// such as QEMU is required for tests to complete. - /// target: std.zig.CrossTarget, updates: std.ArrayList(ZIRUpdate), + /// Adds a subcase in which the module is updated with new ZIR, and the + /// resulting ZIR is validated. pub fn addTransform(self: *ZIRCase, src: [:0]const u8, result: [:0]const u8) void { self.updates.append(.{ .src = src, @@ -104,9 +104,10 @@ pub const TestContext = struct { }) catch unreachable; } - /// TODO: document + /// Adds a subcase in which the module is updated with invalid ZIR, and + /// ensures that compilation fails for the expected reasons. /// - /// Errors must be specified in sequential order + /// Errors must be specified in sequential order. pub fn addError(self: *ZIRCase, src: [:0]const u8, errors: []const []const u8) void { var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch unreachable; for (errors) |e, i| { @@ -194,9 +195,9 @@ pub const TestContext = struct { c.addError(src, expected_errors); } - fn init(self: *TestContext) !void { + fn init() TestContext { const allocator = std.heap.page_allocator; - self.* = .{ + return .{ .zir_cmp_output_cases = std.ArrayList(ZIRCompareOutputCase).init(allocator), .zir_cases = std.ArrayList(ZIRCase).init(allocator), }; @@ -267,10 +268,7 @@ pub const TestContext = struct { }); defer module.deinit(); - for (case.updates.items) |s| { - // TODO: remove before committing. This is for ZLS ;) - const update: ZIRUpdate = s; - + for (case.updates.items) |update| { var update_node = prg_node.start("update", 4); update_node.activate(); defer update_node.end(); diff --git a/test/stage2/compile_errors.zig b/test/stage2/compile_errors.zig index 5484b6459a..43c41aa364 100644 --- a/test/stage2/compile_errors.zig +++ b/test/stage2/compile_errors.zig @@ -9,8 +9,6 @@ const linux_x64 = std.zig.CrossTarget{ }; pub fn addCases(ctx: *TestContext) !void { - // TODO: re-enable these tests. - // https://github.com/ziglang/zig/issues/1364 ctx.addZIRError("call undefined local", linux_x64, \\@noreturn = primitive(noreturn) \\ @@ -47,6 +45,10 @@ pub fn addCases(ctx: *TestContext) !void { \\@2 = export(@1, @start) , &[_][]const u8{":4:9: error: unable to call function with naked calling convention"}); + // TODO: re-enable these tests. + // https://github.com/ziglang/zig/issues/1364 + // TODO: add Zig AST -> ZIR testing pipeline + //try ctx.testCompileError( // \\export fn entry() void {} // \\export fn entry() void {}