pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anytype) !void expected: []const u8template: []const u8args656
657
658
659
660
661
662
663
664pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anytype) !void {
if (@inComptime()) {
var buffer: [std.fmt.count(template, args)]u8 = undefined;
return expectEqualStrings(expected, try std.mem.print(&buffer, template, args));
}
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 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. It depends on
expectEqualStringsfor printing diagnostics.