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 {
144144 }
145145 };
146146 }
147 if (builtin.zig_backend == .stage2_llvm) {
147 if (builtin.zig_backend == .stage2_llvm or builtin.zig_backend == .stage2_wasm) {
148148 const passed = builtin.test_functions.len - skipped - failed;
149149 const stderr = std.io.getStdErr();
150150 writeInt(stderr, passed) catch {};
lib/std/start.zig+4-4
......@@ -31,7 +31,7 @@ comptime {
3131 } else if (builtin.os.tag == .windows) {
3232 @export(wWinMainCRTStartup2, .{ .name = "wWinMainCRTStartup" });
3333 } else if (builtin.os.tag == .wasi and @hasDecl(root, "main")) {
34 @export(wasmMain2, .{ .name = "_start" });
34 @export(wasiMain2, .{ .name = "_start" });
3535 } else {
3636 if (!@hasDecl(root, "_start")) {
3737 @export(_start2, .{ .name = "_start" });
......@@ -100,17 +100,17 @@ fn callMain2() noreturn {
100100 exit2(0);
101101}
102102
103fn wasmMain2() u8 {
103fn wasiMain2() noreturn {
104104 switch (@typeInfo(@typeInfo(@TypeOf(root.main)).Fn.return_type.?)) {
105105 .Void => {
106106 root.main();
107 return 0;
107 std.os.wasi.proc_exit(0);
108108 },
109109 .Int => |info| {
110110 if (info.bits != 8 or info.signedness == .signed) {
111111 @compileError(bad_main_ret);
112112 }
113 return root.main();
113 std.os.wasi.proc_exit(root.main());
114114 },
115115 else => @compileError("Bad return type main"),
116116 }
src/arch/wasm/CodeGen.zig+1-1
......@@ -954,7 +954,7 @@ pub const DeclGen = struct {
954954 } else if (decl.val.castTag(.extern_fn)) |extern_fn| {
955955 const ext_decl = extern_fn.data.owner_decl;
956956 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);
958958 ext_decl.fn_link.wasm.type_index = try self.bin_file.putOrGetFuncType(func_type);
959959 return Result{ .appended = {} };
960960 } else {
src/link/Wasm.zig+10-6
......@@ -260,7 +260,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void {
260260 if (build_options.have_llvm) {
261261 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(module, decl);
262262 }
263 if (!decl.ty.hasRuntimeBits()) return;
263
264264 assert(decl.link.wasm.sym_index != 0); // Must call allocateDeclIndexes()
265265
266266 decl.link.wasm.clear();
......@@ -297,8 +297,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void {
297297
298298fn finishUpdateDecl(self: *Wasm, decl: *Module.Decl, code: []const u8) !void {
299299 if (decl.isExtern()) {
300 try self.addOrUpdateImport(decl);
301 return;
300 return self.addOrUpdateImport(decl);
302301 }
303302
304303 if (code.len == 0) return;
......@@ -407,16 +406,18 @@ pub fn freeDecl(self: *Wasm, decl: *Module.Decl) void {
407406 self.symbols.items[atom.sym_index].tag = .dead; // to ensure it does not end in the names section
408407 for (atom.locals.items) |local_atom| {
409408 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 {};
410410 }
411 atom.deinit(self.base.allocator);
412411
413412 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;
415414 switch (import.kind) {
416415 .function => self.imported_functions_count -= 1,
417416 else => unreachable,
418417 }
419418 }
419
420 atom.deinit(self.base.allocator);
420421}
421422
422423/// Appends a new entry to the indirect function table
......@@ -441,10 +442,13 @@ fn addOrUpdateImport(self: *Wasm, decl: *Module.Decl) !void {
441442 switch (decl.ty.zigTypeTag()) {
442443 .Fn => {
443444 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;
444448 if (!gop.found_existing) {
445449 self.imported_functions_count += 1;
446450 gop.value_ptr.* = .{
447 .module_name = self.host_name,
451 .module_name = module_name,
448452 .name = std.mem.span(symbol.name),
449453 .kind = .{ .function = decl.fn_link.wasm.type_index },
450454 };
src/link/Wasm/Symbol.zig+3-2
......@@ -142,19 +142,20 @@ pub fn format(self: Symbol, comptime fmt: []const u8, options: std.fmt.FormatOpt
142142 _ = fmt;
143143 _ = options;
144144
145 const kind_fmt: u8 = switch (self.kind) {
145 const kind_fmt: u8 = switch (self.tag) {
146146 .function => 'F',
147147 .data => 'D',
148148 .global => 'G',
149149 .section => 'S',
150150 .event => 'E',
151151 .table => 'T',
152 .dead => '-',
152153 };
153154 const visible: []const u8 = if (self.isVisible()) "yes" else "no";
154155 const binding: []const u8 = if (self.isLocal()) "local" else "global";
155156
156157 try writer.print(
157158 "{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 },
159160 );
160161}
test/stage2/wasm.zig+109-116
......@@ -11,37 +11,31 @@ pub fn addCases(ctx: *TestContext) !void {
1111 var case = ctx.exe("wasm function calls", wasi);
1212
1313 case.addCompareOutput(
14 \\pub fn main() u8 {
14 \\pub fn main() void {
1515 \\ foo();
1616 \\ bar();
17 \\ return 42;
1817 \\}
1918 \\fn foo() void {
2019 \\ bar();
2120 \\ bar();
2221 \\}
2322 \\fn bar() void {}
24 ,
25 "42\n",
26 );
23 , "");
2724
2825 case.addCompareOutput(
29 \\pub fn main() u8 {
26 \\pub fn main() void {
3027 \\ bar();
3128 \\ foo();
3229 \\ foo();
3330 \\ bar();
3431 \\ foo();
3532 \\ bar();
36 \\ return 42;
3733 \\}
3834 \\fn foo() void {
3935 \\ bar();
4036 \\}
4137 \\fn bar() void {}
42 ,
43 "42\n",
44 );
38 , "");
4539
4640 case.addCompareOutput(
4741 \\pub fn main() void {
......@@ -56,23 +50,22 @@ pub fn addCases(ctx: *TestContext) !void {
5650 \\}
5751 \\fn bar() void {}
5852 ,
59 "0\n",
53 "",
6054 );
6155
6256 case.addCompareOutput(
63 \\pub fn main() u8 {
57 \\pub fn main() void {
6458 \\ foo(10, 20);
65 \\ return 5;
6659 \\}
6760 \\fn foo(x: u8, y: u8) void { _ = x; _ = y; }
68 , "5\n");
61 , "");
6962 }
7063
7164 {
7265 var case = ctx.exe("wasm locals", wasi);
7366
7467 case.addCompareOutput(
75 \\pub fn main() u8 {
68 \\pub fn main() void {
7669 \\ var i: u8 = 5;
7770 \\ var y: f32 = 42.0;
7871 \\ var x: u8 = 10;
......@@ -80,38 +73,38 @@ pub fn addCases(ctx: *TestContext) !void {
8073 \\ y;
8174 \\ x;
8275 \\ }
83 \\ return i;
76 \\ if (i != 5) unreachable;
8477 \\}
85 , "5\n");
78 , "");
8679
8780 case.addCompareOutput(
88 \\pub fn main() u8 {
81 \\pub fn main() void {
8982 \\ var i: u8 = 5;
9083 \\ var y: f32 = 42.0;
9184 \\ _ = y;
9285 \\ var x: u8 = 10;
9386 \\ foo(i, x);
9487 \\ i = x;
95 \\ return i;
88 \\ if (i != 10) unreachable;
9689 \\}
9790 \\fn foo(x: u8, y: u8) void {
9891 \\ _ = y;
9992 \\ var i: u8 = 10;
10093 \\ i = x;
10194 \\}
102 , "10\n");
95 , "");
10396 }
10497
10598 {
10699 var case = ctx.exe("wasm binary operands", wasi);
107100
108101 case.addCompareOutput(
109 \\pub fn main() u8 {
102 \\pub fn main() void {
110103 \\ var i: u8 = 5;
111104 \\ i += 20;
112 \\ return i;
105 \\ if (i != 25) unreachable;
113106 \\}
114 , "25\n");
107 , "");
115108
116109 case.addCompareOutput(
117110 \\pub fn main() void {
......@@ -119,7 +112,7 @@ pub fn addCases(ctx: *TestContext) !void {
119112 \\ if (i +% 1 != -2147483648) unreachable;
120113 \\ return;
121114 \\}
122 , "0\n");
115 , "");
123116
124117 case.addCompareOutput(
125118 \\pub fn main() void {
......@@ -127,34 +120,34 @@ pub fn addCases(ctx: *TestContext) !void {
127120 \\ if (i +% 1 != 0) unreachable;
128121 \\ return;
129122 \\}
130 , "0\n");
123 , "");
131124
132125 case.addCompareOutput(
133126 \\pub fn main() u8 {
134127 \\ var i: u8 = 255;
135128 \\ return i +% 1;
136129 \\}
137 , "0\n");
130 , "");
138131
139132 case.addCompareOutput(
140133 \\pub fn main() u8 {
141134 \\ var i: u8 = 5;
142135 \\ i += 20;
143136 \\ var result: u8 = foo(i, 10);
144 \\ return result;
137 \\ return result - 35;
145138 \\}
146139 \\fn foo(x: u8, y: u8) u8 {
147140 \\ return x + y;
148141 \\}
149 , "35\n");
142 , "");
150143
151144 case.addCompareOutput(
152145 \\pub fn main() u8 {
153146 \\ var i: u8 = 20;
154147 \\ i -= 5;
155 \\ return i;
148 \\ return i - 15;
156149 \\}
157 , "15\n");
150 , "");
158151
159152 case.addCompareOutput(
160153 \\pub fn main() void {
......@@ -162,7 +155,7 @@ pub fn addCases(ctx: *TestContext) !void {
162155 \\ if (i -% 1 != 2147483647) unreachable;
163156 \\ return;
164157 \\}
165 , "0\n");
158 , "");
166159
167160 case.addCompareOutput(
168161 \\pub fn main() void {
......@@ -170,26 +163,26 @@ pub fn addCases(ctx: *TestContext) !void {
170163 \\ if (i -% 1 != 63) unreachable;
171164 \\ return;
172165 \\}
173 , "0\n");
166 , "");
174167
175168 case.addCompareOutput(
176 \\pub fn main() u8 {
169 \\pub fn main() void {
177170 \\ var i: u4 = 0;
178 \\ return i -% 1;
171 \\ if(i -% 1 != 15) unreachable;
179172 \\}
180 , "15\n");
173 , "");
181174
182175 case.addCompareOutput(
183176 \\pub fn main() u8 {
184177 \\ var i: u8 = 5;
185178 \\ i -= 3;
186179 \\ var result: u8 = foo(i, 10);
187 \\ return result;
180 \\ return result - 8;
188181 \\}
189182 \\fn foo(x: u8, y: u8) u8 {
190183 \\ return y - x;
191184 \\}
192 , "8\n");
185 , "");
193186
194187 case.addCompareOutput(
195188 \\pub fn main() void {
......@@ -202,7 +195,7 @@ pub fn addCases(ctx: *TestContext) !void {
202195 \\fn foo(x: u32, y: u32) u32 {
203196 \\ return x * y;
204197 \\}
205 , "0\n");
198 , "");
206199
207200 case.addCompareOutput(
208201 \\pub fn main() void {
......@@ -211,7 +204,7 @@ pub fn addCases(ctx: *TestContext) !void {
211204 \\ if (result != -2) unreachable;
212205 \\ return;
213206 \\}
214 , "0\n");
207 , "");
215208
216209 case.addCompareOutput(
217210 \\pub fn main() void {
......@@ -219,7 +212,7 @@ pub fn addCases(ctx: *TestContext) !void {
219212 \\ if (i *% 3 != 1) unreachable;
220213 \\ return;
221214 \\}
222 , "0\n");
215 , "");
223216
224217 case.addCompareOutput(
225218 \\pub fn main() void {
......@@ -227,7 +220,7 @@ pub fn addCases(ctx: *TestContext) !void {
227220 \\ if (i *% 3 != 1) unreachable;
228221 \\ return;
229222 \\}
230 , "0\n");
223 , "");
231224
232225 case.addCompareOutput(
233226 \\pub fn main() void {
......@@ -240,31 +233,31 @@ pub fn addCases(ctx: *TestContext) !void {
240233 \\fn foo(x: u32, y: u32) u32 {
241234 \\ return x / y;
242235 \\}
243 , "0\n");
236 , "");
244237
245238 case.addCompareOutput(
246239 \\pub fn main() u8 {
247240 \\ var i: u8 = 5;
248241 \\ i &= 6;
249 \\ return i;
242 \\ return i - 4;
250243 \\}
251 , "4\n");
244 , "");
252245
253246 case.addCompareOutput(
254247 \\pub fn main() u8 {
255248 \\ var i: u8 = 5;
256249 \\ i |= 6;
257 \\ return i;
250 \\ return i - 7;
258251 \\}
259 , "7\n");
252 , "");
260253
261254 case.addCompareOutput(
262255 \\pub fn main() u8 {
263256 \\ var i: u8 = 5;
264257 \\ i ^= 6;
265 \\ return i;
258 \\ return i - 3;
266259 \\}
267 , "3\n");
260 , "");
268261
269262 case.addCompareOutput(
270263 \\pub fn main() void {
......@@ -273,7 +266,7 @@ pub fn addCases(ctx: *TestContext) !void {
273266 \\ if (b) unreachable;
274267 \\ return;
275268 \\}
276 , "0\n");
269 , "");
277270
278271 case.addCompareOutput(
279272 \\pub fn main() void {
......@@ -282,7 +275,7 @@ pub fn addCases(ctx: *TestContext) !void {
282275 \\ if (!b) unreachable;
283276 \\ return;
284277 \\}
285 , "0\n");
278 , "");
286279
287280 case.addCompareOutput(
288281 \\pub fn main() void {
......@@ -291,7 +284,7 @@ pub fn addCases(ctx: *TestContext) !void {
291284 \\ if (!b) unreachable;
292285 \\ return;
293286 \\}
294 , "0\n");
287 , "");
295288
296289 case.addCompareOutput(
297290 \\pub fn main() void {
......@@ -300,7 +293,7 @@ pub fn addCases(ctx: *TestContext) !void {
300293 \\ if (!b) unreachable;
301294 \\ return;
302295 \\}
303 , "0\n");
296 , "");
304297
305298 case.addCompareOutput(
306299 \\pub fn main() void {
......@@ -309,7 +302,7 @@ pub fn addCases(ctx: *TestContext) !void {
309302 \\ if (b) unreachable;
310303 \\ return;
311304 \\}
312 , "0\n");
305 , "");
313306
314307 case.addCompareOutput(
315308 \\pub fn main() void {
......@@ -318,7 +311,7 @@ pub fn addCases(ctx: *TestContext) !void {
318311 \\ if (b) unreachable;
319312 \\ return;
320313 \\}
321 , "0\n");
314 , "");
322315
323316 case.addCompareOutput(
324317 \\pub fn main() void {
......@@ -327,7 +320,7 @@ pub fn addCases(ctx: *TestContext) !void {
327320 \\ if (b) unreachable;
328321 \\ return;
329322 \\}
330 , "0\n");
323 , "");
331324
332325 case.addCompareOutput(
333326 \\pub fn main() void {
......@@ -336,7 +329,7 @@ pub fn addCases(ctx: *TestContext) !void {
336329 \\ if (!b) unreachable;
337330 \\ return;
338331 \\}
339 , "0\n");
332 , "");
340333 }
341334
342335 {
......@@ -348,9 +341,9 @@ pub fn addCases(ctx: *TestContext) !void {
348341 \\ if (i > @as(u8, 4)) {
349342 \\ i += 10;
350343 \\ }
351 \\ return i;
344 \\ return i - 15;
352345 \\}
353 , "15\n");
346 , "");
354347
355348 case.addCompareOutput(
356349 \\pub fn main() u8 {
......@@ -360,9 +353,9 @@ pub fn addCases(ctx: *TestContext) !void {
360353 \\ } else {
361354 \\ i = 2;
362355 \\ }
363 \\ return i;
356 \\ return i - 2;
364357 \\}
365 , "2\n");
358 , "");
366359
367360 case.addCompareOutput(
368361 \\pub fn main() u8 {
......@@ -372,9 +365,9 @@ pub fn addCases(ctx: *TestContext) !void {
372365 \\ } else if(i == @as(u8, 5)) {
373366 \\ i = 20;
374367 \\ }
375 \\ return i;
368 \\ return i - 20;
376369 \\}
377 , "20\n");
370 , "");
378371
379372 case.addCompareOutput(
380373 \\pub fn main() u8 {
......@@ -388,9 +381,9 @@ pub fn addCases(ctx: *TestContext) !void {
388381 \\ i = 20;
389382 \\ }
390383 \\ }
391 \\ return i;
384 \\ return i - 31;
392385 \\}
393 , "31\n");
386 , "");
394387
395388 case.addCompareOutput(
396389 \\pub fn main() void {
......@@ -405,7 +398,7 @@ pub fn addCases(ctx: *TestContext) !void {
405398 \\ const x = if(ok) @as(i32, 20) else @as(i32, 10);
406399 \\ return x;
407400 \\}
408 , "0\n");
401 , "");
409402
410403 case.addCompareOutput(
411404 \\pub fn main() void {
......@@ -425,7 +418,7 @@ pub fn addCases(ctx: *TestContext) !void {
425418 \\ };
426419 \\ return val + 10;
427420 \\}
428 , "0\n");
421 , "");
429422 }
430423
431424 {
......@@ -438,9 +431,9 @@ pub fn addCases(ctx: *TestContext) !void {
438431 \\ i += 1;
439432 \\ }
440433 \\
441 \\ return i;
434 \\ return i - 5;
442435 \\}
443 , "5\n");
436 , "");
444437
445438 case.addCompareOutput(
446439 \\pub fn main() u8 {
......@@ -449,9 +442,9 @@ pub fn addCases(ctx: *TestContext) !void {
449442 \\ var x: u8 = 1;
450443 \\ i += x;
451444 \\ }
452 \\ return i;
445 \\ return i - 10;
453446 \\}
454 , "10\n");
447 , "");
455448
456449 case.addCompareOutput(
457450 \\pub fn main() u8 {
......@@ -461,9 +454,9 @@ pub fn addCases(ctx: *TestContext) !void {
461454 \\ i += x;
462455 \\ if (i == @as(u8, 5)) break;
463456 \\ }
464 \\ return i;
457 \\ return i - 5;
465458 \\}
466 , "5\n");
459 , "");
467460 }
468461
469462 {
......@@ -485,7 +478,7 @@ pub fn addCases(ctx: *TestContext) !void {
485478 \\ }
486479 \\ return;
487480 \\}
488 , "0\n");
481 , "");
489482
490483 case.addCompareOutput(
491484 \\const Number = enum { One, Two, Three };
......@@ -507,7 +500,7 @@ pub fn addCases(ctx: *TestContext) !void {
507500 \\fn assert(val: bool) void {
508501 \\ if(!val) unreachable;
509502 \\}
510 , "0\n");
503 , "");
511504 }
512505
513506 {
......@@ -518,9 +511,9 @@ pub fn addCases(ctx: *TestContext) !void {
518511 \\
519512 \\pub fn main() u8 {
520513 \\ var example: Example = .{ .x = 5 };
521 \\ return example.x;
514 \\ return example.x - 5;
522515 \\}
523 , "5\n");
516 , "");
524517
525518 case.addCompareOutput(
526519 \\const Example = struct { x: u8 };
......@@ -528,18 +521,18 @@ pub fn addCases(ctx: *TestContext) !void {
528521 \\pub fn main() u8 {
529522 \\ var example: Example = .{ .x = 5 };
530523 \\ example.x = 10;
531 \\ return example.x;
524 \\ return example.x - 10;
532525 \\}
533 , "10\n");
526 , "");
534527
535528 case.addCompareOutput(
536529 \\const Example = struct { x: u8, y: u8 };
537530 \\
538531 \\pub fn main() u8 {
539532 \\ var example: Example = .{ .x = 5, .y = 10 };
540 \\ return example.y + example.x;
533 \\ return example.y + example.x - 15;
541534 \\}
542 , "15\n");
535 , "");
543536
544537 case.addCompareOutput(
545538 \\const Example = struct { x: u8, y: u8 };
......@@ -549,9 +542,9 @@ pub fn addCases(ctx: *TestContext) !void {
549542 \\ var example2: Example = .{ .x = 10, .y = 20 };
550543 \\
551544 \\ example = example2;
552 \\ return example.y + example.x;
545 \\ return example.y + example.x - 30;
553546 \\}
554 , "30\n");
547 , "");
555548
556549 case.addCompareOutput(
557550 \\const Example = struct { x: u8, y: u8 };
......@@ -560,9 +553,9 @@ pub fn addCases(ctx: *TestContext) !void {
560553 \\ var example: Example = .{ .x = 5, .y = 10 };
561554 \\
562555 \\ example = .{ .x = 10, .y = 20 };
563 \\ return example.y + example.x;
556 \\ return example.y + example.x - 30;
564557 \\}
565 , "30\n");
558 , "");
566559 }
567560
568561 {
......@@ -578,9 +571,9 @@ pub fn addCases(ctx: *TestContext) !void {
578571 \\ else => 5,
579572 \\ };
580573 \\
581 \\ return a;
574 \\ return a - 2;
582575 \\}
583 , "2\n");
576 , "");
584577
585578 case.addCompareOutput(
586579 \\pub fn main() u8 {
......@@ -592,9 +585,9 @@ pub fn addCases(ctx: *TestContext) !void {
592585 \\ else => 5,
593586 \\ };
594587 \\
595 \\ return a;
588 \\ return a - 3;
596589 \\}
597 , "3\n");
590 , "");
598591
599592 case.addCompareOutput(
600593 \\pub fn main() u8 {
......@@ -606,9 +599,9 @@ pub fn addCases(ctx: *TestContext) !void {
606599 \\ else => 5,
607600 \\ };
608601 \\
609 \\ return a;
602 \\ return a - 5;
610603 \\}
611 , "5\n");
604 , "");
612605
613606 case.addCompareOutput(
614607 \\const MyEnum = enum { One, Two, Three };
......@@ -621,9 +614,9 @@ pub fn addCases(ctx: *TestContext) !void {
621614 \\ .Three => 3,
622615 \\ };
623616 \\
624 \\ return a;
617 \\ return a - 2;
625618 \\}
626 , "2\n");
619 , "");
627620 }
628621
629622 {
......@@ -641,35 +634,35 @@ pub fn addCases(ctx: *TestContext) !void {
641634 \\fn assert(b: bool) void {
642635 \\ if (!b) unreachable;
643636 \\}
644 , "0\n");
637 , "");
645638
646639 case.addCompareOutput(
647640 \\pub fn main() u8 {
648641 \\ var e: anyerror!u8 = 5;
649642 \\ const i = e catch 10;
650 \\ return i;
643 \\ return i - 5;
651644 \\}
652 , "5\n");
645 , "");
653646
654647 case.addCompareOutput(
655648 \\pub fn main() u8 {
656649 \\ var e: anyerror!u8 = error.Foo;
657650 \\ const i = e catch 10;
658 \\ return i;
651 \\ return i - 10;
659652 \\}
660 , "10\n");
653 , "");
661654
662655 case.addCompareOutput(
663656 \\pub fn main() u8 {
664657 \\ var e = foo();
665658 \\ const i = e catch 69;
666 \\ return i;
659 \\ return i - 5;
667660 \\}
668661 \\
669662 \\fn foo() anyerror!u8 {
670663 \\ return 5;
671664 \\}
672 , "5\n");
665 , "");
673666 }
674667
675668 {
......@@ -679,24 +672,24 @@ pub fn addCases(ctx: *TestContext) !void {
679672 \\pub fn main() u8 {
680673 \\ var e = foo();
681674 \\ const i = e catch 69;
682 \\ return i;
675 \\ return i - 69;
683676 \\}
684677 \\
685678 \\fn foo() anyerror!u8 {
686679 \\ return error.Bruh;
687680 \\}
688 , "69\n");
681 , "");
689682 case.addCompareOutput(
690683 \\pub fn main() u8 {
691684 \\ var e = foo();
692685 \\ const i = e catch 42;
693 \\ return i;
686 \\ return i - 42;
694687 \\}
695688 \\
696689 \\fn foo() anyerror!u8 {
697690 \\ return error.Dab;
698691 \\}
699 , "42\n");
692 , "");
700693 }
701694
702695 {
......@@ -709,7 +702,7 @@ pub fn addCases(ctx: *TestContext) !void {
709702 \\ _ = y;
710703 \\ return;
711704 \\}
712 , "0\n");
705 , "");
713706 }
714707
715708 {
......@@ -722,9 +715,9 @@ pub fn addCases(ctx: *TestContext) !void {
722715 \\ if (x) |val| {
723716 \\ y = val;
724717 \\ }
725 \\ return y;
718 \\ return y - 5;
726719 \\}
727 , "5\n");
720 , "");
728721
729722 case.addCompareOutput(
730723 \\pub fn main() u8 {
......@@ -735,22 +728,22 @@ pub fn addCases(ctx: *TestContext) !void {
735728 \\ }
736729 \\ return y;
737730 \\}
738 , "0\n");
731 , "");
739732
740733 case.addCompareOutput(
741734 \\pub fn main() u8 {
742735 \\ var x: ?u8 = 5;
743 \\ return x.?;
736 \\ return x.? - 5;
744737 \\}
745 , "5\n");
738 , "");
746739
747740 case.addCompareOutput(
748741 \\pub fn main() u8 {
749742 \\ var x: u8 = 5;
750743 \\ var y: ?u8 = x;
751 \\ return y.?;
744 \\ return y.? - 5;
752745 \\}
753 , "5\n");
746 , "");
754747
755748 case.addCompareOutput(
756749 \\pub fn main() u8 {
......@@ -763,7 +756,7 @@ pub fn addCases(ctx: *TestContext) !void {
763756 \\ }
764757 \\ return 0;
765758 \\}
766 , "0\n");
759 , "");
767760 }
768761
769762 {
......@@ -774,13 +767,13 @@ pub fn addCases(ctx: *TestContext) !void {
774767 \\ var x: u8 = 0;
775768 \\
776769 \\ foo(&x);
777 \\ return x;
770 \\ return x - 2;
778771 \\}
779772 \\
780773 \\fn foo(x: *u8)void {
781774 \\ x.* = 2;
782775 \\}
783 , "2\n");
776 , "");
784777
785778 case.addCompareOutput(
786779 \\pub fn main() u8 {
......@@ -788,7 +781,7 @@ pub fn addCases(ctx: *TestContext) !void {
788781 \\
789782 \\ foo(&x);
790783 \\ bar(&x);
791 \\ return x;
784 \\ return x - 4;
792785 \\}
793786 \\
794787 \\fn foo(x: *u8)void {
......@@ -798,6 +791,6 @@ pub fn addCases(ctx: *TestContext) !void {
798791 \\fn bar(x: *u8) void {
799792 \\ x.* += 2;
800793 \\}
801 , "4\n");
794 , "");
802795 }
803796}