| author | |
| committer | |
| log | 649da2df5234f504f2f22afe9e0b4cf7eeb9ef35 |
| tree | 2e7873b9d8bdead87e2d3698e6462d7d86133b54 |
| parent | c88edbc46fbbdc5a97c9703d09097af5f8d2a653 |
| signature |
4 files changed, 83 insertions(+), 9 deletions(-)
src-self-hosted/test.zig+74| ... | @@ -138,6 +138,14 @@ pub const TestContext = struct { | ... | @@ -138,6 +138,14 @@ pub const TestContext = struct { |
| 138 | return &ctx.cases.items[ctx.cases.items.len - 1]; | 138 | return &ctx.cases.items[ctx.cases.items.len - 1]; |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | pub fn exe(ctx: *TestContext, name: []const u8, target: std.zig.CrossTarget) *Case { | ||
| 142 | return ctx.addExe(name, target, .Zig); | ||
| 143 | } | ||
| 144 | |||
| 145 | pub fn exeZIR(ctx: *TestContext, name: []const u8, target: std.zig.CrossTarget) *Case { | ||
| 146 | return ctx.addExe(name, target, .ZIR); | ||
| 147 | } | ||
| 148 | |||
| 141 | pub fn addObj( | 149 | pub fn addObj( |
| 142 | ctx: *TestContext, | 150 | ctx: *TestContext, |
| 143 | name: []const u8, | 151 | name: []const u8, |
| ... | @@ -154,6 +162,14 @@ pub const TestContext = struct { | ... | @@ -154,6 +162,14 @@ pub const TestContext = struct { |
| 154 | return &ctx.cases.items[ctx.cases.items.len - 1]; | 162 | return &ctx.cases.items[ctx.cases.items.len - 1]; |
| 155 | } | 163 | } |
| 156 | 164 | ||
| 165 | pub fn obj(ctx: *TestContext, name: []const u8, target: std.zig.CrossTarget) *Case { | ||
| 166 | return ctx.addObj(name, target, .Zig); | ||
| 167 | } | ||
| 168 | |||
| 169 | pub fn objZIR(ctx: *TestContext, name: []const u8, target: std.zig.CrossTarget) *Case { | ||
| 170 | return ctx.addObj(name, target, .ZIR); | ||
| 171 | } | ||
| 172 | |||
| 157 | pub fn addCompareOutput( | 173 | pub fn addCompareOutput( |
| 158 | ctx: *TestContext, | 174 | ctx: *TestContext, |
| 159 | name: []const u8, | 175 | name: []const u8, |
| ... | @@ -164,6 +180,24 @@ pub const TestContext = struct { | ... | @@ -164,6 +180,24 @@ pub const TestContext = struct { |
| 164 | ctx.addExe(name, .{}, T).addCompareOutput(src, expected_stdout); | 180 | ctx.addExe(name, .{}, T).addCompareOutput(src, expected_stdout); |
| 165 | } | 181 | } |
| 166 | 182 | ||
| 183 | pub fn compareOutput( | ||
| 184 | ctx: *TestContext, | ||
| 185 | name: []const u8, | ||
| 186 | src: [:0]const u8, | ||
| 187 | expected_stdout: []const u8, | ||
| 188 | ) void { | ||
| 189 | return ctx.addCompareOutput(name, .Zig, src, expected_stdout); | ||
| 190 | } | ||
| 191 | |||
| 192 | pub fn compareOutputZIR( | ||
| 193 | ctx: *TestContext, | ||
| 194 | name: []const u8, | ||
| 195 | src: [:0]const u8, | ||
| 196 | expected_stdout: []const u8, | ||
| 197 | ) void { | ||
| 198 | ctx.addCompareOutput(name, .ZIR, src, expected_stdout); | ||
| 199 | } | ||
| 200 | |||
| 167 | pub fn addTransform( | 201 | pub fn addTransform( |
| 168 | ctx: *TestContext, | 202 | ctx: *TestContext, |
| 169 | name: []const u8, | 203 | name: []const u8, |
| ... | @@ -175,6 +209,26 @@ pub const TestContext = struct { | ... | @@ -175,6 +209,26 @@ pub const TestContext = struct { |
| 175 | ctx.addObj(name, target, T).addTransform(src, result); | 209 | ctx.addObj(name, target, T).addTransform(src, result); |
| 176 | } | 210 | } |
| 177 | 211 | ||
| 212 | pub fn transform( | ||
| 213 | ctx: *TestContext, | ||
| 214 | name: []const u8, | ||
| 215 | target: std.zig.CrossTarget, | ||
| 216 | src: [:0]const u8, | ||
| 217 | result: [:0]const u8, | ||
| 218 | ) void { | ||
| 219 | ctx.addTransform(name, target, .Zig, src, result); | ||
| 220 | } | ||
| 221 | |||
| 222 | pub fn transformZIR( | ||
| 223 | ctx: *TestContext, | ||
| 224 | name: []const u8, | ||
| 225 | target: std.zig.CrossTarget, | ||
| 226 | src: [:0]const u8, | ||
| 227 | result: [:0]const u8, | ||
| 228 | ) void { | ||
| 229 | ctx.addTransform(name, target, .ZIR, src, result); | ||
| 230 | } | ||
| 231 | |||
| 178 | pub fn addError( | 232 | pub fn addError( |
| 179 | ctx: *TestContext, | 233 | ctx: *TestContext, |
| 180 | name: []const u8, | 234 | name: []const u8, |
| ... | @@ -186,6 +240,26 @@ pub const TestContext = struct { | ... | @@ -186,6 +240,26 @@ pub const TestContext = struct { |
| 186 | ctx.addObj(name, target, T).addError(src, expected_errors); | 240 | ctx.addObj(name, target, T).addError(src, expected_errors); |
| 187 | } | 241 | } |
| 188 | 242 | ||
| 243 | pub fn compileError( | ||
| 244 | ctx: *TestContext, | ||
| 245 | name: []const u8, | ||
| 246 | target: std.zig.CrossTarget, | ||
| 247 | src: [:0]const u8, | ||
| 248 | expected_errors: []const []const u8, | ||
| 249 | ) void { | ||
| 250 | ctx.addError(name, target, .Zig, src, expected_errors); | ||
| 251 | } | ||
| 252 | |||
| 253 | pub fn compileErrorZIR( | ||
| 254 | ctx: *TestContext, | ||
| 255 | name: []const u8, | ||
| 256 | target: std.zig.CrossTarget, | ||
| 257 | src: [:0]const u8, | ||
| 258 | expected_errors: []const []const u8, | ||
| 259 | ) void { | ||
| 260 | ctx.addError(name, target, .ZIR, src, expected_errors); | ||
| 261 | } | ||
| 262 | |||
| 189 | fn init() TestContext { | 263 | fn init() TestContext { |
| 190 | const allocator = std.heap.page_allocator; | 264 | const allocator = std.heap.page_allocator; |
| 191 | return .{ .cases = std.ArrayList(Case).init(allocator) }; | 265 | return .{ .cases = std.ArrayList(Case).init(allocator) }; |
test/stage2/compare_output.zig+1-1| ... | @@ -17,7 +17,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -17,7 +17,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | { | 19 | { |
| 20 | var case = ctx.addExe("hello world with updates", linux_x64, .Zig); | 20 | var case = ctx.exe("hello world with updates", linux_x64); |
| 21 | // Regular old hello world | 21 | // Regular old hello world |
| 22 | case.addCompareOutput( | 22 | case.addCompareOutput( |
| 23 | \\export fn _start() noreturn { | 23 | \\export fn _start() noreturn { |
test/stage2/compile_errors.zig+3-3| ... | @@ -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 | ctx.addError("call undefined local", linux_x64, .ZIR, | 12 | ctx.compileErrorZIR("call undefined local", linux_x64, |
| 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 | ctx.addError("call with non-existent target", linux_x64, .ZIR, | 22 | ctx.compileErrorZIR("call with non-existent target", linux_x64, |
| 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 | ctx.addError("call naked function", linux_x64, .ZIR, | 34 | ctx.compileErrorZIR("call naked function", linux_x64, |
| 35 | \\@noreturn = primitive(noreturn) | 35 | \\@noreturn = primitive(noreturn) |
| 36 | \\ | 36 | \\ |
| 37 | \\@start_fnty = fntype([], @noreturn, cc=Naked) | 37 | \\@start_fnty = fntype([], @noreturn, cc=Naked) |
test/stage2/zir.zig+5-5| ... | @@ -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 | ctx.addTransform("referencing decls which appear later in the file", linux_x64, .ZIR, | 12 | ctx.transformZIR("referencing decls which appear later in the file", linux_x64, |
| 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 | ctx.addTransform("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, .ZIR, | 35 | ctx.transformZIR("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, |
| 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,7 +86,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -86,7 +86,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 86 | ); | 86 | ); |
| 87 | 87 | ||
| 88 | { | 88 | { |
| 89 | var case = ctx.addObj("reference cycle with compile error in the cycle", linux_x64, .ZIR); | 89 | var case = ctx.objZIR("reference cycle with compile error in the cycle", linux_x64); |
| 90 | 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) |
| ... | @@ -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 | ctx.addCompareOutput("hello world ZIR", .ZIR, | 210 | ctx.compareOutputZIR("hello world 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 | ctx.addCompareOutput("function call with no args no return value", .ZIR, | 268 | ctx.compareOutputZIR("function call with no args no return value", |
| 269 | \\@noreturn = primitive(noreturn) | 269 | \\@noreturn = primitive(noreturn) |
| 270 | \\@void = primitive(void) | 270 | \\@void = primitive(void) |
| 271 | \\@usize = primitive(usize) | 271 | \\@usize = primitive(usize) |