Make expected runtime runner value optional to skip assertion
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / puppeteer-perf (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled

This commit is contained in:
Karl Seguin
2025-05-14 21:57:45 +08:00
committed by Sjors
parent 905eb1a93f
commit 6f9dd8d7cd

View File

@@ -64,7 +64,7 @@ pub fn Runner(comptime State: type, comptime Global: type, comptime types: anyty
} }
const RunOpts = struct {}; const RunOpts = struct {};
pub const Case = std.meta.Tuple(&.{ []const u8, []const u8 }); pub const Case = std.meta.Tuple(&.{ []const u8, ?[]const u8 });
pub fn testCases(self: *Self, cases: []const Case, _: RunOpts) !void { pub fn testCases(self: *Self, cases: []const Case, _: RunOpts) !void {
for (cases, 0..) |case, i| { for (cases, 0..) |case, i| {
var try_catch: Env.TryCatch = undefined; var try_catch: Env.TryCatch = undefined;
@@ -82,18 +82,22 @@ pub fn Runner(comptime State: type, comptime Global: type, comptime types: anyty
return err; return err;
}; };
const actual = try value.toString(allocator); if (case.@"1") |expected| {
defer allocator.free(actual); const actual = try value.toString(allocator);
if (std.mem.eql(u8, case.@"1", actual) == false) { defer allocator.free(actual);
std.debug.print("Expected:\n{s}\n\nGot:\n{s}\n\nCase: {d}\n{s}\n", .{ case.@"1", actual, i + 1, case.@"0" }); if (std.mem.eql(u8, expected, actual) == false) {
return error.UnexpectedResult; std.debug.print("Expected:\n{s}\n\nGot:\n{s}\n\nCase: {d}\n{s}\n", .{ expected, actual, i + 1, case.@"0" });
return error.UnexpectedResult;
}
} }
} }
} }
}; };
} }
fn isExpectedTypeError(expected: []const u8, msg: []const u8) bool { fn isExpectedTypeError(expected_: ?[]const u8, msg: []const u8) bool {
const expected = expected_ orelse return false;
if (!std.mem.eql(u8, expected, "TypeError")) { if (!std.mem.eql(u8, expected, "TypeError")) {
return false; return false;
} }