authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2026-01-16 15:38:01-05:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-01-21 16:41:37+01:00
log32f977a4b7b17b774ff09157a902d4e22adf7384
treee806fa66e8fb8671f5eca43e984767812d4dfa83
parentfc59f0e7f0681096cf99fbd27330ed7c5ba5ffaa
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.fs.test: fix tests using Dir.realPath

* add fn isRealPathSupported * incorporate into tests that depends on Dir.realPath

2 files changed, 32 insertions(+), 33 deletions(-)

lib/std/fs/test.zig+29-31
...@@ -20,6 +20,28 @@ const expectEqualStrings = std.testing.expectEqualStrings;...@@ -20,6 +20,28 @@ const expectEqualStrings = std.testing.expectEqualStrings;
20const expectError = std.testing.expectError;20const expectError = std.testing.expectError;
21const tmpDir = std.testing.tmpDir;21const tmpDir = std.testing.tmpDir;
2222
23// This is kept in sync with Io.Threaded.realPath .
24pub inline fn isRealPathSupported() bool {
25 return switch (native_os) {
26 .windows,
27 .driverkit,
28 .ios,
29 .maccatalyst,
30 .macos,
31 .tvos,
32 .visionos,
33 .watchos,
34 .linux,
35 .serenity,
36 .illumos,
37 .freebsd,
38 => true,
39 .dragonfly => builtin.os.version_range.semver.min.order(.{ .major = 6, .minor = 0, .patch = 0 }) != .lt,
40 .netbsd => builtin.os.version_range.semver.min.order(.{ .major = 10, .minor = 0, .patch = 0 }) != .lt,
41 else => false,
42 };
43}
44
23const PathType = enum {45const PathType = enum {
24 relative,46 relative,
25 absolute,47 absolute,
...@@ -28,25 +50,7 @@ const PathType = enum {...@@ -28,25 +50,7 @@ const PathType = enum {
28 fn isSupported(self: PathType, target_os: std.Target.Os) bool {50 fn isSupported(self: PathType, target_os: std.Target.Os) bool {
29 return switch (self) {51 return switch (self) {
30 .relative => true,52 .relative => true,
31 .absolute => switch (target_os.tag) {53 .absolute => isRealPathSupported(),
32 .windows,
33 .driverkit,
34 .ios,
35 .maccatalyst,
36 .macos,
37 .tvos,
38 .visionos,
39 .watchos,
40 .linux,
41 .illumos,
42 .freebsd,
43 .serenity,
44 => true,
45
46 .dragonfly => target_os.version_range.semver.max.order(.{ .major = 6, .minor = 0, .patch = 0 }) != .lt,
47 .netbsd => target_os.version_range.semver.max.order(.{ .major = 10, .minor = 0, .patch = 0 }) != .lt,
48 else => false,
49 },
50 .unc => target_os.tag == .windows,54 .unc => target_os.tag == .windows,
51 };55 };
52 }56 }
...@@ -314,8 +318,7 @@ test "openDir" {...@@ -314,8 +318,7 @@ test "openDir" {
314}318}
315319
316test "accessAbsolute" {320test "accessAbsolute" {
317 if (native_os == .wasi) return error.SkipZigTest;321 if (!isRealPathSupported()) return error.SkipZigTest;
318 if (native_os == .openbsd) return error.SkipZigTest;
319322
320 const io = testing.io;323 const io = testing.io;
321 const gpa = testing.allocator;324 const gpa = testing.allocator;
...@@ -330,8 +333,7 @@ test "accessAbsolute" {...@@ -330,8 +333,7 @@ test "accessAbsolute" {
330}333}
331334
332test "openDirAbsolute" {335test "openDirAbsolute" {
333 if (native_os == .wasi) return error.SkipZigTest;336 if (!isRealPathSupported()) return error.SkipZigTest;
334 if (native_os == .openbsd) return error.SkipZigTest;
335337
336 const io = testing.io;338 const io = testing.io;
337 const gpa = testing.allocator;339 const gpa = testing.allocator;
...@@ -428,8 +430,7 @@ test "openDir non-cwd parent '..'" {...@@ -428,8 +430,7 @@ test "openDir non-cwd parent '..'" {
428}430}
429431
430test "readLinkAbsolute" {432test "readLinkAbsolute" {
431 if (native_os == .wasi) return error.SkipZigTest;433 if (!isRealPathSupported()) return error.SkipZigTest;
432 if (native_os == .openbsd) return error.SkipZigTest;
433434
434 const io = testing.io;435 const io = testing.io;
435436
...@@ -645,8 +646,7 @@ fn contains(entries: *const std.array_list.Managed(Dir.Entry), el: Dir.Entry) bo...@@ -645,8 +646,7 @@ fn contains(entries: *const std.array_list.Managed(Dir.Entry), el: Dir.Entry) bo
645}646}
646647
647test "Dir.realPath smoke test" {648test "Dir.realPath smoke test" {
648 if (native_os == .wasi) return error.SkipZigTest;649 if (!isRealPathSupported()) return error.SkipZigTest;
649 if (native_os == .openbsd) return error.SkipZigTest;
650650
651 try testWithAllSupportedPathTypes(struct {651 try testWithAllSupportedPathTypes(struct {
652 fn impl(ctx: *TestContext) !void {652 fn impl(ctx: *TestContext) !void {
...@@ -1074,8 +1074,7 @@ test "rename" {...@@ -1074,8 +1074,7 @@ test "rename" {
1074}1074}
10751075
1076test "renameAbsolute" {1076test "renameAbsolute" {
1077 if (native_os == .wasi) return error.SkipZigTest;1077 if (!isRealPathSupported()) return error.SkipZigTest;
1078 if (native_os == .openbsd) return error.SkipZigTest;
10791078
1080 const io = testing.io;1079 const io = testing.io;
10811080
...@@ -2029,8 +2028,7 @@ test "'.' and '..' in Dir functions" {...@@ -2029,8 +2028,7 @@ test "'.' and '..' in Dir functions" {
2029}2028}
20302029
2031test "'.' and '..' in absolute functions" {2030test "'.' and '..' in absolute functions" {
2032 if (native_os == .wasi) return error.SkipZigTest;2031 if (!isRealPathSupported()) return error.SkipZigTest;
2033 if (native_os == .openbsd) return error.SkipZigTest;
20342032
2035 const io = testing.io;2033 const io = testing.io;
20362034
lib/std/posix/test.zig+3-2
...@@ -20,6 +20,8 @@ const expectEqualStrings = std.testing.expectEqualStrings;...@@ -20,6 +20,8 @@ const expectEqualStrings = std.testing.expectEqualStrings;
20const expectError = std.testing.expectError;20const expectError = std.testing.expectError;
21const tmpDir = std.testing.tmpDir;21const tmpDir = std.testing.tmpDir;
2222
23const fstest = @import("../fs/test.zig");
24
23test "check WASI CWD" {25test "check WASI CWD" {
24 if (native_os == .wasi) {26 if (native_os == .wasi) {
25 const cwd: Dir = .cwd();27 const cwd: Dir = .cwd();
...@@ -444,9 +446,8 @@ test "getppid" {...@@ -444,9 +446,8 @@ test "getppid" {
444}446}
445447
446test "rename smoke test" {448test "rename smoke test" {
447 if (native_os == .wasi) return error.SkipZigTest;
448 if (native_os == .windows) return error.SkipZigTest;449 if (native_os == .windows) return error.SkipZigTest;
449 if (native_os == .openbsd) return error.SkipZigTest;450 if (!fstest.isRealPathSupported()) return error.SkipZigTest;
450451
451 const io = testing.io;452 const io = testing.io;
452 const gpa = testing.allocator;453 const gpa = testing.allocator;