authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2024-02-02 11:52:42-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-02 18:03:17-08:00
logf2e249e92020462ac29f34fc3d45cef3dc90a3b2
treebeec6848767c1c0c6541123d316fe44533207b80
parent5e791e8e0786ea050f0f09da5de4657f3f9caad1

fs tests: Make path type show up in stack traces of testWithAllSupportedPathTypes

This allows for easier debugging without the need to print out the path type to stderr. Context: 5a3ae38f3b79a69cb6f4ad28934a51165cae2ef1

1 files changed, 10 insertions(+), 7 deletions(-)

lib/std/fs/test.zig+10-7
...@@ -106,15 +106,18 @@ const TestContext = struct {...@@ -106,15 +106,18 @@ const TestContext = struct {
106/// and will be passed a TestContext that can transform a relative path into the path type under test.106/// and will be passed a TestContext that can transform a relative path into the path type under test.
107/// The TestContext will also create a tmp directory for you (and will clean it up for you too).107/// The TestContext will also create a tmp directory for you (and will clean it up for you too).
108fn testWithAllSupportedPathTypes(test_func: anytype) !void {108fn testWithAllSupportedPathTypes(test_func: anytype) !void {
109 inline for (@typeInfo(PathType).Enum.fields) |enum_field| {109 try testWithPathTypeIfSupported(.relative, test_func);
110 const path_type = @field(PathType, enum_field.name);110 try testWithPathTypeIfSupported(.absolute, test_func);
111 if (!(comptime path_type.isSupported(builtin.os))) continue;111 try testWithPathTypeIfSupported(.unc, test_func);
112}
112113
113 var ctx = TestContext.init(path_type, testing.allocator, path_type.getTransformFn());114fn testWithPathTypeIfSupported(comptime path_type: PathType, test_func: anytype) !void {
114 defer ctx.deinit();115 if (!(comptime path_type.isSupported(builtin.os))) return;
115116
116 try test_func(&ctx);117 var ctx = TestContext.init(path_type, testing.allocator, path_type.getTransformFn());
117 }118 defer ctx.deinit();
119
120 try test_func(&ctx);
118}121}
119122
120// For use in test setup. If the symlink creation fails on Windows with123// For use in test setup. If the symlink creation fails on Windows with