authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-14 20:55:49-04:00
committergravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-15 20:33:32-04:00
log71dca252a575a6a09e16dfc8faf8b704e847eb87
treedef217a032cfb61f408f01d61846c9c45f667f8d
parentb6bd51ed69f75930bbf9a80b5b8841d1517a6828
signature Commit is signed but in an unrecognized format.

Stage2/Testing: Rename stage -> update


1 files changed, 25 insertions(+), 25 deletions(-)

src-self-hosted/test.zig+25-25
......@@ -82,24 +82,24 @@ pub const TestContext = struct {
8282 };
8383
8484 pub const ZIRUpdateType = enum {
85 /// A transformation stage transforms the input ZIR and tests against
85 /// A transformation update transforms the input ZIR and tests against
8686 /// the expected output
8787 Transformation,
88 /// An error stage attempts to compile bad code, and ensures that it
88 /// An error update attempts to compile bad code, and ensures that it
8989 /// fails to compile, and for the expected reasons
9090 Error,
91 /// An execution stage compiles and runs the input ZIR, feeding in
91 /// An execution update compiles and runs the input ZIR, feeding in
9292 /// provided input and ensuring that the outputs match what is expected
9393 Execution,
94 /// A compilation stage checks that the ZIR compiles without any issues
94 /// A compilation update checks that the ZIR compiles without any issues
9595 Compiles,
9696 };
9797
9898 pub const ZIRUpdate = struct {
99 /// The input to the current stage. We simulate an incremental update
100 /// with the file's contents changed to this value each stage.
99 /// The input to the current update. We simulate an incremental update
100 /// with the file's contents changed to this value each update.
101101 ///
102 /// This value can change entirely between stages, which would be akin
102 /// This value can change entirely between updates, which would be akin
103103 /// to deleting the source file and creating a new one from scratch; or
104104 /// you can keep it mostly consistent, with small changes, testing the
105105 /// effects of the incremental compilation.
......@@ -114,7 +114,7 @@ pub const TestContext = struct {
114114 ///
115115 /// If stdout, stderr, and exit_code are all null, addZIRCase will
116116 /// discard the test. To test for successful compilation, use a
117 /// dedicated Compile stage instead.
117 /// dedicated Compile update instead.
118118 Execution: struct {
119119 stdin: ?[]const u8,
120120 stdout: ?[]const u8,
......@@ -131,9 +131,9 @@ pub const TestContext = struct {
131131 },
132132 };
133133
134 /// A ZIRCase consists of a set of *stages*. A stage can transform ZIR,
134 /// A ZIRCase consists of a set of *updates*. A update can transform ZIR,
135135 /// compile it, ensure that compilation fails, and more. The same Module is
136 /// used for each stage, so each stage's source is treated as a single file
136 /// used for each update, so each update's source is treated as a single file
137137 /// being updated by the test harness and incrementally compiled.
138138 pub const ZIRCase = struct {
139139 name: []const u8,
......@@ -141,19 +141,19 @@ pub const TestContext = struct {
141141 /// such as QEMU is required for tests to complete.
142142 ///
143143 target: std.zig.CrossTarget,
144 stages: []const ZIRUpdate,
144 updates: []const ZIRUpdate,
145145 };
146146
147147 pub fn addZIRCase(
148148 ctx: *TestContext,
149149 name: []const u8,
150150 target: std.zig.CrossTarget,
151 stages: []const ZIRUpdate,
151 updates: []const ZIRUpdate,
152152 ) void {
153153 const case = ZIRCase{
154154 .name = name,
155155 .target = target,
156 .stages = stages,
156 .updates = updates,
157157 };
158158 ctx.zir_cases.append(case) catch |err| std.debug.panic("Error: {}", .{err});
159159 }
......@@ -297,7 +297,7 @@ pub const TestContext = struct {
297297 const root_pkg = try Package.create(allocator, tmp.dir, ".", tmp_src_path);
298298 defer root_pkg.destroy();
299299
300 var prg_node = root_node.start(case.name, case.stages.len);
300 var prg_node = root_node.start(case.name, case.updates.len);
301301 prg_node.activate();
302302 defer prg_node.end();
303303
......@@ -318,33 +318,33 @@ pub const TestContext = struct {
318318 });
319319 defer module.deinit();
320320
321 for (case.stages) |s| {
321 for (case.updates) |s| {
322322 // TODO: remove before committing. This is for ZLS ;)
323 const stage: ZIRUpdate = s;
323 const update: ZIRUpdate = s;
324324
325 var stage_node = prg_node.start("update", 4);
326 stage_node.activate();
327 defer stage_node.end();
325 var update_node = prg_node.start("update", 4);
326 update_node.activate();
327 defer update_node.end();
328328
329 var sync_node = stage_node.start("write", null);
329 var sync_node = update_node.start("write", null);
330330 sync_node.activate();
331 try tmp.dir.writeFile(tmp_src_path, stage.src);
331 try tmp.dir.writeFile(tmp_src_path, update.src);
332332 sync_node.end();
333333
334 var module_node = stage_node.start("parse/analysis/codegen", null);
334 var module_node = update_node.start("parse/analysis/codegen", null);
335335 module_node.activate();
336336 try module.update();
337337 module_node.end();
338338
339 switch (stage.case) {
339 switch (update.case) {
340340 .Transformation => |expected_output| {
341 var emit_node = stage_node.start("emit", null);
341 var emit_node = update_node.start("emit", null);
342342 emit_node.activate();
343343 var new_zir_module = try zir.emit(allocator, module);
344344 defer new_zir_module.deinit(allocator);
345345 emit_node.end();
346346
347 var write_node = stage_node.start("write", null);
347 var write_node = update_node.start("write", null);
348348 write_node.activate();
349349 var out_zir = std.ArrayList(u8).init(allocator);
350350 defer out_zir.deinit();