| ... | @@ -40,6 +40,39 @@ test "readAllAlloc" { | ... | @@ -40,6 +40,39 @@ test "readAllAlloc" { |
| 40 | testing.expectError(error.FileTooBig, file.readAllAlloc(testing.allocator, file_size, write_buf.len - 1)); | 40 | testing.expectError(error.FileTooBig, file.readAllAlloc(testing.allocator, file_size, write_buf.len - 1)); |
| 41 | } | 41 | } |
| 42 | | 42 | |
| | 43 | test "directory operations on files" { |
| | 44 | var tmp_dir = tmpDir(.{}); |
| | 45 | defer tmp_dir.cleanup(); |
| | 46 | |
| | 47 | const test_file_name = "test_file"; |
| | 48 | |
| | 49 | var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true }); |
| | 50 | file.close(); |
| | 51 | |
| | 52 | testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name)); |
| | 53 | testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{})); |
| | 54 | testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name)); |
| | 55 | |
| | 56 | if (builtin.os.tag != .wasi) { |
| | 57 | // TODO: use Dir's realpath function once that exists |
| | 58 | const absolute_path = blk: { |
| | 59 | const relative_path = try fs.path.join(testing.allocator, &[_][]const u8{ "zig-cache", "tmp", tmp_dir.sub_path[0..], test_file_name }); |
| | 60 | defer testing.allocator.free(relative_path); |
| | 61 | break :blk try fs.realpathAlloc(testing.allocator, relative_path); |
| | 62 | }; |
| | 63 | defer testing.allocator.free(absolute_path); |
| | 64 | |
| | 65 | testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path)); |
| | 66 | testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path)); |
| | 67 | } |
| | 68 | |
| | 69 | // ensure the file still exists and is a file as a sanity check |
| | 70 | file = try tmp_dir.dir.openFile(test_file_name, .{}); |
| | 71 | const stat = try file.stat(); |
| | 72 | testing.expect(stat.kind == .File); |
| | 73 | file.close(); |
| | 74 | } |
| | 75 | |
| 43 | test "openSelfExe" { | 76 | test "openSelfExe" { |
| 44 | if (builtin.os.tag == .wasi) return error.SkipZigTest; | 77 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| 45 | | 78 | |