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