zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 30bf8d7147a337444df51926199b70dc152a8283 (tree)
parent bd0dbb0a13d075a1ea7e681a242288e307648559
Author: Travis Staloch <1562827+travisstaloch@users.noreply.github.com>
Date:   Mon, 26 Feb 2024 19:08:27 -0800

testing.expectFmt() - reuse expectEqualStrings()

Diffstat:
Mlib/std/testing.zig | 16+++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/lib/std/testing.zig b/lib/std/testing.zig @@ -210,18 +210,12 @@ test "expectEqual.union(enum)" { /// This function is intended to be used only in tests. When the formatted result of the template /// and its arguments does not equal the expected text, it prints diagnostics to stderr to show how -/// they are not equal, then returns an error. +/// they are not equal, then returns an error. It depends on `expectEqualStrings()` for printing +/// diagnostics. pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anytype) !void { - const result = try std.fmt.allocPrint(allocator, template, args); - defer allocator.free(result); - if (std.mem.eql(u8, result, expected)) return; - - print("\n====== expected this output: =========\n", .{}); - print("{s}", .{expected}); - print("\n======== instead found this: =========\n", .{}); - print("{s}", .{result}); - print("\n======================================\n", .{}); - return error.TestExpectedFmt; + const actual = try std.fmt.allocPrint(allocator, template, args); + defer allocator.free(actual); + return expectEqualStrings(expected, actual); } /// This function is intended to be used only in tests. When the actual value is