From 32f977a4b7b17b774ff09157a902d4e22adf7384 Mon Sep 17 00:00:00 2001 From: Michael Dusan Date: Fri, 16 Jan 2026 15:38:01 -0500 Subject: [PATCH] std.fs.test: fix tests using Dir.realPath * add fn isRealPathSupported * incorporate into tests that depends on Dir.realPath --- lib/std/fs/test.zig | 60 ++++++++++++++++++++---------------------- lib/std/posix/test.zig | 5 ++-- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index 2d5dd78b23c753bc49d50b02785330728dfa8d60..a1987765659a54263d263d93e6ea2e2c73220414 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -20,6 +20,28 @@ const expectEqualStrings = std.testing.expectEqualStrings; const expectError = std.testing.expectError; const tmpDir = std.testing.tmpDir; +// This is kept in sync with Io.Threaded.realPath . +pub inline fn isRealPathSupported() bool { + return switch (native_os) { + .windows, + .driverkit, + .ios, + .maccatalyst, + .macos, + .tvos, + .visionos, + .watchos, + .linux, + .serenity, + .illumos, + .freebsd, + => true, + .dragonfly => builtin.os.version_range.semver.min.order(.{ .major = 6, .minor = 0, .patch = 0 }) != .lt, + .netbsd => builtin.os.version_range.semver.min.order(.{ .major = 10, .minor = 0, .patch = 0 }) != .lt, + else => false, + }; +} + const PathType = enum { relative, absolute, @@ -28,25 +50,7 @@ const PathType = enum { fn isSupported(self: PathType, target_os: std.Target.Os) bool { return switch (self) { .relative => true, - .absolute => switch (target_os.tag) { - .windows, - .driverkit, - .ios, - .maccatalyst, - .macos, - .tvos, - .visionos, - .watchos, - .linux, - .illumos, - .freebsd, - .serenity, - => true, - - .dragonfly => target_os.version_range.semver.max.order(.{ .major = 6, .minor = 0, .patch = 0 }) != .lt, - .netbsd => target_os.version_range.semver.max.order(.{ .major = 10, .minor = 0, .patch = 0 }) != .lt, - else => false, - }, + .absolute => isRealPathSupported(), .unc => target_os.tag == .windows, }; } @@ -314,8 +318,7 @@ test "openDir" { } test "accessAbsolute" { - if (native_os == .wasi) return error.SkipZigTest; - if (native_os == .openbsd) return error.SkipZigTest; + if (!isRealPathSupported()) return error.SkipZigTest; const io = testing.io; const gpa = testing.allocator; @@ -330,8 +333,7 @@ test "accessAbsolute" { } test "openDirAbsolute" { - if (native_os == .wasi) return error.SkipZigTest; - if (native_os == .openbsd) return error.SkipZigTest; + if (!isRealPathSupported()) return error.SkipZigTest; const io = testing.io; const gpa = testing.allocator; @@ -428,8 +430,7 @@ test "openDir non-cwd parent '..'" { } test "readLinkAbsolute" { - if (native_os == .wasi) return error.SkipZigTest; - if (native_os == .openbsd) return error.SkipZigTest; + if (!isRealPathSupported()) return error.SkipZigTest; const io = testing.io; @@ -645,8 +646,7 @@ fn contains(entries: *const std.array_list.Managed(Dir.Entry), el: Dir.Entry) bo } test "Dir.realPath smoke test" { - if (native_os == .wasi) return error.SkipZigTest; - if (native_os == .openbsd) return error.SkipZigTest; + if (!isRealPathSupported()) return error.SkipZigTest; try testWithAllSupportedPathTypes(struct { fn impl(ctx: *TestContext) !void { @@ -1074,8 +1074,7 @@ test "rename" { } test "renameAbsolute" { - if (native_os == .wasi) return error.SkipZigTest; - if (native_os == .openbsd) return error.SkipZigTest; + if (!isRealPathSupported()) return error.SkipZigTest; const io = testing.io; @@ -2029,8 +2028,7 @@ test "'.' and '..' in Dir functions" { } test "'.' and '..' in absolute functions" { - if (native_os == .wasi) return error.SkipZigTest; - if (native_os == .openbsd) return error.SkipZigTest; + if (!isRealPathSupported()) return error.SkipZigTest; const io = testing.io; diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig index 616c6901c0a935521288991c4c67c30e095e5fe7..e720c4a4e6d23aee4573fa082582e5e0c4c066e8 100644 --- a/lib/std/posix/test.zig +++ b/lib/std/posix/test.zig @@ -20,6 +20,8 @@ const expectEqualStrings = std.testing.expectEqualStrings; const expectError = std.testing.expectError; const tmpDir = std.testing.tmpDir; +const fstest = @import("../fs/test.zig"); + test "check WASI CWD" { if (native_os == .wasi) { const cwd: Dir = .cwd(); @@ -444,9 +446,8 @@ test "getppid" { } test "rename smoke test" { - if (native_os == .wasi) return error.SkipZigTest; if (native_os == .windows) return error.SkipZigTest; - if (native_os == .openbsd) return error.SkipZigTest; + if (!fstest.isRealPathSupported()) return error.SkipZigTest; const io = testing.io; const gpa = testing.allocator; -- 2.54.0