authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-15 21:47:42-04:00
committergravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-15 21:47:42-04:00
loga99e61ebaa71aa74dfa95869ea8d02131ef9f696
tree2c2cce660fe15e54e07cfa93cb15097368818cdc
parentafec3e72f438fae41e493e3fd18ca62e5ef1c89b
signaturelock-open Commit is signed but in an unrecognized format.

Stage2/Testing: Code cleanup


2 files changed, 13 insertions(+), 13 deletions(-)

src-self-hosted/test.zig+9-11
...@@ -6,8 +6,7 @@ const zir = @import("zir.zig");...@@ -6,8 +6,7 @@ const zir = @import("zir.zig");
6const Package = @import("Package.zig");6const Package = @import("Package.zig");
77
8test "self-hosted" {8test "self-hosted" {
9 var ctx: TestContext = undefined;9 var ctx = TestContext.init();
10 try ctx.init();
11 defer ctx.deinit();10 defer ctx.deinit();
1211
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 emulator93 /// 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),
9997
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 }
106106
107 /// TODO: document107 /// 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 order110 /// 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 }
196197
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();
269270
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();
test/stage2/compile_errors.zig+4-2
...@@ -9,8 +9,6 @@ const linux_x64 = std.zig.CrossTarget{...@@ -9,8 +9,6 @@ const linux_x64 = std.zig.CrossTarget{
9};9};
1010
11pub fn addCases(ctx: *TestContext) !void {11pub fn addCases(ctx: *TestContext) !void {
12 // TODO: re-enable these tests.
13 // https://github.com/ziglang/zig/issues/1364
14 ctx.addZIRError("call undefined local", linux_x64,12 ctx.addZIRError("call undefined local", linux_x64,
15 \\@noreturn = primitive(noreturn)13 \\@noreturn = primitive(noreturn)
16 \\14 \\
...@@ -47,6 +45,10 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -47,6 +45,10 @@ pub fn addCases(ctx: *TestContext) !void {
47 \\@2 = export(@1, @start)45 \\@2 = export(@1, @start)
48 , &[_][]const u8{":4:9: error: unable to call function with naked calling convention"});46 , &[_][]const u8{":4:9: error: unable to call function with naked calling convention"});
4947
48 // TODO: re-enable these tests.
49 // https://github.com/ziglang/zig/issues/1364
50 // TODO: add Zig AST -> ZIR testing pipeline
51
50 //try ctx.testCompileError(52 //try ctx.testCompileError(
51 // \\export fn entry() void {}53 // \\export fn entry() void {}
52 // \\export fn entry() void {}54 // \\export fn entry() void {}