diff options
| author | Noam Preil <pleasantatk@gmail.com> | 2020-06-26 05:00:53 -0400 |
|---|---|---|
| committer | Noam Preil <pleasantatk@gmail.com> | 2020-06-26 05:00:53 -0400 |
| commit | 0e952a9f3a1522a6fd39d67a495d3918b8d8240d (patch) | |
| tree | bc1c2d4de2fa0cae243ad53ca7e22e80a2dc93ad | |
| parent | c8f60b2e2f15713754ac4b0911a7d13b6057264d (diff) | |
| download | zig-0e952a9f3a1522a6fd39d67a495d3918b8d8240d.tar.gz zig-0e952a9f3a1522a6fd39d67a495d3918b8d8240d.zip | |
Stage2/Testing: Simply incremental compilation tests
| -rw-r--r-- | src-self-hosted/test.zig | 26 | ||||
| -rw-r--r-- | test/stage2/compile_errors.zig | 90 |
2 files changed, 65 insertions, 51 deletions
diff --git a/src-self-hosted/test.zig b/src-self-hosted/test.zig index 13f08d86e2..cb1a9f6981 100644 --- a/src-self-hosted/test.zig +++ b/src-self-hosted/test.zig @@ -274,6 +274,32 @@ pub const TestContext = struct { ctx.addObj(name, target, T).compiles(src); } + pub fn incrementalFailure( + ctx: *TestContext, + name: []const u8, + target: std.zig.CrossTarget, + src: [:0]const u8, + expected_errors: []const []const u8, + fixed_src: [:0]const u8, + ) void { + var case = ctx.addObj(name, target, .Zig); + case.addError(src, expected_errors); + case.compiles(fixed_src); + } + + pub fn incrementalFailureZIR( + ctx: *TestContext, + name: []const u8, + target: std.zig.CrossTarget, + src: [:0]const u8, + expected_errors: []const []const u8, + fixed_src: [:0]const u8, + ) void { + var case = ctx.addObj(name, target, .ZIR); + case.addError(src, expected_errors); + case.compiles(fixed_src); + } + pub fn compiles( ctx: *TestContext, name: []const u8, diff --git a/test/stage2/compile_errors.zig b/test/stage2/compile_errors.zig index 1184048cbb..bfe4bf7d48 100644 --- a/test/stage2/compile_errors.zig +++ b/test/stage2/compile_errors.zig @@ -43,58 +43,46 @@ pub fn addCases(ctx: *TestContext) !void { \\@1 = export(@0, "start") , &[_][]const u8{":4:9: error: unable to call function with naked calling convention"}); - { - var case = ctx.objZIR("exported symbol collision", linux_x64); - // First, ensure we receive the error correctly - case.addError( - \\@noreturn = primitive(noreturn) - \\ - \\@start_fnty = fntype([], @noreturn) - \\@start = fn(@start_fnty, {}) - \\ - \\@0 = str("_start") - \\@1 = export(@0, "start") - \\@2 = export(@0, "start") - , &[_][]const u8{":8:13: error: exported symbol collision: _start"}); - // Next, ensure everything works properly on the next compilation with the problem fixed - case.compiles( - \\@noreturn = primitive(noreturn) - \\ - \\@start_fnty = fntype([], @noreturn) - \\@start = fn(@start_fnty, {}) - \\ - \\@0 = str("_start") - \\@1 = export(@0, "start") - ); - } + ctx.incrementalFailureZIR("exported symbol collision", linux_x64, + \\@noreturn = primitive(noreturn) + \\ + \\@start_fnty = fntype([], @noreturn) + \\@start = fn(@start_fnty, {}) + \\ + \\@0 = str("_start") + \\@1 = export(@0, "start") + \\@2 = export(@0, "start") + , &[_][]const u8{":8:13: error: exported symbol collision: _start"}, + \\@noreturn = primitive(noreturn) + \\ + \\@start_fnty = fntype([], @noreturn) + \\@start = fn(@start_fnty, {}) + \\ + \\@0 = str("_start") + \\@1 = export(@0, "start") + ); + + ctx.incrementalFailure("function redefinition", linux_x64, + \\fn entry() void {} + \\fn entry() void {} + , &[_][]const u8{":2:4: error: redefinition of 'entry'"}, + \\fn entry() void {} + ); + // TODO: need to make sure this works with other variants of export. - // As is, the same error occurs without export. - { - var case = ctx.obj("exported symbol collision", linux_x64); - case.addError( - \\export fn entry() void {} - \\export fn entry() void {} - , &[_][]const u8{":2:11: error: redefinition of 'entry'"}); - case.compiles( - \\export fn entry() void {} - ); - case.addError( - \\fn entry() void {} - \\fn entry() void {} - , &[_][]const u8{":2:4: error: redefinition of 'entry'"}); - case.compiles( - \\export fn entry() void {} - ); - } - { - var case = ctx.obj("missing function name", linux_x64); - case.addError( - \\fn() void {} - , &[_][]const u8{":1:3: error: missing function name"}); - case.compiles( - \\fn a() void {} - ); - } + ctx.incrementalFailure("function redefinition", linux_x64, + \\export fn entry() void {} + \\export fn entry() void {} + , &[_][]const u8{":2:11: error: redefinition of 'entry'"}, + \\export fn entry() void {} + ); + + ctx.incrementalFailure("missing function name", linux_x64, + \\fn() void {} + , &[_][]const u8{":1:3: error: missing function name"}, + \\fn a() void {} + ); + // TODO: re-enable these tests. // https://github.com/ziglang/zig/issues/1364 |
