| ... | @@ -1074,6 +1074,45 @@ test "Dir.rename file <-> dir" { | ... | @@ -1074,6 +1074,45 @@ test "Dir.rename file <-> dir" { |
| 1074 | }.impl); | 1074 | }.impl); |
| 1075 | } | 1075 | } |
| 1076 | | 1076 | |
| | 1077 | test "Dir.renamePreserve onto existing" { |
| | 1078 | try testWithAllSupportedPathTypes(struct { |
| | 1079 | fn impl(ctx: *TestContext) !void { |
| | 1080 | const io = ctx.io; |
| | 1081 | |
| | 1082 | const test_file_path = try ctx.transformPath("test_file"); |
| | 1083 | const target_file_path = try ctx.transformPath("target_file"); |
| | 1084 | const test_dir_path = try ctx.transformPath("test_dir"); |
| | 1085 | const target_dir_path = try ctx.transformPath("target_dir"); |
| | 1086 | |
| | 1087 | try ctx.dir.writeFile(io, .{ .sub_path = test_file_path, .data = "" }); |
| | 1088 | try ctx.dir.writeFile(io, .{ .sub_path = target_file_path, .data = "" }); |
| | 1089 | try ctx.dir.createDir(io, test_dir_path, .default_dir); |
| | 1090 | try ctx.dir.createDir(io, target_dir_path, .default_dir); |
| | 1091 | |
| | 1092 | // file -> file |
| | 1093 | try expectError(error.PathAlreadyExists, ctx.dir.renamePreserve(test_file_path, ctx.dir, target_file_path, io)); |
| | 1094 | // file -> dir |
| | 1095 | try expectError(error.PathAlreadyExists, ctx.dir.renamePreserve(test_file_path, ctx.dir, target_dir_path, io)); |
| | 1096 | |
| | 1097 | // TODO: fix dir renaming on non-Linux, non-Windows systems, see https://codeberg.org/ziglang/zig/issues/35340 |
| | 1098 | if (native_os != .windows and native_os != .linux) return; |
| | 1099 | |
| | 1100 | // dir -> file |
| | 1101 | try expectError(error.PathAlreadyExists, ctx.dir.renamePreserve(test_dir_path, ctx.dir, target_file_path, io)); |
| | 1102 | // dir -> dir |
| | 1103 | try expectError(error.PathAlreadyExists, ctx.dir.renamePreserve(test_dir_path, ctx.dir, target_dir_path, io)); |
| | 1104 | |
| | 1105 | // dir -> non-empty dir |
| | 1106 | { |
| | 1107 | const target_dir = try ctx.dir.openDir(io, target_dir_path, .{}); |
| | 1108 | defer target_dir.close(io); |
| | 1109 | try target_dir.writeFile(io, .{ .sub_path = "test_file", .data = "" }); |
| | 1110 | } |
| | 1111 | try expectError(error.PathAlreadyExists, ctx.dir.renamePreserve(test_dir_path, ctx.dir, target_dir_path, io)); |
| | 1112 | } |
| | 1113 | }.impl); |
| | 1114 | } |
| | 1115 | |
| 1077 | test "rename" { | 1116 | test "rename" { |
| 1078 | const io = testing.io; | 1117 | const io = testing.io; |
| 1079 | | 1118 | |