| author | |
| committer | |
| log | c88edbc46fbbdc5a97c9703d09097af5f8d2a653 |
| tree | 839a36bb12fb8efc84c44481add210c34319ba17 |
| parent | 5d7e981f95423b3b009e0d7eebccae6c856f68ca |
| signature | Commit is signed but in an unrecognized format. |
4 files changed, 46 insertions(+), 52 deletions(-)
src-self-hosted/test.zig+22-28| ... | @@ -66,26 +66,26 @@ pub const TestContext = struct { | ... | @@ -66,26 +66,26 @@ pub const TestContext = struct { |
| 66 | 66 | ||
| 67 | /// Adds a subcase in which the module is updated with new ZIR, and the | 67 | /// Adds a subcase in which the module is updated with new ZIR, and the |
| 68 | /// resulting ZIR is validated. | 68 | /// resulting ZIR is validated. |
| 69 | pub fn addTransform(self: *Case, src: [:0]const u8, result: [:0]const u8) !void { | 69 | pub fn addTransform(self: *Case, src: [:0]const u8, result: [:0]const u8) void { |
| 70 | try self.updates.append(.{ | 70 | self.updates.append(.{ |
| 71 | .src = src, | 71 | .src = src, |
| 72 | .case = .{ .Transformation = result }, | 72 | .case = .{ .Transformation = result }, |
| 73 | }); | 73 | }) catch unreachable; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | pub fn addCompareOutput(self: *Case, src: [:0]const u8, result: []const u8) !void { | 76 | pub fn addCompareOutput(self: *Case, src: [:0]const u8, result: []const u8) void { |
| 77 | try self.updates.append(.{ | 77 | self.updates.append(.{ |
| 78 | .src = src, | 78 | .src = src, |
| 79 | .case = .{ .Execution = result }, | 79 | .case = .{ .Execution = result }, |
| 80 | }); | 80 | }) catch unreachable; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | /// Adds a subcase in which the module is updated with invalid ZIR, and | 83 | /// Adds a subcase in which the module is updated with invalid ZIR, and |
| 84 | /// ensures that compilation fails for the expected reasons. | 84 | /// ensures that compilation fails for the expected reasons. |
| 85 | /// | 85 | /// |
| 86 | /// Errors must be specified in sequential order. | 86 | /// Errors must be specified in sequential order. |
| 87 | pub fn addError(self: *Case, src: [:0]const u8, errors: []const []const u8) !void { | 87 | pub fn addError(self: *Case, src: [:0]const u8, errors: []const []const u8) void { |
| 88 | var array = try self.updates.allocator.alloc(ErrorMsg, errors.len); | 88 | var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch unreachable; |
| 89 | for (errors) |e, i| { | 89 | for (errors) |e, i| { |
| 90 | if (e[0] != ':') { | 90 | if (e[0] != ':') { |
| 91 | @panic("Invalid test: error must be specified as follows:\n:line:column: error: message\n=========\n"); | 91 | @panic("Invalid test: error must be specified as follows:\n:line:column: error: message\n=========\n"); |
| ... | @@ -118,7 +118,7 @@ pub const TestContext = struct { | ... | @@ -118,7 +118,7 @@ pub const TestContext = struct { |
| 118 | .column = column - 1, | 118 | .column = column - 1, |
| 119 | }; | 119 | }; |
| 120 | } | 120 | } |
| 121 | try self.updates.append(.{ .src = src, .case = .{ .Error = array } }); | 121 | self.updates.append(.{ .src = src, .case = .{ .Error = array } }) catch unreachable; |
| 122 | } | 122 | } |
| 123 | }; | 123 | }; |
| 124 | 124 | ||
| ... | @@ -127,15 +127,14 @@ pub const TestContext = struct { | ... | @@ -127,15 +127,14 @@ pub const TestContext = struct { |
| 127 | name: []const u8, | 127 | name: []const u8, |
| 128 | target: std.zig.CrossTarget, | 128 | target: std.zig.CrossTarget, |
| 129 | T: TestType, | 129 | T: TestType, |
| 130 | ) !*Case { | 130 | ) *Case { |
| 131 | const case = Case{ | 131 | ctx.cases.append(Case{ |
| 132 | .name = name, | 132 | .name = name, |
| 133 | .target = target, | 133 | .target = target, |
| 134 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), | 134 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), |
| 135 | .output_mode = .Exe, | 135 | .output_mode = .Exe, |
| 136 | .@"type" = T, | 136 | .@"type" = T, |
| 137 | }; | 137 | }) catch unreachable; |
| 138 | try ctx.cases.append(case); | ||
| 139 | return &ctx.cases.items[ctx.cases.items.len - 1]; | 138 | return &ctx.cases.items[ctx.cases.items.len - 1]; |
| 140 | } | 139 | } |
| 141 | 140 | ||
| ... | @@ -144,14 +143,14 @@ pub const TestContext = struct { | ... | @@ -144,14 +143,14 @@ pub const TestContext = struct { |
| 144 | name: []const u8, | 143 | name: []const u8, |
| 145 | target: std.zig.CrossTarget, | 144 | target: std.zig.CrossTarget, |
| 146 | T: TestType, | 145 | T: TestType, |
| 147 | ) !*Case { | 146 | ) *Case { |
| 148 | try ctx.cases.append(Case{ | 147 | ctx.cases.append(Case{ |
| 149 | .name = name, | 148 | .name = name, |
| 150 | .target = target, | 149 | .target = target, |
| 151 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), | 150 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), |
| 152 | .output_mode = .Obj, | 151 | .output_mode = .Obj, |
| 153 | .@"type" = T, | 152 | .@"type" = T, |
| 154 | }); | 153 | }) catch unreachable; |
| 155 | return &ctx.cases.items[ctx.cases.items.len - 1]; | 154 | return &ctx.cases.items[ctx.cases.items.len - 1]; |
| 156 | } | 155 | } |
| 157 | 156 | ||
| ... | @@ -161,9 +160,8 @@ pub const TestContext = struct { | ... | @@ -161,9 +160,8 @@ pub const TestContext = struct { |
| 161 | T: TestType, | 160 | T: TestType, |
| 162 | src: [:0]const u8, | 161 | src: [:0]const u8, |
| 163 | expected_stdout: []const u8, | 162 | expected_stdout: []const u8, |
| 164 | ) !void { | 163 | ) void { |
| 165 | var c = try ctx.addExe(name, .{}, T); | 164 | ctx.addExe(name, .{}, T).addCompareOutput(src, expected_stdout); |
| 166 | try c.addCompareOutput(src, expected_stdout); | ||
| 167 | } | 165 | } |
| 168 | 166 | ||
| 169 | pub fn addTransform( | 167 | pub fn addTransform( |
| ... | @@ -173,9 +171,8 @@ pub const TestContext = struct { | ... | @@ -173,9 +171,8 @@ pub const TestContext = struct { |
| 173 | T: TestType, | 171 | T: TestType, |
| 174 | src: [:0]const u8, | 172 | src: [:0]const u8, |
| 175 | result: [:0]const u8, | 173 | result: [:0]const u8, |
| 176 | ) !void { | 174 | ) void { |
| 177 | var c = try ctx.addObj(name, target, T); | 175 | ctx.addObj(name, target, T).addTransform(src, result); |
| 178 | try c.addTransform(src, result); | ||
| 179 | } | 176 | } |
| 180 | 177 | ||
| 181 | pub fn addError( | 178 | pub fn addError( |
| ... | @@ -185,16 +182,13 @@ pub const TestContext = struct { | ... | @@ -185,16 +182,13 @@ pub const TestContext = struct { |
| 185 | T: TestType, | 182 | T: TestType, |
| 186 | src: [:0]const u8, | 183 | src: [:0]const u8, |
| 187 | expected_errors: []const []const u8, | 184 | expected_errors: []const []const u8, |
| 188 | ) !void { | 185 | ) void { |
| 189 | var c = try ctx.addObj(name, target, T); | 186 | ctx.addObj(name, target, T).addError(src, expected_errors); |
| 190 | try c.addError(src, expected_errors); | ||
| 191 | } | 187 | } |
| 192 | 188 | ||
| 193 | fn init() TestContext { | 189 | fn init() TestContext { |
| 194 | const allocator = std.heap.page_allocator; | 190 | const allocator = std.heap.page_allocator; |
| 195 | return .{ | 191 | return .{ .cases = std.ArrayList(Case).init(allocator) }; |
| 196 | .cases = std.ArrayList(Case).init(allocator), | ||
| 197 | }; | ||
| 198 | } | 192 | } |
| 199 | 193 | ||
| 200 | fn deinit(self: *TestContext) void { | 194 | fn deinit(self: *TestContext) void { |
test/stage2/compare_output.zig+4-4| ... | @@ -17,9 +17,9 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -17,9 +17,9 @@ pub fn addCases(ctx: *TestContext) !void { |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | { | 19 | { |
| 20 | var case = try ctx.addExe("hello world with updates", linux_x64, .Zig); | 20 | var case = ctx.addExe("hello world with updates", linux_x64, .Zig); |
| 21 | // Regular old hello world | 21 | // Regular old hello world |
| 22 | try case.addCompareOutput( | 22 | case.addCompareOutput( |
| 23 | \\export fn _start() noreturn { | 23 | \\export fn _start() noreturn { |
| 24 | \\ print(); | 24 | \\ print(); |
| 25 | \\ | 25 | \\ |
| ... | @@ -51,7 +51,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -51,7 +51,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 51 | "Hello, World!\n", | 51 | "Hello, World!\n", |
| 52 | ); | 52 | ); |
| 53 | // Now change the message only | 53 | // Now change the message only |
| 54 | try case.addCompareOutput( | 54 | case.addCompareOutput( |
| 55 | \\export fn _start() noreturn { | 55 | \\export fn _start() noreturn { |
| 56 | \\ print(); | 56 | \\ print(); |
| 57 | \\ | 57 | \\ |
| ... | @@ -83,7 +83,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -83,7 +83,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 83 | "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n", | 83 | "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n", |
| 84 | ); | 84 | ); |
| 85 | // Now we print it twice. | 85 | // Now we print it twice. |
| 86 | try case.addCompareOutput( | 86 | case.addCompareOutput( |
| 87 | \\export fn _start() noreturn { | 87 | \\export fn _start() noreturn { |
| 88 | \\ print(); | 88 | \\ print(); |
| 89 | \\ print(); | 89 | \\ print(); |
test/stage2/compile_errors.zig+12-12| ... | @@ -9,7 +9,7 @@ const linux_x64 = std.zig.CrossTarget{ | ... | @@ -9,7 +9,7 @@ const linux_x64 = std.zig.CrossTarget{ |
| 9 | }; | 9 | }; |
| 10 | 10 | ||
| 11 | pub fn addCases(ctx: *TestContext) !void { | 11 | pub fn addCases(ctx: *TestContext) !void { |
| 12 | try ctx.addError("call undefined local", linux_x64, .ZIR, | 12 | ctx.addError("call undefined local", linux_x64, .ZIR, |
| 13 | \\@noreturn = primitive(noreturn) | 13 | \\@noreturn = primitive(noreturn) |
| 14 | \\ | 14 | \\ |
| 15 | \\@start_fnty = fntype([], @noreturn, cc=Naked) | 15 | \\@start_fnty = fntype([], @noreturn, cc=Naked) |
| ... | @@ -19,7 +19,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -19,7 +19,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 19 | // TODO: address inconsistency in this message and the one in the next test | 19 | // TODO: address inconsistency in this message and the one in the next test |
| 20 | , &[_][]const u8{":5:13: error: unrecognized identifier: %test"}); | 20 | , &[_][]const u8{":5:13: error: unrecognized identifier: %test"}); |
| 21 | 21 | ||
| 22 | try ctx.addError("call with non-existent target", linux_x64, .ZIR, | 22 | ctx.addError("call with non-existent target", linux_x64, .ZIR, |
| 23 | \\@noreturn = primitive(noreturn) | 23 | \\@noreturn = primitive(noreturn) |
| 24 | \\ | 24 | \\ |
| 25 | \\@start_fnty = fntype([], @noreturn, cc=Naked) | 25 | \\@start_fnty = fntype([], @noreturn, cc=Naked) |
| ... | @@ -31,7 +31,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -31,7 +31,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 31 | , &[_][]const u8{":5:13: error: decl 'notafunc' not found"}); | 31 | , &[_][]const u8{":5:13: error: decl 'notafunc' not found"}); |
| 32 | 32 | ||
| 33 | // TODO: this error should occur at the call site, not the fntype decl | 33 | // TODO: this error should occur at the call site, not the fntype decl |
| 34 | try ctx.addError("call naked function", linux_x64, .ZIR, | 34 | ctx.addError("call naked function", linux_x64, .ZIR, |
| 35 | \\@noreturn = primitive(noreturn) | 35 | \\@noreturn = primitive(noreturn) |
| 36 | \\ | 36 | \\ |
| 37 | \\@start_fnty = fntype([], @noreturn, cc=Naked) | 37 | \\@start_fnty = fntype([], @noreturn, cc=Naked) |
| ... | @@ -46,51 +46,51 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -46,51 +46,51 @@ pub fn addCases(ctx: *TestContext) !void { |
| 46 | // TODO: re-enable these tests. | 46 | // TODO: re-enable these tests. |
| 47 | // https://github.com/ziglang/zig/issues/1364 | 47 | // https://github.com/ziglang/zig/issues/1364 |
| 48 | 48 | ||
| 49 | // try ctx.addError("Export same symbol twice", linux_x64, .Zig, | 49 | // ctx.addError("Export same symbol twice", linux_x64, .Zig, |
| 50 | // \\export fn entry() void {} | 50 | // \\export fn entry() void {} |
| 51 | // \\export fn entry() void {} | 51 | // \\export fn entry() void {} |
| 52 | // , &[_][]const u8{":2:1: error: exported symbol collision"}); | 52 | // , &[_][]const u8{":2:1: error: exported symbol collision"}); |
| 53 | 53 | ||
| 54 | // try ctx.addError("Missing function name", linux_x64, .Zig, | 54 | // ctx.addError("Missing function name", linux_x64, .Zig, |
| 55 | // \\fn() void {} | 55 | // \\fn() void {} |
| 56 | // , &[_][]const u8{":1:3: error: missing function name"}); | 56 | // , &[_][]const u8{":1:3: error: missing function name"}); |
| 57 | //try ctx.testCompileError( | 57 | //ctx.testCompileError( |
| 58 | // \\comptime { | 58 | // \\comptime { |
| 59 | // \\ return; | 59 | // \\ return; |
| 60 | // \\} | 60 | // \\} |
| 61 | //, "1.zig", 2, 5, "return expression outside function definition"); | 61 | //, "1.zig", 2, 5, "return expression outside function definition"); |
| 62 | 62 | ||
| 63 | //try ctx.testCompileError( | 63 | //ctx.testCompileError( |
| 64 | // \\export fn entry() void { | 64 | // \\export fn entry() void { |
| 65 | // \\ defer return; | 65 | // \\ defer return; |
| 66 | // \\} | 66 | // \\} |
| 67 | //, "1.zig", 2, 11, "cannot return from defer expression"); | 67 | //, "1.zig", 2, 11, "cannot return from defer expression"); |
| 68 | 68 | ||
| 69 | //try ctx.testCompileError( | 69 | //ctx.testCompileError( |
| 70 | // \\export fn entry() c_int { | 70 | // \\export fn entry() c_int { |
| 71 | // \\ return 36893488147419103232; | 71 | // \\ return 36893488147419103232; |
| 72 | // \\} | 72 | // \\} |
| 73 | //, "1.zig", 2, 12, "integer value '36893488147419103232' cannot be stored in type 'c_int'"); | 73 | //, "1.zig", 2, 12, "integer value '36893488147419103232' cannot be stored in type 'c_int'"); |
| 74 | 74 | ||
| 75 | //try ctx.testCompileError( | 75 | //ctx.testCompileError( |
| 76 | // \\comptime { | 76 | // \\comptime { |
| 77 | // \\ var a: *align(4) align(4) i32 = 0; | 77 | // \\ var a: *align(4) align(4) i32 = 0; |
| 78 | // \\} | 78 | // \\} |
| 79 | //, "1.zig", 2, 22, "Extra align qualifier"); | 79 | //, "1.zig", 2, 22, "Extra align qualifier"); |
| 80 | 80 | ||
| 81 | //try ctx.testCompileError( | 81 | //ctx.testCompileError( |
| 82 | // \\comptime { | 82 | // \\comptime { |
| 83 | // \\ var b: *const const i32 = 0; | 83 | // \\ var b: *const const i32 = 0; |
| 84 | // \\} | 84 | // \\} |
| 85 | //, "1.zig", 2, 19, "Extra align qualifier"); | 85 | //, "1.zig", 2, 19, "Extra align qualifier"); |
| 86 | 86 | ||
| 87 | //try ctx.testCompileError( | 87 | //ctx.testCompileError( |
| 88 | // \\comptime { | 88 | // \\comptime { |
| 89 | // \\ var c: *volatile volatile i32 = 0; | 89 | // \\ var c: *volatile volatile i32 = 0; |
| 90 | // \\} | 90 | // \\} |
| 91 | //, "1.zig", 2, 22, "Extra align qualifier"); | 91 | //, "1.zig", 2, 22, "Extra align qualifier"); |
| 92 | 92 | ||
| 93 | //try ctx.testCompileError( | 93 | //ctx.testCompileError( |
| 94 | // \\comptime { | 94 | // \\comptime { |
| 95 | // \\ var d: *allowzero allowzero i32 = 0; | 95 | // \\ var d: *allowzero allowzero i32 = 0; |
| 96 | // \\} | 96 | // \\} |
test/stage2/zir.zig+8-8| ... | @@ -9,7 +9,7 @@ const linux_x64 = std.zig.CrossTarget{ | ... | @@ -9,7 +9,7 @@ const linux_x64 = std.zig.CrossTarget{ |
| 9 | }; | 9 | }; |
| 10 | 10 | ||
| 11 | pub fn addCases(ctx: *TestContext) !void { | 11 | pub fn addCases(ctx: *TestContext) !void { |
| 12 | try ctx.addTransform("referencing decls which appear later in the file", linux_x64, .ZIR, | 12 | ctx.addTransform("referencing decls which appear later in the file", linux_x64, .ZIR, |
| 13 | \\@void = primitive(void) | 13 | \\@void = primitive(void) |
| 14 | \\@fnty = fntype([], @void, cc=C) | 14 | \\@fnty = fntype([], @void, cc=C) |
| 15 | \\ | 15 | \\ |
| ... | @@ -32,7 +32,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -32,7 +32,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 32 | \\}) | 32 | \\}) |
| 33 | \\ | 33 | \\ |
| 34 | ); | 34 | ); |
| 35 | try ctx.addTransform("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, .ZIR, | 35 | ctx.addTransform("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, .ZIR, |
| 36 | \\@void = primitive(void) | 36 | \\@void = primitive(void) |
| 37 | \\@usize = primitive(usize) | 37 | \\@usize = primitive(usize) |
| 38 | \\@fnty = fntype([], @void, cc=C) | 38 | \\@fnty = fntype([], @void, cc=C) |
| ... | @@ -86,8 +86,8 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -86,8 +86,8 @@ pub fn addCases(ctx: *TestContext) !void { |
| 86 | ); | 86 | ); |
| 87 | 87 | ||
| 88 | { | 88 | { |
| 89 | var case = try ctx.addObj("reference cycle with compile error in the cycle", linux_x64, .ZIR); | 89 | var case = ctx.addObj("reference cycle with compile error in the cycle", linux_x64, .ZIR); |
| 90 | try case.addTransform( | 90 | case.addTransform( |
| 91 | \\@void = primitive(void) | 91 | \\@void = primitive(void) |
| 92 | \\@fnty = fntype([], @void, cc=C) | 92 | \\@fnty = fntype([], @void, cc=C) |
| 93 | \\ | 93 | \\ |
| ... | @@ -133,7 +133,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -133,7 +133,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 133 | \\ | 133 | \\ |
| 134 | ); | 134 | ); |
| 135 | // Now we introduce a compile error | 135 | // Now we introduce a compile error |
| 136 | try case.addError( | 136 | case.addError( |
| 137 | \\@void = primitive(void) | 137 | \\@void = primitive(void) |
| 138 | \\@fnty = fntype([], @void, cc=C) | 138 | \\@fnty = fntype([], @void, cc=C) |
| 139 | \\ | 139 | \\ |
| ... | @@ -163,7 +163,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -163,7 +163,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 163 | // Now we remove the call to `a`. `a` and `b` form a cycle, but no entry points are | 163 | // Now we remove the call to `a`. `a` and `b` form a cycle, but no entry points are |
| 164 | // referencing either of them. This tests that the cycle is detected, and the error | 164 | // referencing either of them. This tests that the cycle is detected, and the error |
| 165 | // goes away. | 165 | // goes away. |
| 166 | try case.addTransform( | 166 | case.addTransform( |
| 167 | \\@void = primitive(void) | 167 | \\@void = primitive(void) |
| 168 | \\@fnty = fntype([], @void, cc=C) | 168 | \\@fnty = fntype([], @void, cc=C) |
| 169 | \\ | 169 | \\ |
| ... | @@ -207,7 +207,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -207,7 +207,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 207 | return; | 207 | return; |
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | try ctx.addCompareOutput("hello world ZIR", .ZIR, | 210 | ctx.addCompareOutput("hello world ZIR", .ZIR, |
| 211 | \\@noreturn = primitive(noreturn) | 211 | \\@noreturn = primitive(noreturn) |
| 212 | \\@void = primitive(void) | 212 | \\@void = primitive(void) |
| 213 | \\@usize = primitive(usize) | 213 | \\@usize = primitive(usize) |
| ... | @@ -265,7 +265,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -265,7 +265,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 265 | \\ | 265 | \\ |
| 266 | ); | 266 | ); |
| 267 | 267 | ||
| 268 | try ctx.addCompareOutput("function call with no args no return value", .ZIR, | 268 | ctx.addCompareOutput("function call with no args no return value", .ZIR, |
| 269 | \\@noreturn = primitive(noreturn) | 269 | \\@noreturn = primitive(noreturn) |
| 270 | \\@void = primitive(void) | 270 | \\@void = primitive(void) |
| 271 | \\@usize = primitive(usize) | 271 | \\@usize = primitive(usize) |