| ... | @@ -932,3 +932,64 @@ test "walker" { | ... | @@ -932,3 +932,64 @@ test "walker" { |
| 932 | try testing.expectEqualStrings(expected_dir_name, try fs.path.relative(allocator, tmp_path, entry.path)); | 932 | try testing.expectEqualStrings(expected_dir_name, try fs.path.relative(allocator, tmp_path, entry.path)); |
| 933 | } | 933 | } |
| 934 | } | 934 | } |
| | 935 | |
| | 936 | test ". and .. in fs.Dir functions" { |
| | 937 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| | 938 | |
| | 939 | var tmp = tmpDir(.{}); |
| | 940 | defer tmp.cleanup(); |
| | 941 | |
| | 942 | try tmp.dir.makeDir("./subdir"); |
| | 943 | try tmp.dir.access("./subdir", .{}); |
| | 944 | var created_subdir = try tmp.dir.openDir("./subdir", .{}); |
| | 945 | created_subdir.close(); |
| | 946 | |
| | 947 | const created_file = try tmp.dir.createFile("./subdir/../file", .{}); |
| | 948 | created_file.close(); |
| | 949 | try tmp.dir.access("./subdir/../file", .{}); |
| | 950 | |
| | 951 | try tmp.dir.copyFile("./subdir/../file", tmp.dir, "./subdir/../copy", .{}); |
| | 952 | try tmp.dir.rename("./subdir/../copy", "./subdir/../rename"); |
| | 953 | const renamed_file = try tmp.dir.openFile("./subdir/../rename", .{}); |
| | 954 | renamed_file.close(); |
| | 955 | try tmp.dir.deleteFile("./subdir/../rename"); |
| | 956 | |
| | 957 | try tmp.dir.deleteDir("./subdir"); |
| | 958 | } |
| | 959 | |
| | 960 | test ". and .. in absolute functions" { |
| | 961 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| | 962 | |
| | 963 | var tmp = tmpDir(.{}); |
| | 964 | defer tmp.cleanup(); |
| | 965 | |
| | 966 | var arena = ArenaAllocator.init(testing.allocator); |
| | 967 | defer arena.deinit(); |
| | 968 | const allocator = &arena.allocator; |
| | 969 | |
| | 970 | const base_path = blk: { |
| | 971 | const relative_path = try fs.path.join(&arena.allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); |
| | 972 | break :blk try fs.realpathAlloc(&arena.allocator, relative_path); |
| | 973 | }; |
| | 974 | |
| | 975 | const subdir_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "./subdir" }); |
| | 976 | try fs.makeDirAbsolute(subdir_path); |
| | 977 | try fs.accessAbsolute(subdir_path, .{}); |
| | 978 | var created_subdir = try fs.openDirAbsolute(subdir_path, .{}); |
| | 979 | created_subdir.close(); |
| | 980 | |
| | 981 | const created_file_path = try fs.path.join(allocator, &[_][]const u8{ subdir_path, "../file" }); |
| | 982 | const created_file = try fs.createFileAbsolute(created_file_path, .{}); |
| | 983 | created_file.close(); |
| | 984 | try fs.accessAbsolute(created_file_path, .{}); |
| | 985 | |
| | 986 | const copied_file_path = try fs.path.join(allocator, &[_][]const u8{ subdir_path, "../copy" }); |
| | 987 | try fs.copyFileAbsolute(created_file_path, copied_file_path, .{}); |
| | 988 | const renamed_file_path = try fs.path.join(allocator, &[_][]const u8{ subdir_path, "../rename" }); |
| | 989 | try fs.renameAbsolute(copied_file_path, renamed_file_path); |
| | 990 | const renamed_file = try fs.openFileAbsolute(renamed_file_path, .{}); |
| | 991 | renamed_file.close(); |
| | 992 | try fs.deleteFileAbsolute(renamed_file_path); |
| | 993 | |
| | 994 | try fs.deleteDirAbsolute(subdir_path); |
| | 995 | } |