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