| ... | @@ -461,18 +461,44 @@ test "Dir.rename directories" { | ... | @@ -461,18 +461,44 @@ test "Dir.rename directories" { |
| 461 | file = try dir.openFile("test_file", .{}); | 461 | file = try dir.openFile("test_file", .{}); |
| 462 | file.close(); | 462 | file.close(); |
| 463 | dir.close(); | 463 | dir.close(); |
| | 464 | } |
| | 465 | |
| | 466 | test "Dir.rename directory onto empty dir" { |
| | 467 | // TODO: Fix on Windows, see https://github.com/ziglang/zig/issues/6364 |
| | 468 | if (builtin.os.tag == .windows) return error.SkipZigTest; |
| | 469 | |
| | 470 | var tmp_dir = testing.tmpDir(.{}); |
| | 471 | defer tmp_dir.cleanup(); |
| 464 | | 472 | |
| 465 | // Try to rename to a non-empty directory now | 473 | try tmp_dir.dir.makeDir("test_dir"); |
| 466 | var target_dir = try tmp_dir.dir.makeOpenPath("non_empty_target_dir", .{}); | 474 | try tmp_dir.dir.makeDir("target_dir"); |
| 467 | file = try target_dir.createFile("filler", .{ .read = true }); | 475 | try tmp_dir.dir.rename("test_dir", "target_dir"); |
| | 476 | |
| | 477 | // Ensure the directory was renamed |
| | 478 | try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir", .{})); |
| | 479 | var dir = try tmp_dir.dir.openDir("target_dir", .{}); |
| | 480 | dir.close(); |
| | 481 | } |
| | 482 | |
| | 483 | test "Dir.rename directory onto non-empty dir" { |
| | 484 | // TODO: Fix on Windows, see https://github.com/ziglang/zig/issues/6364 |
| | 485 | if (builtin.os.tag == .windows) return error.SkipZigTest; |
| | 486 | |
| | 487 | var tmp_dir = testing.tmpDir(.{}); |
| | 488 | defer tmp_dir.cleanup(); |
| | 489 | |
| | 490 | try tmp_dir.dir.makeDir("test_dir"); |
| | 491 | |
| | 492 | var target_dir = try tmp_dir.dir.makeOpenPath("target_dir", .{}); |
| | 493 | var file = try target_dir.createFile("test_file", .{ .read = true }); |
| 468 | file.close(); | 494 | file.close(); |
| | 495 | target_dir.close(); |
| 469 | | 496 | |
| 470 | try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.rename("test_dir_renamed_again", "non_empty_target_dir")); | 497 | // Rename should fail with PathAlreadyExists if target_dir is non-empty |
| | 498 | try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.rename("test_dir", "target_dir")); |
| 471 | | 499 | |
| 472 | // Ensure the directory was not renamed | 500 | // Ensure the directory was not renamed |
| 473 | dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{}); | 501 | var dir = try tmp_dir.dir.openDir("test_dir", .{}); |
| 474 | file = try dir.openFile("test_file", .{}); | | |
| 475 | file.close(); | | |
| 476 | dir.close(); | 502 | dir.close(); |
| 477 | } | 503 | } |
| 478 | | 504 | |