mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
testing.expectFmt() - reuse expectEqualStrings()
This commit is contained in:
parent
bd0dbb0a13
commit
30bf8d7147
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user