| ... | @@ -210,18 +210,12 @@ test "expectEqual.union(enum)" { | ... | @@ -210,18 +210,12 @@ test "expectEqual.union(enum)" { |
| 210 | | 210 | |
| 211 | /// This function is intended to be used only in tests. When the formatted result of the template | 211 | /// This function is intended to be used only in tests. When the formatted result of the template |
| 212 | /// and its arguments does not equal the expected text, it prints diagnostics to stderr to show how | 212 | /// and its arguments does not equal the expected text, it prints diagnostics to stderr to show how |
| 213 | /// they are not equal, then returns an error. | 213 | /// they are not equal, then returns an error. It depends on `expectEqualStrings()` for printing |
| | 214 | /// diagnostics. |
| 214 | pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anytype) !void { | 215 | pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anytype) !void { |
| 215 | const result = try std.fmt.allocPrint(allocator, template, args); | 216 | const actual = try std.fmt.allocPrint(allocator, template, args); |
| 216 | defer allocator.free(result); | 217 | defer allocator.free(actual); |
| 217 | if (std.mem.eql(u8, result, expected)) return; | 218 | return expectEqualStrings(expected, actual); |
| 218 | | | |
| 219 | print("\n====== expected this output: =========\n", .{}); | | |
| 220 | print("{s}", .{expected}); | | |
| 221 | print("\n======== instead found this: =========\n", .{}); | | |
| 222 | print("{s}", .{result}); | | |
| 223 | print("\n======================================\n", .{}); | | |
| 224 | return error.TestExpectedFmt; | | |
| 225 | } | 219 | } |
| 226 | | 220 | |
| 227 | /// This function is intended to be used only in tests. When the actual value is | 221 | /// This function is intended to be used only in tests. When the actual value is |