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
signature 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");
66const Package = @import("Package.zig");
77
88test "self-hosted" {
9 var ctx: TestContext = undefined;
10 try ctx.init();
9 var ctx = TestContext.init();
1110 defer ctx.deinit();
1211
1312 try @import("stage2_tests").addCases(&ctx);
......@@ -93,10 +92,11 @@ pub const TestContext = struct {
9392 name: []const u8,
9493 /// The platform the ZIR targets. For non-native platforms, an emulator
9594 /// such as QEMU is required for tests to complete.
96 ///
9795 target: std.zig.CrossTarget,
9896 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.
100100 pub fn addTransform(self: *ZIRCase, src: [:0]const u8, result: [:0]const u8) void {
101101 self.updates.append(.{
102102 .src = src,
......@@ -104,9 +104,10 @@ pub const TestContext = struct {
104104 }) catch unreachable;
105105 }
106106
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.
108109 ///
109 /// Errors must be specified in sequential order
110 /// Errors must be specified in sequential order.
110111 pub fn addError(self: *ZIRCase, src: [:0]const u8, errors: []const []const u8) void {
111112 var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch unreachable;
112113 for (errors) |e, i| {
......@@ -194,9 +195,9 @@ pub const TestContext = struct {
194195 c.addError(src, expected_errors);
195196 }
196197
197 fn init(self: *TestContext) !void {
198 fn init() TestContext {
198199 const allocator = std.heap.page_allocator;
199 self.* = .{
200 return .{
200201 .zir_cmp_output_cases = std.ArrayList(ZIRCompareOutputCase).init(allocator),
201202 .zir_cases = std.ArrayList(ZIRCase).init(allocator),
202203 };
......@@ -267,10 +268,7 @@ pub const TestContext = struct {
267268 });
268269 defer module.deinit();
269270
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| {
274272 var update_node = prg_node.start("update", 4);
275273 update_node.activate();
276274 defer update_node.end();
test/stage2/compile_errors.zig+4-2
......@@ -9,8 +9,6 @@ const linux_x64 = std.zig.CrossTarget{
99};
1010
1111pub fn addCases(ctx: *TestContext) !void {
12 // TODO: re-enable these tests.
13 // https://github.com/ziglang/zig/issues/1364
1412 ctx.addZIRError("call undefined local", linux_x64,
1513 \\@noreturn = primitive(noreturn)
1614 \\
......@@ -47,6 +45,10 @@ pub fn addCases(ctx: *TestContext) !void {
4745 \\@2 = export(@1, @start)
4846 , &[_][]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
5052 //try ctx.testCompileError(
5153 // \\export fn entry() void {}
5254 // \\export fn entry() void {}