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 {
274274 ctx.addObj(name, target, T).compiles(src);
275275 }
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
277303 pub fn compiles(
278304 ctx: *TestContext,
279305 name: []const u8,
test/stage2/compile_errors.zig+39-51
......@@ -43,58 +43,46 @@ pub fn addCases(ctx: *TestContext) !void {
4343 \\@1 = export(@0, "start")
4444 , &[_][]const u8{":4:9: error: unable to call function with naked calling convention"});
4545
46 {
47 var case = ctx.objZIR("exported symbol collision", linux_x64);
48 // First, ensure we receive the error correctly
49 case.addError(
50 \\@noreturn = primitive(noreturn)
51 \\
52 \\@start_fnty = fntype([], @noreturn)
53 \\@start = fn(@start_fnty, {})
54 \\
55 \\@0 = str("_start")
56 \\@1 = export(@0, "start")
57 \\@2 = export(@0, "start")
58 , &[_][]const u8{":8:13: error: exported symbol collision: _start"});
59 // Next, ensure everything works properly on the next compilation with the problem fixed
60 case.compiles(
61 \\@noreturn = primitive(noreturn)
62 \\
63 \\@start_fnty = fntype([], @noreturn)
64 \\@start = fn(@start_fnty, {})
65 \\
66 \\@0 = str("_start")
67 \\@1 = export(@0, "start")
68 );
69 }
46 ctx.incrementalFailureZIR("exported symbol collision", linux_x64,
47 \\@noreturn = primitive(noreturn)
48 \\
49 \\@start_fnty = fntype([], @noreturn)
50 \\@start = fn(@start_fnty, {})
51 \\
52 \\@0 = str("_start")
53 \\@1 = export(@0, "start")
54 \\@2 = export(@0, "start")
55 , &[_][]const u8{":8:13: error: exported symbol collision: _start"},
56 \\@noreturn = primitive(noreturn)
57 \\
58 \\@start_fnty = fntype([], @noreturn)
59 \\@start = fn(@start_fnty, {})
60 \\
61 \\@0 = str("_start")
62 \\@1 = export(@0, "start")
63 );
64
65 ctx.incrementalFailure("function redefinition", linux_x64,
66 \\fn entry() void {}
67 \\fn entry() void {}
68 , &[_][]const u8{":2:4: error: redefinition of 'entry'"},
69 \\fn entry() void {}
70 );
71
7072 // TODO: need to make sure this works with other variants of export.
71 // As is, the same error occurs without export.
72 {
73 var case = ctx.obj("exported symbol collision", linux_x64);
74 case.addError(
75 \\export fn entry() void {}
76 \\export fn entry() void {}
77 , &[_][]const u8{":2:11: error: redefinition of 'entry'"});
78 case.compiles(
79 \\export fn entry() void {}
80 );
81 case.addError(
82 \\fn entry() void {}
83 \\fn entry() void {}
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 }
73 ctx.incrementalFailure("function redefinition", linux_x64,
74 \\export fn entry() void {}
75 \\export fn entry() void {}
76 , &[_][]const u8{":2:11: error: redefinition of 'entry'"},
77 \\export fn entry() void {}
78 );
79
80 ctx.incrementalFailure("missing function name", linux_x64,
81 \\fn() void {}
82 , &[_][]const u8{":1:3: error: missing function name"},
83 \\fn a() void {}
84 );
85
9886 // TODO: re-enable these tests.
9987 // https://github.com/ziglang/zig/issues/1364
10088