authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-26 05:00:53-04:00
committergravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-26 05:00:53-04:00
log0e952a9f3a1522a6fd39d67a495d3918b8d8240d
treebc1c2d4de2fa0cae243ad53ca7e22e80a2dc93ad
parentc8f60b2e2f15713754ac4b0911a7d13b6057264d
signaturelock-open Commit is signed but in an unrecognized format.

Stage2/Testing: Simply incremental compilation tests


2 files changed, 65 insertions(+), 51 deletions(-)

src-self-hosted/test.zig+26
...@@ -274,6 +274,32 @@ pub const TestContext = struct {...@@ -274,6 +274,32 @@ pub const TestContext = struct {
274 ctx.addObj(name, target, T).compiles(src);274 ctx.addObj(name, target, T).compiles(src);
275 }275 }
276276
277 pub fn incrementalFailure(
278 ctx: *TestContext,
279 name: []const u8,
280 target: std.zig.CrossTarget,
281 src: [:0]const u8,
282 expected_errors: []const []const u8,
283 fixed_src: [:0]const u8,
284 ) void {
285 var case = ctx.addObj(name, target, .Zig);
286 case.addError(src, expected_errors);
287 case.compiles(fixed_src);
288 }
289
290 pub fn incrementalFailureZIR(
291 ctx: *TestContext,
292 name: []const u8,
293 target: std.zig.CrossTarget,
294 src: [:0]const u8,
295 expected_errors: []const []const u8,
296 fixed_src: [:0]const u8,
297 ) void {
298 var case = ctx.addObj(name, target, .ZIR);
299 case.addError(src, expected_errors);
300 case.compiles(fixed_src);
301 }
302
277 pub fn compiles(303 pub fn compiles(
278 ctx: *TestContext,304 ctx: *TestContext,
279 name: []const u8,305 name: []const u8,
test/stage2/compile_errors.zig+39-51
...@@ -43,58 +43,46 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -43,58 +43,46 @@ pub fn addCases(ctx: *TestContext) !void {
43 \\@1 = export(@0, "start")43 \\@1 = export(@0, "start")
44 , &[_][]const u8{":4:9: error: unable to call function with naked calling convention"});44 , &[_][]const u8{":4:9: error: unable to call function with naked calling convention"});
4545
46 {46 ctx.incrementalFailureZIR("exported symbol collision", linux_x64,
47 var case = ctx.objZIR("exported symbol collision", linux_x64);47 \\@noreturn = primitive(noreturn)
48 // First, ensure we receive the error correctly48 \\
49 case.addError(49 \\@start_fnty = fntype([], @noreturn)
50 \\@noreturn = primitive(noreturn)50 \\@start = fn(@start_fnty, {})
51 \\51 \\
52 \\@start_fnty = fntype([], @noreturn)52 \\@0 = str("_start")
53 \\@start = fn(@start_fnty, {})53 \\@1 = export(@0, "start")
54 \\54 \\@2 = export(@0, "start")
55 \\@0 = str("_start")55 , &[_][]const u8{":8:13: error: exported symbol collision: _start"},
56 \\@1 = export(@0, "start")56 \\@noreturn = primitive(noreturn)
57 \\@2 = export(@0, "start")57 \\
58 , &[_][]const u8{":8:13: error: exported symbol collision: _start"});58 \\@start_fnty = fntype([], @noreturn)
59 // Next, ensure everything works properly on the next compilation with the problem fixed59 \\@start = fn(@start_fnty, {})
60 case.compiles(60 \\
61 \\@noreturn = primitive(noreturn)61 \\@0 = str("_start")
62 \\62 \\@1 = export(@0, "start")
63 \\@start_fnty = fntype([], @noreturn)63 );
64 \\@start = fn(@start_fnty, {})64
65 \\65 ctx.incrementalFailure("function redefinition", linux_x64,
66 \\@0 = str("_start")66 \\fn entry() void {}
67 \\@1 = export(@0, "start")67 \\fn entry() void {}
68 );68 , &[_][]const u8{":2:4: error: redefinition of 'entry'"},
69 }69 \\fn entry() void {}
70 );
71
70 // TODO: need to make sure this works with other variants of export.72 // TODO: need to make sure this works with other variants of export.
71 // As is, the same error occurs without export.73 ctx.incrementalFailure("function redefinition", linux_x64,
72 {74 \\export fn entry() void {}
73 var case = ctx.obj("exported symbol collision", linux_x64);75 \\export fn entry() void {}
74 case.addError(76 , &[_][]const u8{":2:11: error: redefinition of 'entry'"},
75 \\export fn entry() void {}77 \\export fn entry() void {}
76 \\export fn entry() void {}78 );
77 , &[_][]const u8{":2:11: error: redefinition of 'entry'"});79
78 case.compiles(80 ctx.incrementalFailure("missing function name", linux_x64,
79 \\export fn entry() void {}81 \\fn() void {}
80 );82 , &[_][]const u8{":1:3: error: missing function name"},
81 case.addError(83 \\fn a() void {}
82 \\fn entry() void {}84 );
83 \\fn entry() void {}85
84 , &[_][]const u8{":2:4: error: redefinition of 'entry'"});
85 case.compiles(
86 \\export fn entry() void {}
87 );
88 }
89 {
90 var case = ctx.obj("missing function name", linux_x64);
91 case.addError(
92 \\fn() void {}
93 , &[_][]const u8{":1:3: error: missing function name"});
94 case.compiles(
95 \\fn a() void {}
96 );
97 }
98 // TODO: re-enable these tests.86 // TODO: re-enable these tests.
99 // https://github.com/ziglang/zig/issues/136487 // https://github.com/ziglang/zig/issues/1364
10088