authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-02-06 12:49:42+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-02-08 10:03:29+01:00
logf50203c83667ed3ad0c57fdc953322a5f9c221ac
treee00d3de5d985d8a579aa3e1229fc2a9ecd36889d
parent2302ded9511a6ee5bc3d672e6405df6a955b3622

wasm: update test runner

This updates the test runner for stage2 to emit to stdout with the passed, skipped and failed tests similar to the LLVM backend. Another change to this is the start function, as it's now more in line with stage1's. The stage2 test infrastructure for wasm/wasi has been updated to reflect this as well.

6 files changed, 128 insertions(+), 130 deletions(-)

lib/std/special/test_runner.zig+1-1
...@@ -144,7 +144,7 @@ pub fn main2() anyerror!void {...@@ -144,7 +144,7 @@ pub fn main2() anyerror!void {
144 }144 }
145 };145 };
146 }146 }
147 if (builtin.zig_backend == .stage2_llvm) {147 if (builtin.zig_backend == .stage2_llvm or builtin.zig_backend == .stage2_wasm) {
148 const passed = builtin.test_functions.len - skipped - failed;148 const passed = builtin.test_functions.len - skipped - failed;
149 const stderr = std.io.getStdErr();149 const stderr = std.io.getStdErr();
150 writeInt(stderr, passed) catch {};150 writeInt(stderr, passed) catch {};
lib/std/start.zig+4-4
...@@ -31,7 +31,7 @@ comptime {...@@ -31,7 +31,7 @@ comptime {
31 } else if (builtin.os.tag == .windows) {31 } else if (builtin.os.tag == .windows) {
32 @export(wWinMainCRTStartup2, .{ .name = "wWinMainCRTStartup" });32 @export(wWinMainCRTStartup2, .{ .name = "wWinMainCRTStartup" });
33 } else if (builtin.os.tag == .wasi and @hasDecl(root, "main")) {33 } else if (builtin.os.tag == .wasi and @hasDecl(root, "main")) {
34 @export(wasmMain2, .{ .name = "_start" });34 @export(wasiMain2, .{ .name = "_start" });
35 } else {35 } else {
36 if (!@hasDecl(root, "_start")) {36 if (!@hasDecl(root, "_start")) {
37 @export(_start2, .{ .name = "_start" });37 @export(_start2, .{ .name = "_start" });
...@@ -100,17 +100,17 @@ fn callMain2() noreturn {...@@ -100,17 +100,17 @@ fn callMain2() noreturn {
100 exit2(0);100 exit2(0);
101}101}
102102
103fn wasmMain2() u8 {103fn wasiMain2() noreturn {
104 switch (@typeInfo(@typeInfo(@TypeOf(root.main)).Fn.return_type.?)) {104 switch (@typeInfo(@typeInfo(@TypeOf(root.main)).Fn.return_type.?)) {
105 .Void => {105 .Void => {
106 root.main();106 root.main();
107 return 0;107 std.os.wasi.proc_exit(0);
108 },108 },
109 .Int => |info| {109 .Int => |info| {
110 if (info.bits != 8 or info.signedness == .signed) {110 if (info.bits != 8 or info.signedness == .signed) {
111 @compileError(bad_main_ret);111 @compileError(bad_main_ret);
112 }112 }
113 return root.main();113 std.os.wasi.proc_exit(root.main());
114 },114 },
115 else => @compileError("Bad return type main"),115 else => @compileError("Bad return type main"),
116 }116 }
src/arch/wasm/CodeGen.zig+1-1
...@@ -954,7 +954,7 @@ pub const DeclGen = struct {...@@ -954,7 +954,7 @@ pub const DeclGen = struct {
954 } else if (decl.val.castTag(.extern_fn)) |extern_fn| {954 } else if (decl.val.castTag(.extern_fn)) |extern_fn| {
955 const ext_decl = extern_fn.data.owner_decl;955 const ext_decl = extern_fn.data.owner_decl;
956 var func_type = try genFunctype(self.gpa, ext_decl.ty, self.target());956 var func_type = try genFunctype(self.gpa, ext_decl.ty, self.target());
957 func_type.deinit(self.gpa);957 defer func_type.deinit(self.gpa);
958 ext_decl.fn_link.wasm.type_index = try self.bin_file.putOrGetFuncType(func_type);958 ext_decl.fn_link.wasm.type_index = try self.bin_file.putOrGetFuncType(func_type);
959 return Result{ .appended = {} };959 return Result{ .appended = {} };
960 } else {960 } else {
src/link/Wasm.zig+10-6
...@@ -260,7 +260,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void {...@@ -260,7 +260,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void {
260 if (build_options.have_llvm) {260 if (build_options.have_llvm) {
261 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(module, decl);261 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(module, decl);
262 }262 }
263 if (!decl.ty.hasRuntimeBits()) return;263
264 assert(decl.link.wasm.sym_index != 0); // Must call allocateDeclIndexes()264 assert(decl.link.wasm.sym_index != 0); // Must call allocateDeclIndexes()
265265
266 decl.link.wasm.clear();266 decl.link.wasm.clear();
...@@ -297,8 +297,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void {...@@ -297,8 +297,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void {
297297
298fn finishUpdateDecl(self: *Wasm, decl: *Module.Decl, code: []const u8) !void {298fn finishUpdateDecl(self: *Wasm, decl: *Module.Decl, code: []const u8) !void {
299 if (decl.isExtern()) {299 if (decl.isExtern()) {
300 try self.addOrUpdateImport(decl);300 return self.addOrUpdateImport(decl);
301 return;
302 }301 }
303302
304 if (code.len == 0) return;303 if (code.len == 0) return;
...@@ -407,16 +406,18 @@ pub fn freeDecl(self: *Wasm, decl: *Module.Decl) void {...@@ -407,16 +406,18 @@ pub fn freeDecl(self: *Wasm, decl: *Module.Decl) void {
407 self.symbols.items[atom.sym_index].tag = .dead; // to ensure it does not end in the names section406 self.symbols.items[atom.sym_index].tag = .dead; // to ensure it does not end in the names section
408 for (atom.locals.items) |local_atom| {407 for (atom.locals.items) |local_atom| {
409 self.symbols.items[local_atom.sym_index].tag = .dead; // also for any local symbol408 self.symbols.items[local_atom.sym_index].tag = .dead; // also for any local symbol
409 self.symbols_free_list.append(self.base.allocator, local_atom.sym_index) catch {};
410 }410 }
411 atom.deinit(self.base.allocator);
412411
413 if (decl.isExtern()) {412 if (decl.isExtern()) {
414 const import = self.imports.fetchRemove(decl.link.wasm.sym_index).?.value;413 const import = self.imports.fetchRemove(atom.sym_index).?.value;
415 switch (import.kind) {414 switch (import.kind) {
416 .function => self.imported_functions_count -= 1,415 .function => self.imported_functions_count -= 1,
417 else => unreachable,416 else => unreachable,
418 }417 }
419 }418 }
419
420 atom.deinit(self.base.allocator);
420}421}
421422
422/// Appends a new entry to the indirect function table423/// Appends a new entry to the indirect function table
...@@ -441,10 +442,13 @@ fn addOrUpdateImport(self: *Wasm, decl: *Module.Decl) !void {...@@ -441,10 +442,13 @@ fn addOrUpdateImport(self: *Wasm, decl: *Module.Decl) !void {
441 switch (decl.ty.zigTypeTag()) {442 switch (decl.ty.zigTypeTag()) {
442 .Fn => {443 .Fn => {
443 const gop = try self.imports.getOrPut(self.base.allocator, symbol_index);444 const gop = try self.imports.getOrPut(self.base.allocator, symbol_index);
445 const module_name = if (decl.getExternFn().?.lib_name) |lib_name| blk: {
446 break :blk std.mem.sliceTo(lib_name, 0);
447 } else self.host_name;
444 if (!gop.found_existing) {448 if (!gop.found_existing) {
445 self.imported_functions_count += 1;449 self.imported_functions_count += 1;
446 gop.value_ptr.* = .{450 gop.value_ptr.* = .{
447 .module_name = self.host_name,451 .module_name = module_name,
448 .name = std.mem.span(symbol.name),452 .name = std.mem.span(symbol.name),
449 .kind = .{ .function = decl.fn_link.wasm.type_index },453 .kind = .{ .function = decl.fn_link.wasm.type_index },
450 };454 };
src/link/Wasm/Symbol.zig+3-2
...@@ -142,19 +142,20 @@ pub fn format(self: Symbol, comptime fmt: []const u8, options: std.fmt.FormatOpt...@@ -142,19 +142,20 @@ pub fn format(self: Symbol, comptime fmt: []const u8, options: std.fmt.FormatOpt
142 _ = fmt;142 _ = fmt;
143 _ = options;143 _ = options;
144144
145 const kind_fmt: u8 = switch (self.kind) {145 const kind_fmt: u8 = switch (self.tag) {
146 .function => 'F',146 .function => 'F',
147 .data => 'D',147 .data => 'D',
148 .global => 'G',148 .global => 'G',
149 .section => 'S',149 .section => 'S',
150 .event => 'E',150 .event => 'E',
151 .table => 'T',151 .table => 'T',
152 .dead => '-',
152 };153 };
153 const visible: []const u8 = if (self.isVisible()) "yes" else "no";154 const visible: []const u8 = if (self.isVisible()) "yes" else "no";
154 const binding: []const u8 = if (self.isLocal()) "local" else "global";155 const binding: []const u8 = if (self.isLocal()) "local" else "global";
155156
156 try writer.print(157 try writer.print(
157 "{c} binding={s} visible={s} id={d} name={s}",158 "{c} binding={s} visible={s} id={d} name={s}",
158 .{ kind_fmt, binding, visible, self.index(), self.name },159 .{ kind_fmt, binding, visible, self.index, self.name },
159 );160 );
160}161}
test/stage2/wasm.zig+109-116
...@@ -11,37 +11,31 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -11,37 +11,31 @@ pub fn addCases(ctx: *TestContext) !void {
11 var case = ctx.exe("wasm function calls", wasi);11 var case = ctx.exe("wasm function calls", wasi);
1212
13 case.addCompareOutput(13 case.addCompareOutput(
14 \\pub fn main() u8 {14 \\pub fn main() void {
15 \\ foo();15 \\ foo();
16 \\ bar();16 \\ bar();
17 \\ return 42;
18 \\}17 \\}
19 \\fn foo() void {18 \\fn foo() void {
20 \\ bar();19 \\ bar();
21 \\ bar();20 \\ bar();
22 \\}21 \\}
23 \\fn bar() void {}22 \\fn bar() void {}
24 ,23 , "");
25 "42\n",
26 );
2724
28 case.addCompareOutput(25 case.addCompareOutput(
29 \\pub fn main() u8 {26 \\pub fn main() void {
30 \\ bar();27 \\ bar();
31 \\ foo();28 \\ foo();
32 \\ foo();29 \\ foo();
33 \\ bar();30 \\ bar();
34 \\ foo();31 \\ foo();
35 \\ bar();32 \\ bar();
36 \\ return 42;
37 \\}33 \\}
38 \\fn foo() void {34 \\fn foo() void {
39 \\ bar();35 \\ bar();
40 \\}36 \\}
41 \\fn bar() void {}37 \\fn bar() void {}
42 ,38 , "");
43 "42\n",
44 );
4539
46 case.addCompareOutput(40 case.addCompareOutput(
47 \\pub fn main() void {41 \\pub fn main() void {
...@@ -56,23 +50,22 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -56,23 +50,22 @@ pub fn addCases(ctx: *TestContext) !void {
56 \\}50 \\}
57 \\fn bar() void {}51 \\fn bar() void {}
58 ,52 ,
59 "0\n",53 "",
60 );54 );
6155
62 case.addCompareOutput(56 case.addCompareOutput(
63 \\pub fn main() u8 {57 \\pub fn main() void {
64 \\ foo(10, 20);58 \\ foo(10, 20);
65 \\ return 5;
66 \\}59 \\}
67 \\fn foo(x: u8, y: u8) void { _ = x; _ = y; }60 \\fn foo(x: u8, y: u8) void { _ = x; _ = y; }
68 , "5\n");61 , "");
69 }62 }
7063
71 {64 {
72 var case = ctx.exe("wasm locals", wasi);65 var case = ctx.exe("wasm locals", wasi);
7366
74 case.addCompareOutput(67 case.addCompareOutput(
75 \\pub fn main() u8 {68 \\pub fn main() void {
76 \\ var i: u8 = 5;69 \\ var i: u8 = 5;
77 \\ var y: f32 = 42.0;70 \\ var y: f32 = 42.0;
78 \\ var x: u8 = 10;71 \\ var x: u8 = 10;
...@@ -80,38 +73,38 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -80,38 +73,38 @@ pub fn addCases(ctx: *TestContext) !void {
80 \\ y;73 \\ y;
81 \\ x;74 \\ x;
82 \\ }75 \\ }
83 \\ return i;76 \\ if (i != 5) unreachable;
84 \\}77 \\}
85 , "5\n");78 , "");
8679
87 case.addCompareOutput(80 case.addCompareOutput(
88 \\pub fn main() u8 {81 \\pub fn main() void {
89 \\ var i: u8 = 5;82 \\ var i: u8 = 5;
90 \\ var y: f32 = 42.0;83 \\ var y: f32 = 42.0;
91 \\ _ = y;84 \\ _ = y;
92 \\ var x: u8 = 10;85 \\ var x: u8 = 10;
93 \\ foo(i, x);86 \\ foo(i, x);
94 \\ i = x;87 \\ i = x;
95 \\ return i;88 \\ if (i != 10) unreachable;
96 \\}89 \\}
97 \\fn foo(x: u8, y: u8) void {90 \\fn foo(x: u8, y: u8) void {
98 \\ _ = y;91 \\ _ = y;
99 \\ var i: u8 = 10;92 \\ var i: u8 = 10;
100 \\ i = x;93 \\ i = x;
101 \\}94 \\}
102 , "10\n");95 , "");
103 }96 }
10497
105 {98 {
106 var case = ctx.exe("wasm binary operands", wasi);99 var case = ctx.exe("wasm binary operands", wasi);
107100
108 case.addCompareOutput(101 case.addCompareOutput(
109 \\pub fn main() u8 {102 \\pub fn main() void {
110 \\ var i: u8 = 5;103 \\ var i: u8 = 5;
111 \\ i += 20;104 \\ i += 20;
112 \\ return i;105 \\ if (i != 25) unreachable;
113 \\}106 \\}
114 , "25\n");107 , "");
115108
116 case.addCompareOutput(109 case.addCompareOutput(
117 \\pub fn main() void {110 \\pub fn main() void {
...@@ -119,7 +112,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -119,7 +112,7 @@ pub fn addCases(ctx: *TestContext) !void {
119 \\ if (i +% 1 != -2147483648) unreachable;112 \\ if (i +% 1 != -2147483648) unreachable;
120 \\ return;113 \\ return;
121 \\}114 \\}
122 , "0\n");115 , "");
123116
124 case.addCompareOutput(117 case.addCompareOutput(
125 \\pub fn main() void {118 \\pub fn main() void {
...@@ -127,34 +120,34 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -127,34 +120,34 @@ pub fn addCases(ctx: *TestContext) !void {
127 \\ if (i +% 1 != 0) unreachable;120 \\ if (i +% 1 != 0) unreachable;
128 \\ return;121 \\ return;
129 \\}122 \\}
130 , "0\n");123 , "");
131124
132 case.addCompareOutput(125 case.addCompareOutput(
133 \\pub fn main() u8 {126 \\pub fn main() u8 {
134 \\ var i: u8 = 255;127 \\ var i: u8 = 255;
135 \\ return i +% 1;128 \\ return i +% 1;
136 \\}129 \\}
137 , "0\n");130 , "");
138131
139 case.addCompareOutput(132 case.addCompareOutput(
140 \\pub fn main() u8 {133 \\pub fn main() u8 {
141 \\ var i: u8 = 5;134 \\ var i: u8 = 5;
142 \\ i += 20;135 \\ i += 20;
143 \\ var result: u8 = foo(i, 10);136 \\ var result: u8 = foo(i, 10);
144 \\ return result;137 \\ return result - 35;
145 \\}138 \\}
146 \\fn foo(x: u8, y: u8) u8 {139 \\fn foo(x: u8, y: u8) u8 {
147 \\ return x + y;140 \\ return x + y;
148 \\}141 \\}
149 , "35\n");142 , "");
150143
151 case.addCompareOutput(144 case.addCompareOutput(
152 \\pub fn main() u8 {145 \\pub fn main() u8 {
153 \\ var i: u8 = 20;146 \\ var i: u8 = 20;
154 \\ i -= 5;147 \\ i -= 5;
155 \\ return i;148 \\ return i - 15;
156 \\}149 \\}
157 , "15\n");150 , "");
158151
159 case.addCompareOutput(152 case.addCompareOutput(
160 \\pub fn main() void {153 \\pub fn main() void {
...@@ -162,7 +155,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -162,7 +155,7 @@ pub fn addCases(ctx: *TestContext) !void {
162 \\ if (i -% 1 != 2147483647) unreachable;155 \\ if (i -% 1 != 2147483647) unreachable;
163 \\ return;156 \\ return;
164 \\}157 \\}
165 , "0\n");158 , "");
166159
167 case.addCompareOutput(160 case.addCompareOutput(
168 \\pub fn main() void {161 \\pub fn main() void {
...@@ -170,26 +163,26 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -170,26 +163,26 @@ pub fn addCases(ctx: *TestContext) !void {
170 \\ if (i -% 1 != 63) unreachable;163 \\ if (i -% 1 != 63) unreachable;
171 \\ return;164 \\ return;
172 \\}165 \\}
173 , "0\n");166 , "");
174167
175 case.addCompareOutput(168 case.addCompareOutput(
176 \\pub fn main() u8 {169 \\pub fn main() void {
177 \\ var i: u4 = 0;170 \\ var i: u4 = 0;
178 \\ return i -% 1;171 \\ if(i -% 1 != 15) unreachable;
179 \\}172 \\}
180 , "15\n");173 , "");
181174
182 case.addCompareOutput(175 case.addCompareOutput(
183 \\pub fn main() u8 {176 \\pub fn main() u8 {
184 \\ var i: u8 = 5;177 \\ var i: u8 = 5;
185 \\ i -= 3;178 \\ i -= 3;
186 \\ var result: u8 = foo(i, 10);179 \\ var result: u8 = foo(i, 10);
187 \\ return result;180 \\ return result - 8;
188 \\}181 \\}
189 \\fn foo(x: u8, y: u8) u8 {182 \\fn foo(x: u8, y: u8) u8 {
190 \\ return y - x;183 \\ return y - x;
191 \\}184 \\}
192 , "8\n");185 , "");
193186
194 case.addCompareOutput(187 case.addCompareOutput(
195 \\pub fn main() void {188 \\pub fn main() void {
...@@ -202,7 +195,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -202,7 +195,7 @@ pub fn addCases(ctx: *TestContext) !void {
202 \\fn foo(x: u32, y: u32) u32 {195 \\fn foo(x: u32, y: u32) u32 {
203 \\ return x * y;196 \\ return x * y;
204 \\}197 \\}
205 , "0\n");198 , "");
206199
207 case.addCompareOutput(200 case.addCompareOutput(
208 \\pub fn main() void {201 \\pub fn main() void {
...@@ -211,7 +204,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -211,7 +204,7 @@ pub fn addCases(ctx: *TestContext) !void {
211 \\ if (result != -2) unreachable;204 \\ if (result != -2) unreachable;
212 \\ return;205 \\ return;
213 \\}206 \\}
214 , "0\n");207 , "");
215208
216 case.addCompareOutput(209 case.addCompareOutput(
217 \\pub fn main() void {210 \\pub fn main() void {
...@@ -219,7 +212,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -219,7 +212,7 @@ pub fn addCases(ctx: *TestContext) !void {
219 \\ if (i *% 3 != 1) unreachable;212 \\ if (i *% 3 != 1) unreachable;
220 \\ return;213 \\ return;
221 \\}214 \\}
222 , "0\n");215 , "");
223216
224 case.addCompareOutput(217 case.addCompareOutput(
225 \\pub fn main() void {218 \\pub fn main() void {
...@@ -227,7 +220,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -227,7 +220,7 @@ pub fn addCases(ctx: *TestContext) !void {
227 \\ if (i *% 3 != 1) unreachable;220 \\ if (i *% 3 != 1) unreachable;
228 \\ return;221 \\ return;
229 \\}222 \\}
230 , "0\n");223 , "");
231224
232 case.addCompareOutput(225 case.addCompareOutput(
233 \\pub fn main() void {226 \\pub fn main() void {
...@@ -240,31 +233,31 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -240,31 +233,31 @@ pub fn addCases(ctx: *TestContext) !void {
240 \\fn foo(x: u32, y: u32) u32 {233 \\fn foo(x: u32, y: u32) u32 {
241 \\ return x / y;234 \\ return x / y;
242 \\}235 \\}
243 , "0\n");236 , "");
244237
245 case.addCompareOutput(238 case.addCompareOutput(
246 \\pub fn main() u8 {239 \\pub fn main() u8 {
247 \\ var i: u8 = 5;240 \\ var i: u8 = 5;
248 \\ i &= 6;241 \\ i &= 6;
249 \\ return i;242 \\ return i - 4;
250 \\}243 \\}
251 , "4\n");244 , "");
252245
253 case.addCompareOutput(246 case.addCompareOutput(
254 \\pub fn main() u8 {247 \\pub fn main() u8 {
255 \\ var i: u8 = 5;248 \\ var i: u8 = 5;
256 \\ i |= 6;249 \\ i |= 6;
257 \\ return i;250 \\ return i - 7;
258 \\}251 \\}
259 , "7\n");252 , "");
260253
261 case.addCompareOutput(254 case.addCompareOutput(
262 \\pub fn main() u8 {255 \\pub fn main() u8 {
263 \\ var i: u8 = 5;256 \\ var i: u8 = 5;
264 \\ i ^= 6;257 \\ i ^= 6;
265 \\ return i;258 \\ return i - 3;
266 \\}259 \\}
267 , "3\n");260 , "");
268261
269 case.addCompareOutput(262 case.addCompareOutput(
270 \\pub fn main() void {263 \\pub fn main() void {
...@@ -273,7 +266,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -273,7 +266,7 @@ pub fn addCases(ctx: *TestContext) !void {
273 \\ if (b) unreachable;266 \\ if (b) unreachable;
274 \\ return;267 \\ return;
275 \\}268 \\}
276 , "0\n");269 , "");
277270
278 case.addCompareOutput(271 case.addCompareOutput(
279 \\pub fn main() void {272 \\pub fn main() void {
...@@ -282,7 +275,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -282,7 +275,7 @@ pub fn addCases(ctx: *TestContext) !void {
282 \\ if (!b) unreachable;275 \\ if (!b) unreachable;
283 \\ return;276 \\ return;
284 \\}277 \\}
285 , "0\n");278 , "");
286279
287 case.addCompareOutput(280 case.addCompareOutput(
288 \\pub fn main() void {281 \\pub fn main() void {
...@@ -291,7 +284,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -291,7 +284,7 @@ pub fn addCases(ctx: *TestContext) !void {
291 \\ if (!b) unreachable;284 \\ if (!b) unreachable;
292 \\ return;285 \\ return;
293 \\}286 \\}
294 , "0\n");287 , "");
295288
296 case.addCompareOutput(289 case.addCompareOutput(
297 \\pub fn main() void {290 \\pub fn main() void {
...@@ -300,7 +293,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -300,7 +293,7 @@ pub fn addCases(ctx: *TestContext) !void {
300 \\ if (!b) unreachable;293 \\ if (!b) unreachable;
301 \\ return;294 \\ return;
302 \\}295 \\}
303 , "0\n");296 , "");
304297
305 case.addCompareOutput(298 case.addCompareOutput(
306 \\pub fn main() void {299 \\pub fn main() void {
...@@ -309,7 +302,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -309,7 +302,7 @@ pub fn addCases(ctx: *TestContext) !void {
309 \\ if (b) unreachable;302 \\ if (b) unreachable;
310 \\ return;303 \\ return;
311 \\}304 \\}
312 , "0\n");305 , "");
313306
314 case.addCompareOutput(307 case.addCompareOutput(
315 \\pub fn main() void {308 \\pub fn main() void {
...@@ -318,7 +311,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -318,7 +311,7 @@ pub fn addCases(ctx: *TestContext) !void {
318 \\ if (b) unreachable;311 \\ if (b) unreachable;
319 \\ return;312 \\ return;
320 \\}313 \\}
321 , "0\n");314 , "");
322315
323 case.addCompareOutput(316 case.addCompareOutput(
324 \\pub fn main() void {317 \\pub fn main() void {
...@@ -327,7 +320,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -327,7 +320,7 @@ pub fn addCases(ctx: *TestContext) !void {
327 \\ if (b) unreachable;320 \\ if (b) unreachable;
328 \\ return;321 \\ return;
329 \\}322 \\}
330 , "0\n");323 , "");
331324
332 case.addCompareOutput(325 case.addCompareOutput(
333 \\pub fn main() void {326 \\pub fn main() void {
...@@ -336,7 +329,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -336,7 +329,7 @@ pub fn addCases(ctx: *TestContext) !void {
336 \\ if (!b) unreachable;329 \\ if (!b) unreachable;
337 \\ return;330 \\ return;
338 \\}331 \\}
339 , "0\n");332 , "");
340 }333 }
341334
342 {335 {
...@@ -348,9 +341,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -348,9 +341,9 @@ pub fn addCases(ctx: *TestContext) !void {
348 \\ if (i > @as(u8, 4)) {341 \\ if (i > @as(u8, 4)) {
349 \\ i += 10;342 \\ i += 10;
350 \\ }343 \\ }
351 \\ return i;344 \\ return i - 15;
352 \\}345 \\}
353 , "15\n");346 , "");
354347
355 case.addCompareOutput(348 case.addCompareOutput(
356 \\pub fn main() u8 {349 \\pub fn main() u8 {
...@@ -360,9 +353,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -360,9 +353,9 @@ pub fn addCases(ctx: *TestContext) !void {
360 \\ } else {353 \\ } else {
361 \\ i = 2;354 \\ i = 2;
362 \\ }355 \\ }
363 \\ return i;356 \\ return i - 2;
364 \\}357 \\}
365 , "2\n");358 , "");
366359
367 case.addCompareOutput(360 case.addCompareOutput(
368 \\pub fn main() u8 {361 \\pub fn main() u8 {
...@@ -372,9 +365,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -372,9 +365,9 @@ pub fn addCases(ctx: *TestContext) !void {
372 \\ } else if(i == @as(u8, 5)) {365 \\ } else if(i == @as(u8, 5)) {
373 \\ i = 20;366 \\ i = 20;
374 \\ }367 \\ }
375 \\ return i;368 \\ return i - 20;
376 \\}369 \\}
377 , "20\n");370 , "");
378371
379 case.addCompareOutput(372 case.addCompareOutput(
380 \\pub fn main() u8 {373 \\pub fn main() u8 {
...@@ -388,9 +381,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -388,9 +381,9 @@ pub fn addCases(ctx: *TestContext) !void {
388 \\ i = 20;381 \\ i = 20;
389 \\ }382 \\ }
390 \\ }383 \\ }
391 \\ return i;384 \\ return i - 31;
392 \\}385 \\}
393 , "31\n");386 , "");
394387
395 case.addCompareOutput(388 case.addCompareOutput(
396 \\pub fn main() void {389 \\pub fn main() void {
...@@ -405,7 +398,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -405,7 +398,7 @@ pub fn addCases(ctx: *TestContext) !void {
405 \\ const x = if(ok) @as(i32, 20) else @as(i32, 10);398 \\ const x = if(ok) @as(i32, 20) else @as(i32, 10);
406 \\ return x;399 \\ return x;
407 \\}400 \\}
408 , "0\n");401 , "");
409402
410 case.addCompareOutput(403 case.addCompareOutput(
411 \\pub fn main() void {404 \\pub fn main() void {
...@@ -425,7 +418,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -425,7 +418,7 @@ pub fn addCases(ctx: *TestContext) !void {
425 \\ };418 \\ };
426 \\ return val + 10;419 \\ return val + 10;
427 \\}420 \\}
428 , "0\n");421 , "");
429 }422 }
430423
431 {424 {
...@@ -438,9 +431,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -438,9 +431,9 @@ pub fn addCases(ctx: *TestContext) !void {
438 \\ i += 1;431 \\ i += 1;
439 \\ }432 \\ }
440 \\433 \\
441 \\ return i;434 \\ return i - 5;
442 \\}435 \\}
443 , "5\n");436 , "");
444437
445 case.addCompareOutput(438 case.addCompareOutput(
446 \\pub fn main() u8 {439 \\pub fn main() u8 {
...@@ -449,9 +442,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -449,9 +442,9 @@ pub fn addCases(ctx: *TestContext) !void {
449 \\ var x: u8 = 1;442 \\ var x: u8 = 1;
450 \\ i += x;443 \\ i += x;
451 \\ }444 \\ }
452 \\ return i;445 \\ return i - 10;
453 \\}446 \\}
454 , "10\n");447 , "");
455448
456 case.addCompareOutput(449 case.addCompareOutput(
457 \\pub fn main() u8 {450 \\pub fn main() u8 {
...@@ -461,9 +454,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -461,9 +454,9 @@ pub fn addCases(ctx: *TestContext) !void {
461 \\ i += x;454 \\ i += x;
462 \\ if (i == @as(u8, 5)) break;455 \\ if (i == @as(u8, 5)) break;
463 \\ }456 \\ }
464 \\ return i;457 \\ return i - 5;
465 \\}458 \\}
466 , "5\n");459 , "");
467 }460 }
468461
469 {462 {
...@@ -485,7 +478,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -485,7 +478,7 @@ pub fn addCases(ctx: *TestContext) !void {
485 \\ }478 \\ }
486 \\ return;479 \\ return;
487 \\}480 \\}
488 , "0\n");481 , "");
489482
490 case.addCompareOutput(483 case.addCompareOutput(
491 \\const Number = enum { One, Two, Three };484 \\const Number = enum { One, Two, Three };
...@@ -507,7 +500,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -507,7 +500,7 @@ pub fn addCases(ctx: *TestContext) !void {
507 \\fn assert(val: bool) void {500 \\fn assert(val: bool) void {
508 \\ if(!val) unreachable;501 \\ if(!val) unreachable;
509 \\}502 \\}
510 , "0\n");503 , "");
511 }504 }
512505
513 {506 {
...@@ -518,9 +511,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -518,9 +511,9 @@ pub fn addCases(ctx: *TestContext) !void {
518 \\511 \\
519 \\pub fn main() u8 {512 \\pub fn main() u8 {
520 \\ var example: Example = .{ .x = 5 };513 \\ var example: Example = .{ .x = 5 };
521 \\ return example.x;514 \\ return example.x - 5;
522 \\}515 \\}
523 , "5\n");516 , "");
524517
525 case.addCompareOutput(518 case.addCompareOutput(
526 \\const Example = struct { x: u8 };519 \\const Example = struct { x: u8 };
...@@ -528,18 +521,18 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -528,18 +521,18 @@ pub fn addCases(ctx: *TestContext) !void {
528 \\pub fn main() u8 {521 \\pub fn main() u8 {
529 \\ var example: Example = .{ .x = 5 };522 \\ var example: Example = .{ .x = 5 };
530 \\ example.x = 10;523 \\ example.x = 10;
531 \\ return example.x;524 \\ return example.x - 10;
532 \\}525 \\}
533 , "10\n");526 , "");
534527
535 case.addCompareOutput(528 case.addCompareOutput(
536 \\const Example = struct { x: u8, y: u8 };529 \\const Example = struct { x: u8, y: u8 };
537 \\530 \\
538 \\pub fn main() u8 {531 \\pub fn main() u8 {
539 \\ var example: Example = .{ .x = 5, .y = 10 };532 \\ var example: Example = .{ .x = 5, .y = 10 };
540 \\ return example.y + example.x;533 \\ return example.y + example.x - 15;
541 \\}534 \\}
542 , "15\n");535 , "");
543536
544 case.addCompareOutput(537 case.addCompareOutput(
545 \\const Example = struct { x: u8, y: u8 };538 \\const Example = struct { x: u8, y: u8 };
...@@ -549,9 +542,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -549,9 +542,9 @@ pub fn addCases(ctx: *TestContext) !void {
549 \\ var example2: Example = .{ .x = 10, .y = 20 };542 \\ var example2: Example = .{ .x = 10, .y = 20 };
550 \\543 \\
551 \\ example = example2;544 \\ example = example2;
552 \\ return example.y + example.x;545 \\ return example.y + example.x - 30;
553 \\}546 \\}
554 , "30\n");547 , "");
555548
556 case.addCompareOutput(549 case.addCompareOutput(
557 \\const Example = struct { x: u8, y: u8 };550 \\const Example = struct { x: u8, y: u8 };
...@@ -560,9 +553,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -560,9 +553,9 @@ pub fn addCases(ctx: *TestContext) !void {
560 \\ var example: Example = .{ .x = 5, .y = 10 };553 \\ var example: Example = .{ .x = 5, .y = 10 };
561 \\554 \\
562 \\ example = .{ .x = 10, .y = 20 };555 \\ example = .{ .x = 10, .y = 20 };
563 \\ return example.y + example.x;556 \\ return example.y + example.x - 30;
564 \\}557 \\}
565 , "30\n");558 , "");
566 }559 }
567560
568 {561 {
...@@ -578,9 +571,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -578,9 +571,9 @@ pub fn addCases(ctx: *TestContext) !void {
578 \\ else => 5,571 \\ else => 5,
579 \\ };572 \\ };
580 \\573 \\
581 \\ return a;574 \\ return a - 2;
582 \\}575 \\}
583 , "2\n");576 , "");
584577
585 case.addCompareOutput(578 case.addCompareOutput(
586 \\pub fn main() u8 {579 \\pub fn main() u8 {
...@@ -592,9 +585,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -592,9 +585,9 @@ pub fn addCases(ctx: *TestContext) !void {
592 \\ else => 5,585 \\ else => 5,
593 \\ };586 \\ };
594 \\587 \\
595 \\ return a;588 \\ return a - 3;
596 \\}589 \\}
597 , "3\n");590 , "");
598591
599 case.addCompareOutput(592 case.addCompareOutput(
600 \\pub fn main() u8 {593 \\pub fn main() u8 {
...@@ -606,9 +599,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -606,9 +599,9 @@ pub fn addCases(ctx: *TestContext) !void {
606 \\ else => 5,599 \\ else => 5,
607 \\ };600 \\ };
608 \\601 \\
609 \\ return a;602 \\ return a - 5;
610 \\}603 \\}
611 , "5\n");604 , "");
612605
613 case.addCompareOutput(606 case.addCompareOutput(
614 \\const MyEnum = enum { One, Two, Three };607 \\const MyEnum = enum { One, Two, Three };
...@@ -621,9 +614,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -621,9 +614,9 @@ pub fn addCases(ctx: *TestContext) !void {
621 \\ .Three => 3,614 \\ .Three => 3,
622 \\ };615 \\ };
623 \\616 \\
624 \\ return a;617 \\ return a - 2;
625 \\}618 \\}
626 , "2\n");619 , "");
627 }620 }
628621
629 {622 {
...@@ -641,35 +634,35 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -641,35 +634,35 @@ pub fn addCases(ctx: *TestContext) !void {
641 \\fn assert(b: bool) void {634 \\fn assert(b: bool) void {
642 \\ if (!b) unreachable;635 \\ if (!b) unreachable;
643 \\}636 \\}
644 , "0\n");637 , "");
645638
646 case.addCompareOutput(639 case.addCompareOutput(
647 \\pub fn main() u8 {640 \\pub fn main() u8 {
648 \\ var e: anyerror!u8 = 5;641 \\ var e: anyerror!u8 = 5;
649 \\ const i = e catch 10;642 \\ const i = e catch 10;
650 \\ return i;643 \\ return i - 5;
651 \\}644 \\}
652 , "5\n");645 , "");
653646
654 case.addCompareOutput(647 case.addCompareOutput(
655 \\pub fn main() u8 {648 \\pub fn main() u8 {
656 \\ var e: anyerror!u8 = error.Foo;649 \\ var e: anyerror!u8 = error.Foo;
657 \\ const i = e catch 10;650 \\ const i = e catch 10;
658 \\ return i;651 \\ return i - 10;
659 \\}652 \\}
660 , "10\n");653 , "");
661654
662 case.addCompareOutput(655 case.addCompareOutput(
663 \\pub fn main() u8 {656 \\pub fn main() u8 {
664 \\ var e = foo();657 \\ var e = foo();
665 \\ const i = e catch 69;658 \\ const i = e catch 69;
666 \\ return i;659 \\ return i - 5;
667 \\}660 \\}
668 \\661 \\
669 \\fn foo() anyerror!u8 {662 \\fn foo() anyerror!u8 {
670 \\ return 5;663 \\ return 5;
671 \\}664 \\}
672 , "5\n");665 , "");
673 }666 }
674667
675 {668 {
...@@ -679,24 +672,24 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -679,24 +672,24 @@ pub fn addCases(ctx: *TestContext) !void {
679 \\pub fn main() u8 {672 \\pub fn main() u8 {
680 \\ var e = foo();673 \\ var e = foo();
681 \\ const i = e catch 69;674 \\ const i = e catch 69;
682 \\ return i;675 \\ return i - 69;
683 \\}676 \\}
684 \\677 \\
685 \\fn foo() anyerror!u8 {678 \\fn foo() anyerror!u8 {
686 \\ return error.Bruh;679 \\ return error.Bruh;
687 \\}680 \\}
688 , "69\n");681 , "");
689 case.addCompareOutput(682 case.addCompareOutput(
690 \\pub fn main() u8 {683 \\pub fn main() u8 {
691 \\ var e = foo();684 \\ var e = foo();
692 \\ const i = e catch 42;685 \\ const i = e catch 42;
693 \\ return i;686 \\ return i - 42;
694 \\}687 \\}
695 \\688 \\
696 \\fn foo() anyerror!u8 {689 \\fn foo() anyerror!u8 {
697 \\ return error.Dab;690 \\ return error.Dab;
698 \\}691 \\}
699 , "42\n");692 , "");
700 }693 }
701694
702 {695 {
...@@ -709,7 +702,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -709,7 +702,7 @@ pub fn addCases(ctx: *TestContext) !void {
709 \\ _ = y;702 \\ _ = y;
710 \\ return;703 \\ return;
711 \\}704 \\}
712 , "0\n");705 , "");
713 }706 }
714707
715 {708 {
...@@ -722,9 +715,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -722,9 +715,9 @@ pub fn addCases(ctx: *TestContext) !void {
722 \\ if (x) |val| {715 \\ if (x) |val| {
723 \\ y = val;716 \\ y = val;
724 \\ }717 \\ }
725 \\ return y;718 \\ return y - 5;
726 \\}719 \\}
727 , "5\n");720 , "");
728721
729 case.addCompareOutput(722 case.addCompareOutput(
730 \\pub fn main() u8 {723 \\pub fn main() u8 {
...@@ -735,22 +728,22 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -735,22 +728,22 @@ pub fn addCases(ctx: *TestContext) !void {
735 \\ }728 \\ }
736 \\ return y;729 \\ return y;
737 \\}730 \\}
738 , "0\n");731 , "");
739732
740 case.addCompareOutput(733 case.addCompareOutput(
741 \\pub fn main() u8 {734 \\pub fn main() u8 {
742 \\ var x: ?u8 = 5;735 \\ var x: ?u8 = 5;
743 \\ return x.?;736 \\ return x.? - 5;
744 \\}737 \\}
745 , "5\n");738 , "");
746739
747 case.addCompareOutput(740 case.addCompareOutput(
748 \\pub fn main() u8 {741 \\pub fn main() u8 {
749 \\ var x: u8 = 5;742 \\ var x: u8 = 5;
750 \\ var y: ?u8 = x;743 \\ var y: ?u8 = x;
751 \\ return y.?;744 \\ return y.? - 5;
752 \\}745 \\}
753 , "5\n");746 , "");
754747
755 case.addCompareOutput(748 case.addCompareOutput(
756 \\pub fn main() u8 {749 \\pub fn main() u8 {
...@@ -763,7 +756,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -763,7 +756,7 @@ pub fn addCases(ctx: *TestContext) !void {
763 \\ }756 \\ }
764 \\ return 0;757 \\ return 0;
765 \\}758 \\}
766 , "0\n");759 , "");
767 }760 }
768761
769 {762 {
...@@ -774,13 +767,13 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -774,13 +767,13 @@ pub fn addCases(ctx: *TestContext) !void {
774 \\ var x: u8 = 0;767 \\ var x: u8 = 0;
775 \\768 \\
776 \\ foo(&x);769 \\ foo(&x);
777 \\ return x;770 \\ return x - 2;
778 \\}771 \\}
779 \\772 \\
780 \\fn foo(x: *u8)void {773 \\fn foo(x: *u8)void {
781 \\ x.* = 2;774 \\ x.* = 2;
782 \\}775 \\}
783 , "2\n");776 , "");
784777
785 case.addCompareOutput(778 case.addCompareOutput(
786 \\pub fn main() u8 {779 \\pub fn main() u8 {
...@@ -788,7 +781,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -788,7 +781,7 @@ pub fn addCases(ctx: *TestContext) !void {
788 \\781 \\
789 \\ foo(&x);782 \\ foo(&x);
790 \\ bar(&x);783 \\ bar(&x);
791 \\ return x;784 \\ return x - 4;
792 \\}785 \\}
793 \\786 \\
794 \\fn foo(x: *u8)void {787 \\fn foo(x: *u8)void {
...@@ -798,6 +791,6 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -798,6 +791,6 @@ pub fn addCases(ctx: *TestContext) !void {
798 \\fn bar(x: *u8) void {791 \\fn bar(x: *u8) void {
799 \\ x.* += 2;792 \\ x.* += 2;
800 \\}793 \\}
801 , "4\n");794 , "");
802 }795 }
803}796}