snapshot.zig (696B)
1 const std = @import("std"); 2 const build_options = @import("build_options"); 3 4 test "snapshot" { 5 const expected = @embedFile("snapshot_expected.zig"); 6 7 const actual_file = try std.fs.openFileAbsolute(build_options.snapshot_actual, .{}); 8 defer actual_file.close(); 9 10 const actual = try actual_file.readToEndAlloc(std.testing.allocator, 4 * 1024 * 1024 * 1024); 11 defer std.testing.allocator.free(actual); 12 13 if (!std.mem.eql(u8, expected, actual)) { 14 std.debug.print("scanner output does not match snapshot\n", .{}); 15 std.debug.print("diff -C 3 test/snapshot_expected.zig {s}\n", .{build_options.snapshot_actual}); 16 return error.TestUnexpectedResult; 17 } 18 }