Commit a75fd4ff15

Igor Anić <igor.anic@gmail.com>
2023-12-11 23:55:07
tar: move test cases to std/tar/testdata
Create std/tar/test.zig for test which uses cases from testdata.
1 parent f8e42d6
test/cases/tar/gnu-incremental.tar → lib/std/tar/testdata/gnu-incremental.tar
File renamed without changes
test/cases/tar/gnu-long-nul.tar → lib/std/tar/testdata/gnu-long-nul.tar
File renamed without changes
test/cases/tar/gnu-multi-hdrs.tar → lib/std/tar/testdata/gnu-multi-hdrs.tar
File renamed without changes
test/cases/tar/gnu-not-utf8.tar → lib/std/tar/testdata/gnu-not-utf8.tar
File renamed without changes
test/cases/tar/gnu-utf8.tar → lib/std/tar/testdata/gnu-utf8.tar
File renamed without changes
test/cases/tar/gnu.tar → lib/std/tar/testdata/gnu.tar
File renamed without changes
test/cases/tar/invalid-go17.tar → lib/std/tar/testdata/invalid-go17.tar
File renamed without changes
test/cases/tar/issue10968.tar → lib/std/tar/testdata/issue10968.tar
File renamed without changes
test/cases/tar/issue11169.tar → lib/std/tar/testdata/issue11169.tar
File renamed without changes
test/cases/tar/issue12435.tar → lib/std/tar/testdata/issue12435.tar
File renamed without changes
test/cases/tar/neg-size.tar → lib/std/tar/testdata/neg-size.tar
File renamed without changes
test/cases/tar/nil-uid.tar → lib/std/tar/testdata/nil-uid.tar
File renamed without changes
test/cases/tar/pax-bad-hdr-file.tar → lib/std/tar/testdata/pax-bad-hdr-file.tar
File renamed without changes
test/cases/tar/pax-global-records.tar → lib/std/tar/testdata/pax-global-records.tar
File renamed without changes
test/cases/tar/pax-multi-hdrs.tar → lib/std/tar/testdata/pax-multi-hdrs.tar
File renamed without changes
test/cases/tar/pax-nul-path.tar → lib/std/tar/testdata/pax-nul-path.tar
File renamed without changes
test/cases/tar/pax-nul-xattrs.tar → lib/std/tar/testdata/pax-nul-xattrs.tar
File renamed without changes
test/cases/tar/pax-pos-size-file.tar → lib/std/tar/testdata/pax-pos-size-file.tar
File renamed without changes
test/cases/tar/pax-records.tar → lib/std/tar/testdata/pax-records.tar
File renamed without changes
test/cases/tar/pax.tar → lib/std/tar/testdata/pax.tar
File renamed without changes
test/cases/tar/sparse-formats.tar → lib/std/tar/testdata/sparse-formats.tar
File renamed without changes
test/cases/tar/star.tar → lib/std/tar/testdata/star.tar
File renamed without changes
test/cases/tar/trailing-slash.tar → lib/std/tar/testdata/trailing-slash.tar
File renamed without changes
test/cases/tar/ustar-file-devs.tar → lib/std/tar/testdata/ustar-file-devs.tar
File renamed without changes
test/cases/tar/v7.tar → lib/std/tar/testdata/v7.tar
File renamed without changes
test/cases/tar/writer-big-long.tar → lib/std/tar/testdata/writer-big-long.tar
File renamed without changes
test/cases/tar/writer-big.tar → lib/std/tar/testdata/writer-big.tar
File renamed without changes
test/cases/tar/xattrs.tar → lib/std/tar/testdata/xattrs.tar
File renamed without changes
lib/std/tar/test.zig
@@ -0,0 +1,373 @@
+const std = @import("../std.zig");
+const tar = std.tar;
+const assert = std.debug.assert;
+
+test "tar run Go test cases" {
+    const Case = struct {
+        const File = struct {
+            name: []const u8,
+            size: usize = 0,
+            mode: u32 = 0,
+            link_name: []const u8 = &[0]u8{},
+            kind: tar.Header.Kind = .normal,
+            truncated: bool = false, // when there is no file body, just header, usefull for huge files
+        };
+
+        path: []const u8, // path to the tar archive file on dis
+        files: []const File = &[_]@This().File{}, // expected files to found in archive
+        chksums: []const []const u8 = &[_][]const u8{}, // chksums of files content
+        err: ?anyerror = null, // parsing should fail with this error
+    };
+
+    const src_path = comptime std.fs.path.dirname(@src().file) orelse ".";
+    const test_dir = try std.fs.cwd().openDir(src_path ++ "/testdata", .{});
+
+    const cases = [_]Case{
+        .{
+            .path = "gnu.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "small.txt",
+                    .size = 5,
+                    .mode = 0o640,
+                },
+                .{
+                    .name = "small2.txt",
+                    .size = 11,
+                    .mode = 0o640,
+                },
+            },
+            .chksums = &[_][]const u8{
+                "e38b27eaccb4391bdec553a7f3ae6b2f",
+                "c65bd2e50a56a2138bf1716f2fd56fe9",
+            },
+        },
+        .{
+            .path = "sparse-formats.tar",
+            .err = error.TarUnsupportedHeader,
+        },
+        .{
+            .path = "star.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "small.txt",
+                    .size = 5,
+                    .mode = 0o640,
+                },
+                .{
+                    .name = "small2.txt",
+                    .size = 11,
+                    .mode = 0o640,
+                },
+            },
+            .chksums = &[_][]const u8{
+                "e38b27eaccb4391bdec553a7f3ae6b2f",
+                "c65bd2e50a56a2138bf1716f2fd56fe9",
+            },
+        },
+        .{
+            .path = "v7.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "small.txt",
+                    .size = 5,
+                    .mode = 0o444,
+                },
+                .{
+                    .name = "small2.txt",
+                    .size = 11,
+                    .mode = 0o444,
+                },
+            },
+            .chksums = &[_][]const u8{
+                "e38b27eaccb4391bdec553a7f3ae6b2f",
+                "c65bd2e50a56a2138bf1716f2fd56fe9",
+            },
+        },
+        .{
+            .path = "pax.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "a/123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100",
+                    .size = 7,
+                    .mode = 0o664,
+                },
+                .{
+                    .name = "a/b",
+                    .size = 0,
+                    .kind = .symbolic_link,
+                    .mode = 0o777,
+                    .link_name = "123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100",
+                },
+            },
+            .chksums = &[_][]const u8{
+                "3c382e8f5b6631aa2db52643912ffd4a",
+            },
+        },
+        .{
+            // pax attribute don't end with \n
+            .path = "pax-bad-hdr-file.tar",
+            .err = error.PaxInvalidAttributeEnd,
+        },
+        .{
+            // size is in pax attribute
+            .path = "pax-pos-size-file.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "foo",
+                    .size = 999,
+                    .kind = .normal,
+                    .mode = 0o640,
+                },
+            },
+            .chksums = &[_][]const u8{
+                "0afb597b283fe61b5d4879669a350556",
+            },
+        },
+        .{
+            // has pax records which we are not interested in
+            .path = "pax-records.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "file",
+                },
+            },
+        },
+        .{
+            // has global records which we are ignoring
+            .path = "pax-global-records.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "file1",
+                },
+                .{
+                    .name = "file2",
+                },
+                .{
+                    .name = "file3",
+                },
+                .{
+                    .name = "file4",
+                },
+            },
+        },
+        .{
+            .path = "nil-uid.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "P1050238.JPG.log",
+                    .size = 14,
+                    .kind = .normal,
+                    .mode = 0o664,
+                },
+            },
+            .chksums = &[_][]const u8{
+                "08d504674115e77a67244beac19668f5",
+            },
+        },
+        .{
+            // has xattrs and pax records which we are ignoring
+            .path = "xattrs.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "small.txt",
+                    .size = 5,
+                    .kind = .normal,
+                    .mode = 0o644,
+                },
+                .{
+                    .name = "small2.txt",
+                    .size = 11,
+                    .kind = .normal,
+                    .mode = 0o644,
+                },
+            },
+            .chksums = &[_][]const u8{
+                "e38b27eaccb4391bdec553a7f3ae6b2f",
+                "c65bd2e50a56a2138bf1716f2fd56fe9",
+            },
+        },
+        .{
+            .path = "gnu-multi-hdrs.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "GNU2/GNU2/long-path-name",
+                    .link_name = "GNU4/GNU4/long-linkpath-name",
+                    .kind = .symbolic_link,
+                },
+            },
+        },
+        .{
+            // has gnu type D (directory) and S (sparse) blocks
+            .path = "gnu-incremental.tar",
+            .err = error.TarUnsupportedHeader,
+        },
+        .{
+            // should use values only from last pax header
+            .path = "pax-multi-hdrs.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "bar",
+                    .link_name = "PAX4/PAX4/long-linkpath-name",
+                    .kind = .symbolic_link,
+                },
+            },
+        },
+        .{
+            .path = "gnu-long-nul.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "0123456789",
+                    .mode = 0o644,
+                },
+            },
+        },
+        .{
+            .path = "gnu-utf8.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹",
+                    .mode = 0o644,
+                },
+            },
+        },
+        .{
+            .path = "gnu-not-utf8.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "hi\x80\x81\x82\x83bye",
+                    .mode = 0o644,
+                },
+            },
+        },
+        .{
+            // null in pax key
+            .path = "pax-nul-xattrs.tar",
+            .err = error.PaxNullInKeyword,
+        },
+        .{
+            .path = "pax-nul-path.tar",
+            .err = error.PaxNullInValue,
+        },
+        .{
+            .path = "neg-size.tar",
+            .err = error.TarHeader,
+        },
+        .{
+            .path = "issue10968.tar",
+            .err = error.TarHeader,
+        },
+        .{
+            .path = "issue11169.tar",
+            .err = error.TarHeader,
+        },
+        .{
+            .path = "issue12435.tar",
+            .err = error.TarHeaderChksum,
+        },
+        .{
+            // has magic with space at end instead of null
+            .path = "invalid-go17.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/foo",
+                },
+            },
+        },
+        .{
+            .path = "ustar-file-devs.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "file",
+                    .mode = 0o644,
+                },
+            },
+        },
+        .{
+            .path = "trailing-slash.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "123456789/" ** 30,
+                    .kind = .directory,
+                },
+            },
+        },
+        .{
+            // Has size in gnu extended format. To represent size bigger than 8 GB.
+            .path = "writer-big.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "tmp/16gig.txt",
+                    .size = 16 * 1024 * 1024 * 1024,
+                    .truncated = true,
+                    .mode = 0o640,
+                },
+            },
+        },
+        .{
+            // Size in gnu extended format, and name in pax attribute.
+            .path = "writer-big-long.tar",
+            .files = &[_]Case.File{
+                .{
+                    .name = "longname/" ** 15 ++ "16gig.txt",
+                    .size = 16 * 1024 * 1024 * 1024,
+                    .mode = 0o644,
+                    .truncated = true,
+                },
+            },
+        },
+    };
+
+    for (cases) |case| {
+        var fs_file = try test_dir.openFile(case.path, .{});
+
+        defer fs_file.close();
+
+        var iter = tar.tarReader(fs_file.reader(), null);
+        var i: usize = 0;
+        while (iter.next() catch |err| {
+            if (case.err) |e| {
+                try std.testing.expectEqual(e, err);
+                continue;
+            } else {
+                return err;
+            }
+        }) |actual| : (i += 1) {
+            const expected = case.files[i];
+            try std.testing.expectEqualStrings(expected.name, actual.name);
+            try std.testing.expectEqual(expected.size, actual.size);
+            try std.testing.expectEqual(expected.kind, actual.kind);
+            try std.testing.expectEqual(expected.mode, actual.mode);
+            try std.testing.expectEqualStrings(expected.link_name, actual.link_name);
+
+            if (case.chksums.len > i) {
+                var md5writer = Md5Writer{};
+                try actual.write(&md5writer);
+                const chksum = md5writer.chksum();
+                try std.testing.expectEqualStrings(case.chksums[i], &chksum);
+            } else {
+                if (!expected.truncated) try actual.skip(); // skip file content
+            }
+        }
+        try std.testing.expectEqual(case.files.len, i);
+    }
+}
+
+// used in test to calculate file chksum
+const Md5Writer = struct {
+    h: std.crypto.hash.Md5 = std.crypto.hash.Md5.init(.{}),
+
+    pub fn writeAll(self: *Md5Writer, buf: []const u8) !void {
+        self.h.update(buf);
+    }
+
+    pub fn writeByte(self: *Md5Writer, byte: u8) !void {
+        self.h.update(&[_]u8{byte});
+    }
+
+    pub fn chksum(self: *Md5Writer) [32]u8 {
+        var s = [_]u8{0} ** 16;
+        self.h.final(&s);
+        return std.fmt.bytesToHex(s, .lower);
+    }
+};
lib/std/tar.zig
@@ -601,376 +601,6 @@ test "tar stripComponents" {
     try expectEqualStrings("c", try stripComponents("a/b/c", 2));
 }
 
