| ... | @@ -6,8 +6,7 @@ const zir = @import("zir.zig"); | ... | @@ -6,8 +6,7 @@ const zir = @import("zir.zig"); |
| 6 | const Package = @import("Package.zig"); | 6 | const Package = @import("Package.zig"); |
| 7 | | 7 | |
| 8 | test "self-hosted" { | 8 | test "self-hosted" { |
| 9 | var ctx: TestContext = undefined; | 9 | var ctx = TestContext.init(); |
| 10 | try ctx.init(); | | |
| 11 | defer ctx.deinit(); | 10 | defer ctx.deinit(); |
| 12 | | 11 | |
| 13 | try @import("stage2_tests").addCases(&ctx); | 12 | try @import("stage2_tests").addCases(&ctx); |
| ... | @@ -93,10 +92,11 @@ pub const TestContext = struct { | ... | @@ -93,10 +92,11 @@ pub const TestContext = struct { |
| 93 | name: []const u8, | 92 | name: []const u8, |
| 94 | /// The platform the ZIR targets. For non-native platforms, an emulator | 93 | /// The platform the ZIR targets. For non-native platforms, an emulator |
| 95 | /// such as QEMU is required for tests to complete. | 94 | /// such as QEMU is required for tests to complete. |
| 96 | /// | | |
| 97 | target: std.zig.CrossTarget, | 95 | target: std.zig.CrossTarget, |
| 98 | updates: std.ArrayList(ZIRUpdate), | 96 | updates: std.ArrayList(ZIRUpdate), |
| 99 | | 97 | |
| | 98 | /// Adds a subcase in which the module is updated with new ZIR, and the |
| | 99 | /// resulting ZIR is validated. |
| 100 | pub fn addTransform(self: *ZIRCase, src: [:0]const u8, result: [:0]const u8) void { | 100 | pub fn addTransform(self: *ZIRCase, src: [:0]const u8, result: [:0]const u8) void { |
| 101 | self.updates.append(.{ | 101 | self.updates.append(.{ |
| 102 | .src = src, | 102 | .src = src, |
| ... | @@ -104,9 +104,10 @@ pub const TestContext = struct { | ... | @@ -104,9 +104,10 @@ pub const TestContext = struct { |
| 104 | }) catch unreachable; | 104 | }) catch unreachable; |
| 105 | } | 105 | } |
| 106 | | 106 | |
| 107 | /// TODO: document | 107 | /// Adds a subcase in which the module is updated with invalid ZIR, and |
| | 108 | /// ensures that compilation fails for the expected reasons. |
| 108 | /// | 109 | /// |
| 109 | /// Errors must be specified in sequential order | 110 | /// Errors must be specified in sequential order. |
| 110 | pub fn addError(self: *ZIRCase, src: [:0]const u8, errors: []const []const u8) void { | 111 | pub fn addError(self: *ZIRCase, src: [:0]const u8, errors: []const []const u8) void { |
| 111 | var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch unreachable; | 112 | var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch unreachable; |
| 112 | for (errors) |e, i| { | 113 | for (errors) |e, i| { |
| ... | @@ -194,9 +195,9 @@ pub const TestContext = struct { | ... | @@ -194,9 +195,9 @@ pub const TestContext = struct { |
| 194 | c.addError(src, expected_errors); | 195 | c.addError(src, expected_errors); |
| 195 | } | 196 | } |
| 196 | | 197 | |
| 197 | fn init(self: *TestContext) !void { | 198 | fn init() TestContext { |
| 198 | const allocator = std.heap.page_allocator; | 199 | const allocator = std.heap.page_allocator; |
| 199 | self.* = .{ | 200 | return .{ |
| 200 | .zir_cmp_output_cases = std.ArrayList(ZIRCompareOutputCase).init(allocator), | 201 | .zir_cmp_output_cases = std.ArrayList(ZIRCompareOutputCase).init(allocator), |
| 201 | .zir_cases = std.ArrayList(ZIRCase).init(allocator), | 202 | .zir_cases = std.ArrayList(ZIRCase).init(allocator), |
| 202 | }; | 203 | }; |
| ... | @@ -267,10 +268,7 @@ pub const TestContext = struct { | ... | @@ -267,10 +268,7 @@ pub const TestContext = struct { |
| 267 | }); | 268 | }); |
| 268 | defer module.deinit(); | 269 | defer module.deinit(); |
| 269 | | 270 | |
| 270 | for (case.updates.items) |s| { | 271 | for (case.updates.items) |update| { |
| 271 | // TODO: remove before committing. This is for ZLS ;) | | |
| 272 | const update: ZIRUpdate = s; | | |
| 273 | | | |
| 274 | var update_node = prg_node.start("update", 4); | 272 | var update_node = prg_node.start("update", 4); |
| 275 | update_node.activate(); | 273 | update_node.activate(); |
| 276 | defer update_node.end(); | 274 | defer update_node.end(); |