| ... | @@ -56,6 +56,12 @@ pub const TestContext = struct { | ... | @@ -56,6 +56,12 @@ pub const TestContext = struct { |
| 56 | }, | 56 | }, |
| 57 | }; | 57 | }; |
| 58 | | 58 | |
| | 59 | pub const File = struct { |
| | 60 | /// Contents of the importable file. Doesn't yet support incremental updates. |
| | 61 | src: [:0]const u8, |
| | 62 | path: []const u8, |
| | 63 | }; |
| | 64 | |
| 59 | pub const TestType = enum { | 65 | pub const TestType = enum { |
| 60 | Zig, | 66 | Zig, |
| 61 | ZIR, | 67 | ZIR, |
| ... | @@ -78,6 +84,8 @@ pub const TestContext = struct { | ... | @@ -78,6 +84,8 @@ pub const TestContext = struct { |
| 78 | extension: TestType, | 84 | extension: TestType, |
| 79 | cbe: bool = false, | 85 | cbe: bool = false, |
| 80 | | 86 | |
| | 87 | files: std.ArrayList(File), |
| | 88 | |
| 81 | /// Adds a subcase in which the module is updated with `src`, and the | 89 | /// Adds a subcase in which the module is updated with `src`, and the |
| 82 | /// resulting ZIR is validated against `result`. | 90 | /// resulting ZIR is validated against `result`. |
| 83 | pub fn addTransform(self: *Case, src: [:0]const u8, result: [:0]const u8) void { | 91 | pub fn addTransform(self: *Case, src: [:0]const u8, result: [:0]const u8) void { |
| ... | @@ -156,6 +164,7 @@ pub const TestContext = struct { | ... | @@ -156,6 +164,7 @@ pub const TestContext = struct { |
| 156 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), | 164 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), |
| 157 | .output_mode = .Exe, | 165 | .output_mode = .Exe, |
| 158 | .extension = T, | 166 | .extension = T, |
| | 167 | .files = std.ArrayList(File).init(ctx.cases.allocator), |
| 159 | }) catch unreachable; | 168 | }) catch unreachable; |
| 160 | return &ctx.cases.items[ctx.cases.items.len - 1]; | 169 | return &ctx.cases.items[ctx.cases.items.len - 1]; |
| 161 | } | 170 | } |
| ... | @@ -182,6 +191,7 @@ pub const TestContext = struct { | ... | @@ -182,6 +191,7 @@ pub const TestContext = struct { |
| 182 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), | 191 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), |
| 183 | .output_mode = .Obj, | 192 | .output_mode = .Obj, |
| 184 | .extension = T, | 193 | .extension = T, |
| | 194 | .files = std.ArrayList(File).init(ctx.cases.allocator), |
| 185 | }) catch unreachable; | 195 | }) catch unreachable; |
| 186 | return &ctx.cases.items[ctx.cases.items.len - 1]; | 196 | return &ctx.cases.items[ctx.cases.items.len - 1]; |
| 187 | } | 197 | } |
| ... | @@ -204,6 +214,7 @@ pub const TestContext = struct { | ... | @@ -204,6 +214,7 @@ pub const TestContext = struct { |
| 204 | .output_mode = .Obj, | 214 | .output_mode = .Obj, |
| 205 | .extension = T, | 215 | .extension = T, |
| 206 | .cbe = true, | 216 | .cbe = true, |
| | 217 | .files = std.ArrayList(File).init(ctx.cases.allocator), |
| 207 | }) catch unreachable; | 218 | }) catch unreachable; |
| 208 | return &ctx.cases.items[ctx.cases.items.len - 1]; | 219 | return &ctx.cases.items[ctx.cases.items.len - 1]; |
| 209 | } | 220 | } |
| ... | @@ -505,6 +516,10 @@ pub const TestContext = struct { | ... | @@ -505,6 +516,10 @@ pub const TestContext = struct { |
| 505 | }); | 516 | }); |
| 506 | defer comp.destroy(); | 517 | defer comp.destroy(); |
| 507 | | 518 | |
| | 519 | for (case.files.items) |file| { |
| | 520 | try tmp.dir.writeFile(file.path, file.src); |
| | 521 | } |
| | 522 | |
| 508 | for (case.updates.items) |update, update_index| { | 523 | for (case.updates.items) |update, update_index| { |
| 509 | var update_node = root_node.start("update", 3); | 524 | var update_node = root_node.start("update", 3); |
| 510 | update_node.activate(); | 525 | update_node.activate(); |