| ... | @@ -73,6 +73,38 @@ test "directory operations on files" { | ... | @@ -73,6 +73,38 @@ test "directory operations on files" { |
| 73 | file.close(); | 73 | file.close(); |
| 74 | } | 74 | } |
| 75 | | 75 | |
| | 76 | test "file operations on directories" { |
| | 77 | var tmp_dir = tmpDir(.{}); |
| | 78 | defer tmp_dir.cleanup(); |
| | 79 | |
| | 80 | const test_dir_name = "test_dir"; |
| | 81 | |
| | 82 | try tmp_dir.dir.makeDir(test_dir_name); |
| | 83 | |
| | 84 | testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{})); |
| | 85 | testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name)); |
| | 86 | testing.expectError(error.IsDir, tmp_dir.dir.readFileAlloc(testing.allocator, test_dir_name, std.math.maxInt(usize))); |
| | 87 | // note: the `.write = true` is necessary to ensure the error occurs on all platforms |
| | 88 | testing.expectError(error.IsDir, tmp_dir.dir.openFile(test_dir_name, .{ .write = true })); |
| | 89 | |
| | 90 | if (builtin.os.tag != .wasi) { |
| | 91 | // TODO: use Dir's realpath function once that exists |
| | 92 | const absolute_path = blk: { |
| | 93 | const relative_path = try fs.path.join(testing.allocator, &[_][]const u8{ "zig-cache", "tmp", tmp_dir.sub_path[0..], test_dir_name }); |
| | 94 | defer testing.allocator.free(relative_path); |
| | 95 | break :blk try fs.realpathAlloc(testing.allocator, relative_path); |
| | 96 | }; |
| | 97 | defer testing.allocator.free(absolute_path); |
| | 98 | |
| | 99 | testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{})); |
| | 100 | testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path)); |
| | 101 | } |
| | 102 | |
| | 103 | // ensure the directory still exists as a sanity check |
| | 104 | var dir = try tmp_dir.dir.openDir(test_dir_name, .{}); |
| | 105 | dir.close(); |
| | 106 | } |
| | 107 | |
| 76 | test "openSelfExe" { | 108 | test "openSelfExe" { |
| 77 | if (builtin.os.tag == .wasi) return error.SkipZigTest; | 109 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| 78 | | 110 | |