-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnapshot.zig
More file actions
731 lines (603 loc) · 24 KB
/
Copy pathsnapshot.zig
File metadata and controls
731 lines (603 loc) · 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
const std = @import("std");
const compat = @import("compat.zig");
/// Snapshot format type
pub const SnapshotFormat = enum {
/// Pretty-printed text format
pretty_text,
/// Compact text format
compact_text,
/// JSON format
json,
/// Raw format (no formatting)
raw,
};
/// Snapshot testing options
pub const SnapshotOptions = struct {
/// Directory to store snapshots
snapshot_dir: []const u8 = ".snapshots",
/// Update snapshots instead of comparing
update: bool = false,
/// Interactive update mode (ask before updating)
interactive: bool = false,
/// Snapshot format
format: SnapshotFormat = .pretty_text,
/// Pretty print (only for formats that support it)
pretty_print: bool = true,
/// Snapshot file extension
file_extension: []const u8 = ".snap",
};
/// Snapshot diff entry
pub const DiffEntry = struct {
line_number: usize,
expected: []const u8,
received: []const u8,
allocator: std.mem.Allocator,
pub fn deinit(self: *DiffEntry) void {
self.allocator.free(self.expected);
self.allocator.free(self.received);
}
};
/// Snapshot diff result
pub const SnapshotDiff = struct {
has_diff: bool,
diffs: std.ArrayList(DiffEntry),
allocator: std.mem.Allocator,
pub fn init(allocator: std.mem.Allocator) SnapshotDiff {
return .{
.has_diff = false,
.diffs = .empty,
.allocator = allocator,
};
}
pub fn deinit(self: *SnapshotDiff) void {
for (self.diffs.items) |*entry| {
entry.deinit();
}
self.diffs.deinit(self.allocator);
}
pub fn addDiff(self: *SnapshotDiff, line_number: usize, expected: []const u8, received: []const u8) !void {
self.has_diff = true;
const expected_copy = try self.allocator.dupe(u8, expected);
const received_copy = try self.allocator.dupe(u8, received);
try self.diffs.append(self.allocator, .{
.line_number = line_number,
.expected = expected_copy,
.received = received_copy,
.allocator = self.allocator,
});
}
pub fn print(self: *SnapshotDiff) void {
if (!self.has_diff) return;
std.debug.print("\n=== Snapshot Diff ===\n", .{});
for (self.diffs.items) |entry| {
std.debug.print("Line {d}:\n", .{entry.line_number});
std.debug.print(" - Expected: {s}\n", .{entry.expected});
std.debug.print(" + Received: {s}\n", .{entry.received});
}
std.debug.print("=====================\n\n", .{});
}
};
/// Inline snapshot marker
pub const InlineSnapshot = struct {
file_path: []const u8,
line_number: usize,
value: []const u8,
allocator: std.mem.Allocator,
pub fn init(allocator: std.mem.Allocator, file_path: []const u8, line_number: usize, value: []const u8) !InlineSnapshot {
return .{
.file_path = try allocator.dupe(u8, file_path),
.line_number = line_number,
.value = try allocator.dupe(u8, value),
.allocator = allocator,
};
}
pub fn deinit(self: *InlineSnapshot) void {
self.allocator.free(self.file_path);
self.allocator.free(self.value);
}
};
/// Snapshot matcher
pub const Snapshot = struct {
allocator: std.mem.Allocator,
options: SnapshotOptions,
test_name: []const u8,
snapshot_count: usize = 0,
const Self = @This();
pub fn init(allocator: std.mem.Allocator, test_name: []const u8, options: SnapshotOptions) Self {
return .{
.allocator = allocator,
.options = options,
.test_name = test_name,
};
}
/// Match a string value against a snapshot
pub fn matchString(self: *Self, value: []const u8) !void {
const snapshot_path = try self.getSnapshotPath(null);
defer self.allocator.free(snapshot_path);
if (self.options.update) {
if (self.options.interactive) {
try self.interactiveUpdate(snapshot_path, value);
} else {
try self.writeSnapshot(snapshot_path, value);
}
} else {
try self.compareSnapshot(snapshot_path, value);
}
}
/// Match a string with a specific name
pub fn matchStringNamed(self: *Self, name: []const u8, value: []const u8) !void {
const snapshot_path = try self.getSnapshotPath(name);
defer self.allocator.free(snapshot_path);
if (self.options.update) {
if (self.options.interactive) {
try self.interactiveUpdate(snapshot_path, value);
} else {
try self.writeSnapshot(snapshot_path, value);
}
} else {
try self.compareSnapshot(snapshot_path, value);
}
}
/// Match any value against a snapshot (converts to string)
pub fn match(self: *Self, value: anytype) !void {
const formatted = try self.formatValue(value);
defer self.allocator.free(formatted);
try self.matchString(formatted);
}
/// Match any value with a specific name
pub fn matchNamed(self: *Self, name: []const u8, value: anytype) !void {
const formatted = try self.formatValue(value);
defer self.allocator.free(formatted);
try self.matchStringNamed(name, formatted);
}
/// Match inline snapshot
pub fn matchInline(self: *Self, file_path: []const u8, line_number: usize, value: anytype) !void {
const formatted = try self.formatValue(value);
defer self.allocator.free(formatted);
var inline_snap = try InlineSnapshot.init(self.allocator, file_path, line_number, formatted);
defer inline_snap.deinit();
// For inline snapshots, we need to update the source file
if (self.options.update) {
try self.updateInlineSnapshot(&inline_snap);
} else {
try self.verifyInlineSnapshot(&inline_snap);
}
}
/// Format a value for snapshotting
fn formatValue(self: *Self, value: anytype) ![]const u8 {
var buffer = std.ArrayList(u8).empty;
var writer = compat.ArrayListWriter.init(&buffer, self.allocator);
switch (self.options.format) {
.pretty_text => try self.formatValuePretty(&writer, value),
.compact_text => try self.formatValueCompact(&writer, value),
.json => try self.formatValueJson(&writer, value),
.raw => try writer.print("{any}", .{value}),
}
return buffer.toOwnedSlice(self.allocator);
}
/// Format value as pretty text
fn formatValuePretty(self: *Self, writer: anytype, value: anytype) !void {
const T = @TypeOf(value);
const type_info = @typeInfo(T);
switch (type_info) {
.int, .comptime_int => try writer.print("{d}", .{value}),
.float, .comptime_float => try writer.print("{d:.6}", .{value}),
.bool => try writer.print("{}", .{value}),
.pointer => |ptr_info| {
if (ptr_info.size == .slice and ptr_info.child == u8) {
try writer.print("\"{s}\"", .{value});
} else {
try writer.print("{any}", .{value});
}
},
.@"struct" => try self.formatStructPretty(writer, value),
.array => try writer.print("{any}", .{value}),
else => try writer.print("{any}", .{value}),
}
}
/// Format value as compact text
fn formatValueCompact(self: *Self, writer: anytype, value: anytype) !void {
_ = self;
try writer.print("{any}", .{value});
}
/// Format value as JSON
fn formatValueJson(self: *Self, writer: anytype, value: anytype) !void {
const T = @TypeOf(value);
const type_info = @typeInfo(T);
switch (type_info) {
.int, .comptime_int => try writer.print("{d}", .{value}),
.float, .comptime_float => try writer.print("{d:.6}", .{value}),
.bool => try writer.print("{}", .{value}),
.pointer => |ptr_info| {
if (ptr_info.size == .slice and ptr_info.child == u8) {
try writer.print("\"{s}\"", .{value});
} else {
try writer.print("null", .{});
}
},
.@"struct" => {
try writer.writeAll("{\n");
inline for (type_info.@"struct".fields, 0..) |field, i| {
if (self.options.pretty_print) {
try writer.writeAll(" ");
}
try writer.print("\"{s}\": ", .{field.name});
const field_value = @field(value, field.name);
try self.formatJsonValue(writer, field_value);
if (i < type_info.@"struct".fields.len - 1) {
try writer.writeAll(",");
}
if (self.options.pretty_print) {
try writer.writeAll("\n");
}
}
try writer.writeAll("}");
},
else => try writer.print("null", .{}),
}
}
/// Format a single JSON value
fn formatJsonValue(self: *Self, writer: anytype, value: anytype) !void {
_ = self;
const T = @TypeOf(value);
const type_info = @typeInfo(T);
switch (type_info) {
.int, .comptime_int => try writer.print("{d}", .{value}),
.float, .comptime_float => try writer.print("{d:.6}", .{value}),
.bool => try writer.print("{}", .{value}),
.pointer => |ptr_info| {
if (ptr_info.size == .slice and ptr_info.child == u8) {
try writer.print("\"{s}\"", .{value});
} else {
try writer.print("null", .{});
}
},
else => try writer.print("null", .{}),
}
}
/// Format a struct with pretty printing
fn formatStructPretty(self: *Self, writer: anytype, value: anytype) !void {
_ = self;
const T = @TypeOf(value);
const type_info = @typeInfo(T);
if (type_info != .@"struct") {
try writer.print("{any}", .{value});
return;
}
try writer.writeAll("{\n");
inline for (type_info.@"struct".fields, 0..) |field, i| {
try writer.print(" \"{s}\": ", .{field.name});
const field_value = @field(value, field.name);
const FieldType = @TypeOf(field_value);
const field_info = @typeInfo(FieldType);
switch (field_info) {
.int, .comptime_int => try writer.print("{d}", .{field_value}),
.float, .comptime_float => try writer.print("{d:.6}", .{field_value}),
.bool => try writer.print("{}", .{field_value}),
.pointer => |ptr_info| {
if (ptr_info.size == .slice and ptr_info.child == u8) {
try writer.print("\"{s}\"", .{field_value});
} else {
try writer.print("{any}", .{field_value});
}
},
else => try writer.print("{any}", .{field_value}),
}
if (i < type_info.@"struct".fields.len - 1) {
try writer.writeAll(",\n");
} else {
try writer.writeAll("\n");
}
}
try writer.writeAll("}");
}
/// Compare snapshot with deep comparison and diff generation
fn compareSnapshot(self: *Self, path: []const u8, value: []const u8) !void {
const expected = try self.readSnapshot(path);
defer self.allocator.free(expected);
if (!std.mem.eql(u8, value, expected)) {
// Generate diff
var diff = SnapshotDiff.init(self.allocator);
defer diff.deinit();
try self.generateDiff(&diff, expected, value);
std.debug.print("\nSnapshot mismatch for '{s}':\n", .{self.test_name});
diff.print();
std.debug.print("Run with --update-snapshots to update.\n", .{});
return error.SnapshotMismatch;
}
}
/// Generate diff between expected and received
fn generateDiff(self: *Self, diff: *SnapshotDiff, expected: []const u8, received: []const u8) !void {
var expected_lines = std.mem.splitScalar(u8, expected, '\n');
var received_lines = std.mem.splitScalar(u8, received, '\n');
var line_num: usize = 1;
while (true) {
const exp_line = expected_lines.next();
const rec_line = received_lines.next();
if (exp_line == null and rec_line == null) break;
const exp_str = exp_line orelse "";
const rec_str = rec_line orelse "";
if (!std.mem.eql(u8, exp_str, rec_str)) {
try diff.addDiff(line_num, exp_str, rec_str);
}
line_num += 1;
}
// Handle case where files have different line counts
while (expected_lines.next()) |exp_line| {
try diff.addDiff(line_num, exp_line, "");
line_num += 1;
}
while (received_lines.next()) |rec_line| {
try diff.addDiff(line_num, "", rec_line);
line_num += 1;
}
_ = self;
}
/// Interactive update - ask user before updating
fn interactiveUpdate(self: *Self, path: []const u8, value: []const u8) !void {
// Try to read existing snapshot
const existing = self.readSnapshot(path) catch |err| {
if (err == error.SnapshotNotFound) {
// No existing snapshot, create new one
std.debug.print("\nNo existing snapshot for '{s}'\n", .{self.test_name});
std.debug.print("Interactive mode: Creating new snapshot automatically.\n", .{});
try self.writeSnapshot(path, value);
return;
}
return err;
};
defer self.allocator.free(existing);
if (!std.mem.eql(u8, value, existing)) {
std.debug.print("\nSnapshot '{s}' has changed:\n", .{self.test_name});
std.debug.print("Expected:\n{s}\n", .{existing});
std.debug.print("Received:\n{s}\n", .{value});
std.debug.print("Interactive mode: Updating snapshot automatically.\n", .{});
try self.writeSnapshot(path, value);
}
}
/// Update inline snapshot in source file
fn updateInlineSnapshot(self: *Self, inline_snap: *InlineSnapshot) !void {
_ = self;
_ = inline_snap;
// TODO: Implement source file modification for inline snapshots
// This requires parsing the source file and updating the specific line
std.debug.print("Inline snapshot update not yet implemented\n", .{});
}
/// Verify inline snapshot
fn verifyInlineSnapshot(self: *Self, inline_snap: *InlineSnapshot) !void {
_ = self;
_ = inline_snap;
// TODO: Implement inline snapshot verification
std.debug.print("Inline snapshot verification not yet implemented\n", .{});
}
/// Get snapshot file path
fn getSnapshotPath(self: *Self, name: ?[]const u8) ![]const u8 {
// Sanitize test name for filename
const base_name = name orelse self.test_name;
var sanitized = try self.allocator.alloc(u8, base_name.len);
defer self.allocator.free(sanitized);
for (base_name, 0..) |c, i| {
sanitized[i] = switch (c) {
' ' => '_',
'/', '\\', ':', '*', '?', '"', '<', '>', '|' => '-',
else => c,
};
}
if (name != null) {
return std.fmt.allocPrint(
self.allocator,
"{s}/{s}_{s}{s}",
.{ self.options.snapshot_dir, sanitized, sanitized, self.options.file_extension },
);
} else {
return std.fmt.allocPrint(
self.allocator,
"{s}/{s}{s}",
.{ self.options.snapshot_dir, sanitized, self.options.file_extension },
);
}
}
/// Read snapshot from file
fn readSnapshot(self: *Self, path: []const u8) ![]const u8 {
return compat.readFileAlloc(self.allocator, path) catch |err| {
if (err == error.FileNotFound) {
std.debug.print("\nSnapshot file not found: {s}\n", .{path});
std.debug.print("Run with --update-snapshots to create it.\n", .{});
return error.SnapshotNotFound;
}
return err;
};
}
/// Write snapshot to file
fn writeSnapshot(self: *Self, path: []const u8, content: []const u8) !void {
// Ensure snapshot directory exists
compat.makePath(self.allocator, self.options.snapshot_dir) catch {};
try compat.writeFile(self.allocator, path, content);
std.debug.print("Snapshot updated: {s}\n", .{path});
}
};
/// Snapshot cleanup utility
pub const SnapshotCleanup = struct {
allocator: std.mem.Allocator,
snapshot_dir: []const u8,
used_snapshots: std.StringHashMap(bool),
const Self = @This();
pub fn init(allocator: std.mem.Allocator, snapshot_dir: []const u8) Self {
return .{
.allocator = allocator,
.snapshot_dir = snapshot_dir,
.used_snapshots = std.StringHashMap(bool).init(allocator),
};
}
pub fn deinit(self: *Self) void {
self.used_snapshots.deinit();
}
/// Mark a snapshot as used
pub fn markUsed(self: *Self, snapshot_name: []const u8) !void {
try self.used_snapshots.put(snapshot_name, true);
}
/// Find and remove unused snapshots
pub fn cleanupUnused(self: *Self) !usize {
var dir = compat.DirIterator.open(self.snapshot_dir) catch return 0;
defer dir.close();
var removed: usize = 0;
while (try dir.next()) |entry| {
if (entry.kind != .file) continue;
if (!std.mem.endsWith(u8, entry.name, ".snap")) continue;
// Check if this snapshot is marked as used
if (!self.used_snapshots.contains(entry.name)) {
// Delete unused snapshot
const full_path = try std.fs.path.join(self.allocator, &.{ self.snapshot_dir, entry.name });
defer self.allocator.free(full_path);
compat.deleteFile(self.allocator, full_path) catch {};
removed += 1;
}
}
return removed;
}
/// List all snapshot files
pub fn listSnapshots(self: *Self) !std.ArrayList([]const u8) {
var result = std.ArrayList([]const u8).empty;
errdefer {
for (result.items) |item| self.allocator.free(item);
result.deinit(self.allocator);
}
var dir = compat.DirIterator.open(self.snapshot_dir) catch return result;
defer dir.close();
while (try dir.next()) |entry| {
if (entry.kind != .file) continue;
if (!std.mem.endsWith(u8, entry.name, ".snap")) continue;
try result.append(self.allocator, try self.allocator.dupe(u8, entry.name));
}
return result;
}
};
/// Create a snapshot matcher for a test
pub fn snapshot(allocator: std.mem.Allocator, test_name: []const u8, options: SnapshotOptions) Snapshot {
return Snapshot.init(allocator, test_name, options);
}
// Tests
test "Snapshot string matching" {
const allocator = std.testing.allocator;
var snap = Snapshot.init(allocator, "test_snapshot_string", .{ .update = true });
// Update snapshot
try snap.matchString("Hello, World!");
// Now test matching
var snap2 = Snapshot.init(allocator, "test_snapshot_string", .{ .update = false });
try snap2.matchString("Hello, World!");
}
test "Snapshot struct formatting - pretty text" {
const allocator = std.testing.allocator;
const TestStruct = struct {
name: []const u8,
age: u32,
active: bool,
};
const value = TestStruct{
.name = "Alice",
.age = 30,
.active = true,
};
var snap = Snapshot.init(allocator, "test_snapshot_struct", .{
.update = true,
.format = .pretty_text,
});
try snap.match(value);
}
test "Snapshot JSON format" {
const allocator = std.testing.allocator;
const TestStruct = struct {
name: []const u8,
count: u32,
};
const value = TestStruct{
.name = "test",
.count = 42,
};
var snap = Snapshot.init(allocator, "test_snapshot_json", .{
.update = true,
.format = .json,
});
try snap.match(value);
// Cleanup
compat.deleteFile(std.testing.allocator, ".snapshots/test_snapshot_json.snap") catch {};
}
test "Snapshot mismatch detection" {
const allocator = std.testing.allocator;
// Create snapshot
var snap1 = Snapshot.init(allocator, "test_mismatch", .{ .update = true });
try snap1.matchString("original value");
// Try to match different value
var snap2 = Snapshot.init(allocator, "test_mismatch", .{ .update = false });
const result = snap2.matchString("different value");
try std.testing.expectError(error.SnapshotMismatch, result);
// Cleanup
compat.deleteFile(std.testing.allocator, ".snapshots/test_mismatch.snap") catch {};
}
test "Snapshot diff generation" {
const allocator = std.testing.allocator;
var diff = SnapshotDiff.init(allocator);
defer diff.deinit();
try diff.addDiff(1, "line 1", "different line 1");
try diff.addDiff(3, "line 3", "changed line 3");
try std.testing.expect(diff.has_diff);
try std.testing.expectEqual(@as(usize, 2), diff.diffs.items.len);
}
test "Named snapshots" {
const allocator = std.testing.allocator;
var snap = Snapshot.init(allocator, "test_named", .{ .update = true });
try snap.matchStringNamed("first", "First snapshot");
try snap.matchStringNamed("second", "Second snapshot");
// Verify they were created separately
var snap2 = Snapshot.init(allocator, "test_named", .{ .update = false });
try snap2.matchStringNamed("first", "First snapshot");
try snap2.matchStringNamed("second", "Second snapshot");
// Cleanup
compat.deleteFile(std.testing.allocator, ".snapshots/test_named_first.snap") catch {};
compat.deleteFile(std.testing.allocator, ".snapshots/test_named_second.snap") catch {};
}
test "Snapshot cleanup - list snapshots" {
const allocator = std.testing.allocator;
// Create some test snapshots
var snap = Snapshot.init(allocator, "cleanup_test_1", .{ .update = true });
try snap.matchString("test");
var cleanup = SnapshotCleanup.init(allocator, ".snapshots");
defer cleanup.deinit();
var snapshots = try cleanup.listSnapshots();
defer {
for (snapshots.items) |item| {
allocator.free(item);
}
snapshots.deinit(allocator);
}
try std.testing.expect(snapshots.items.len > 0);
// Cleanup
compat.deleteFile(std.testing.allocator, ".snapshots/cleanup_test_1.snap") catch {};
}
test "Snapshot cleanup - remove unused" {
const allocator = std.testing.allocator;
// Create test snapshots
var snap1 = Snapshot.init(allocator, "cleanup_used", .{ .update = true });
try snap1.matchString("used");
var snap2 = Snapshot.init(allocator, "cleanup_unused", .{ .update = true });
try snap2.matchString("unused");
var cleanup = SnapshotCleanup.init(allocator, ".snapshots");
defer cleanup.deinit();
// Mark only first snapshot as used
try cleanup.markUsed("cleanup_used.snap");
// Clean up unused (this should remove cleanup_unused.snap)
const removed = try cleanup.cleanupUnused();
try std.testing.expect(removed >= 1);
// Cleanup remaining
compat.deleteFile(std.testing.allocator, ".snapshots/cleanup_used.snap") catch {};
}
test "Snapshot compact format" {
const allocator = std.testing.allocator;
var snap = Snapshot.init(allocator, "test_compact", .{
.update = true,
.format = .compact_text,
});
try snap.matchString("compact snapshot");
// Cleanup
compat.deleteFile(std.testing.allocator, ".snapshots/test_compact.snap") catch {};
}