-test "tar run Go test cases" {
-    const Case = struct {
-        const File = struct {
-            name: []const u8,
-            size: usize = 0,
-            mode: u32 = 0,
-            link_name: []const u8 = &[0]u8{},
-            kind: Header.Kind = .normal,
-            truncated: bool = false, // when there is no file body, just header, usefull for huge files
-        };
-
-        path: []const u8, // path to the tar archive file on dis
-        files: []const File = &[_]@This().File{}, // expected files to found in archive
-        chksums: []const []const u8 = &[_][]const u8{}, // chksums of files content
-        err: ?anyerror = null, // parsing should fail with this error
-    };
-
-    const src_path = comptime std.fs.path.dirname(@src().file) orelse ".";
-    const test_dir = try std.fs.cwd().openDir(src_path ++ "/../../test/cases/tar", .{});
-
-    const cases = [_]Case{
-        .{
-            .path = "gnu.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "small.txt",
-                    .size = 5,
-                    .mode = 0o640,
-                },
-                .{
-                    .name = "small2.txt",
-                    .size = 11,
-                    .mode = 0o640,
-                },
-            },
-            .chksums = &[_][]const u8{
-                "e38b27eaccb4391bdec553a7f3ae6b2f",
-                "c65bd2e50a56a2138bf1716f2fd56fe9",
-            },
-        },
-        .{
-            .path = "sparse-formats.tar",
-            .err = error.TarUnsupportedHeader,
-        },
-        .{
-            .path = "star.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "small.txt",
-                    .size = 5,
-                    .mode = 0o640,
-                },
-                .{
-                    .name = "small2.txt",
-                    .size = 11,
-                    .mode = 0o640,
-                },
-            },
-            .chksums = &[_][]const u8{
-                "e38b27eaccb4391bdec553a7f3ae6b2f",
-                "c65bd2e50a56a2138bf1716f2fd56fe9",
-            },
-        },
-        .{
-            .path = "v7.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "small.txt",
-                    .size = 5,
-                    .mode = 0o444,
-                },
-                .{
-                    .name = "small2.txt",
-                    .size = 11,
-                    .mode = 0o444,
-                },
-            },
-            .chksums = &[_][]const u8{
-                "e38b27eaccb4391bdec553a7f3ae6b2f",
-                "c65bd2e50a56a2138bf1716f2fd56fe9",
-            },
-        },
-        .{
-            .path = "pax.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "a/123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100",
-                    .size = 7,
-                    .mode = 0o664,
-                },
-                .{
-                    .name = "a/b",
-                    .size = 0,
-                    .kind = .symbolic_link,
-                    .mode = 0o777,
-                    .link_name = "123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100",
-                },
-            },
-            .chksums = &[_][]const u8{
-                "3c382e8f5b6631aa2db52643912ffd4a",
-            },
-        },
-        .{
-            // pax attribute don't end with \n
-            .path = "pax-bad-hdr-file.tar",
-            .err = error.PaxInvalidAttributeEnd,
-        },
-        .{
-            // size is in pax attribute
-            .path = "pax-pos-size-file.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "foo",
-                    .size = 999,
-                    .kind = .normal,
-                    .mode = 0o640,
-                },
-            },
-            .chksums = &[_][]const u8{
-                "0afb597b283fe61b5d4879669a350556",
-            },
-        },
-        .{
-            // has pax records which we are not interested in
-            .path = "pax-records.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "file",
-                },
-            },
-        },
-        .{
-            // has global records which we are ignoring
-            .path = "pax-global-records.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "file1",
-                },
-                .{
-                    .name = "file2",
-                },
-                .{
-                    .name = "file3",
-                },
-                .{
-                    .name = "file4",
-                },
-            },
-        },
-        .{
-            .path = "nil-uid.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "P1050238.JPG.log",
-                    .size = 14,
-                    .kind = .normal,
-                    .mode = 0o664,
-                },
-            },
-            .chksums = &[_][]const u8{
-                "08d504674115e77a67244beac19668f5",
-            },
-        },
-        .{
-            // has xattrs and pax records which we are ignoring
-            .path = "xattrs.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "small.txt",
-                    .size = 5,
-                    .kind = .normal,
-                    .mode = 0o644,
-                },
-                .{
-                    .name = "small2.txt",
-                    .size = 11,
-                    .kind = .normal,
-                    .mode = 0o644,
-                },
-            },
-            .chksums = &[_][]const u8{
-                "e38b27eaccb4391bdec553a7f3ae6b2f",
-                "c65bd2e50a56a2138bf1716f2fd56fe9",
-            },
-        },
-        .{
-            .path = "gnu-multi-hdrs.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "GNU2/GNU2/long-path-name",
-                    .link_name = "GNU4/GNU4/long-linkpath-name",
-                    .kind = .symbolic_link,
-                },
-            },
-        },
-        .{
-            // has gnu type D (directory) and S (sparse) blocks
-            .path = "gnu-incremental.tar",
-            .err = error.TarUnsupportedHeader,
-        },
-        .{
-            // should use values only from last pax header
-            .path = "pax-multi-hdrs.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "bar",
-                    .link_name = "PAX4/PAX4/long-linkpath-name",
-                    .kind = .symbolic_link,
-                },
-            },
-        },
-        .{
-            .path = "gnu-long-nul.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "0123456789",
-                    .mode = 0o644,
-                },
-            },
-        },
-        .{
-            .path = "gnu-utf8.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹",
-                    .mode = 0o644,
-                },
-            },
-        },
-        .{
-            .path = "gnu-not-utf8.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "hi\x80\x81\x82\x83bye",
-                    .mode = 0o644,
-                },
-            },
-        },
-        .{
-            // null in pax key
-            .path = "pax-nul-xattrs.tar",
-            .err = error.PaxNullInKeyword,
-        },
-        .{
-            .path = "pax-nul-path.tar",
-            .err = error.PaxNullInValue,
-        },
-        .{
-            .path = "neg-size.tar",
-            .err = error.TarHeader,
-        },
-        .{
-            .path = "issue10968.tar",
-            .err = error.TarHeader,
-        },
-        .{
-            .path = "issue11169.tar",
-            .err = error.TarHeader,
-        },
-        .{
-            .path = "issue12435.tar",
-            .err = error.TarHeaderChksum,
-        },
-        .{
-            // has magic with space at end instead of null
-            .path = "invalid-go17.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/foo",
-                },
-            },
-        },
-        .{
-            .path = "ustar-file-devs.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "file",
-                    .mode = 0o644,
-                },
-            },
-        },
-        .{
-            .path = "trailing-slash.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "123456789/" ** 30,
-                    .kind = .directory,
-                },
-            },
-        },
-        .{
-            // Has size in gnu extended format. To represent size bigger than 8 GB.
-            .path = "writer-big.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "tmp/16gig.txt",
-                    .size = 16 * 1024 * 1024 * 1024,
-                    .truncated = true,
-                    .mode = 0o640,
-                },
-            },
-        },
-        .{
-            // Size in gnu extended format, and name in pax attribute.
-            .path = "writer-big-long.tar",
-            .files = &[_]Case.File{
-                .{
-                    .name = "longname/" ** 15 ++ "16gig.txt",
-                    .size = 16 * 1024 * 1024 * 1024,
-                    .mode = 0o644,
-                    .truncated = true,
-                },
-            },
-        },
-    };
-
-    for (cases) |case| {
-        var fs_file = try test_dir.openFile(case.path, .{});
-
-        defer fs_file.close();
-
-        var iter = tarReader(fs_file.reader(), null);
-        var i: usize = 0;
-        while (iter.next() catch |err| {
-            if (case.err) |e| {
-                try std.testing.expectEqual(e, err);
-                continue;
-            } else {
-                return err;
-            }
-        }) |actual| : (i += 1) {
-            const expected = case.files[i];
-            try std.testing.expectEqualStrings(expected.name, actual.name);
-            try std.testing.expectEqual(expected.size, actual.size);
-            try std.testing.expectEqual(expected.kind, actual.kind);
-            try std.testing.expectEqual(expected.mode, actual.mode);
-            try std.testing.expectEqualStrings(expected.link_name, actual.link_name);
-
-            if (case.chksums.len > i) {
-                var md5writer = Md5Writer{};
-                try actual.write(&md5writer);
-                const chksum = md5writer.chksum();
-                try std.testing.expectEqualStrings(case.chksums[i], &chksum);
-            } else {
-                if (!expected.truncated) try actual.skip(); // skip file content
-            }
-        }
-        try std.testing.expectEqual(case.files.len, i);
-    }
-}
-
-// used in test to calculate file chksum
-const Md5Writer = struct {
-    h: std.crypto.hash.Md5 = std.crypto.hash.Md5.init(.{}),
-
-    pub fn writeAll(self: *Md5Writer, buf: []const u8) !void {
-        self.h.update(buf);
-    }
-
-    pub fn writeByte(self: *Md5Writer, byte: u8) !void {
-        self.h.update(&[_]u8{byte});
-    }
-
-    pub fn chksum(self: *Md5Writer) [32]u8 {
-        var s = [_]u8{0} ** 16;
-        self.h.final(&s);
-        return std.fmt.bytesToHex(s, .lower);
-    }
-};
-
 test "tar PaxReader" {
     const Attr = struct {
         kind: PaxAttributeKind,
@@ -1094,3 +724,7 @@ test "tar PaxReader" {
         try std.testing.expect(case.err == null);
     }
 }
+
+test {
+    _ = @import("tar/test.zig");
+}