mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:44:43 +01:00
std.fs.test: fix tests using Dir.realPath
* add fn isRealPathSupported * incorporate into tests that depends on Dir.realPath
This commit is contained in:
parent
fc59f0e7f0
commit
32f977a4b7
2 changed files with 32 additions and 33 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue