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;
2020const expectError = std.testing.expectError;
2121const 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
2345const PathType = enum {
2446 relative,
2547 absolute,
......@@ -28,25 +50,7 @@ const PathType = enum {
2850 fn isSupported(self: PathType, target_os: std.Target.Os) bool {
2951 return switch (self) {
3052 .relative => true,
31 .absolute => switch (target_os.tag) {
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 },
53 .absolute => isRealPathSupported(),
5054 .unc => target_os.tag == .windows,
5155 };
5256 }
......@@ -314,8 +318,7 @@ test "openDir" {
314318}
315319
316320test "accessAbsolute" {
317 if (native_os == .wasi) return error.SkipZigTest;
318 if (native_os == .openbsd) return error.SkipZigTest;
321 if (!isRealPathSupported()) return error.SkipZigTest;
319322
320323 const io = testing.io;
321324 const gpa = testing.allocator;
......@@ -330,8 +333,7 @@ test "accessAbsolute" {
330333}
331334
332335test "openDirAbsolute" {
333 if (native_os == .wasi) return error.SkipZigTest;
334 if (native_os == .openbsd) return error.SkipZigTest;
336 if (!isRealPathSupported()) return error.SkipZigTest;
335337
336338 const io = testing.io;
337339 const gpa = testing.allocator;
......@@ -428,8 +430,7 @@ test "openDir non-cwd parent '..'" {
428430}
429431
430432test "readLinkAbsolute" {
431 if (native_os == .wasi) return error.SkipZigTest;
432 if (native_os == .openbsd) return error.SkipZigTest;
433 if (!isRealPathSupported()) return error.SkipZigTest;
433434
434435 const io = testing.io;
435436
......@@ -645,8 +646,7 @@ fn contains(entries: *const std.array_list.Managed(Dir.Entry), el: Dir.Entry) bo
645646}
646647
647648test "Dir.realPath smoke test" {
648 if (native_os == .wasi) return error.SkipZigTest;
649 if (native_os == .openbsd) return error.SkipZigTest;
649 if (!isRealPathSupported()) return error.SkipZigTest;
650650
651651 try testWithAllSupportedPathTypes(struct {
652652 fn impl(ctx: *TestContext) !void {
......@@ -1074,8 +1074,7 @@ test "rename" {
10741074}
10751075
10761076test "renameAbsolute" {
1077 if (native_os == .wasi) return error.SkipZigTest;
1078 if (native_os == .openbsd) return error.SkipZigTest;
1077 if (!isRealPathSupported()) return error.SkipZigTest;
10791078
10801079 const io = testing.io;
10811080
......@@ -2029,8 +2028,7 @@ test "'.' and '..' in Dir functions" {
20292028}
20302029
20312030test "'.' and '..' in absolute functions" {
2032 if (native_os == .wasi) return error.SkipZigTest;
2033 if (native_os == .openbsd) return error.SkipZigTest;
2031 if (!isRealPathSupported()) return error.SkipZigTest;
20342032
20352033 const io = testing.io;
20362034
lib/std/posix/test.zig+3-2
......@@ -20,6 +20,8 @@ const expectEqualStrings = std.testing.expectEqualStrings;
2020const expectError = std.testing.expectError;
2121const tmpDir = std.testing.tmpDir;
2222
23const fstest = @import("../fs/test.zig");
24
2325test "check WASI CWD" {
2426 if (native_os == .wasi) {
2527 const cwd: Dir = .cwd();
......@@ -444,9 +446,8 @@ test "getppid" {
444446}
445447
446448test "rename smoke test" {
447 if (native_os == .wasi) return error.SkipZigTest;
448449 if (native_os == .windows) return error.SkipZigTest;
449 if (native_os == .openbsd) return error.SkipZigTest;
450 if (!fstest.isRealPathSupported()) return error.SkipZigTest;
450451
451452 const io = testing.io;
452453 const gpa = testing.allocator;