| ... | ... | @@ -1080,3 +1080,103 @@ test "isatty" { |
| 1080 | 1080 | var file = try tmp.dir.createFile("foo", .{}); |
| 1081 | 1081 | try expectEqual(os.isatty(file.handle), false); |
| 1082 | 1082 | } |
| 1083 | |
| 1084 | test "read with empty buffer" { |
| 1085 | if (native_os == .wasi) return error.SkipZigTest; |
| 1086 | |
| 1087 | var tmp = tmpDir(.{}); |
| 1088 | defer tmp.cleanup(); |
| 1089 | |
| 1090 | var arena = ArenaAllocator.init(testing.allocator); |
| 1091 | defer arena.deinit(); |
| 1092 | const allocator = arena.allocator(); |
| 1093 | |
| 1094 | // Get base abs path |
| 1095 | const base_path = blk: { |
| 1096 | const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); |
| 1097 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 1098 | }; |
| 1099 | |
| 1100 | var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); |
| 1101 | var file = try fs.cwd().createFile(file_path, .{ .read = true }); |
| 1102 | defer file.close(); |
| 1103 | |
| 1104 | var bytes = try allocator.alloc(u8, 0); |
| 1105 | |
| 1106 | _ = try os.read(file.handle, bytes); |
| 1107 | } |
| 1108 | |
| 1109 | test "pread with empty buffer" { |
| 1110 | if (native_os == .wasi) return error.SkipZigTest; |
| 1111 | |
| 1112 | var tmp = tmpDir(.{}); |
| 1113 | defer tmp.cleanup(); |
| 1114 | |
| 1115 | var arena = ArenaAllocator.init(testing.allocator); |
| 1116 | defer arena.deinit(); |
| 1117 | const allocator = arena.allocator(); |
| 1118 | |
| 1119 | // Get base abs path |
| 1120 | const base_path = blk: { |
| 1121 | const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); |
| 1122 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 1123 | }; |
| 1124 | |
| 1125 | var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); |
| 1126 | var file = try fs.cwd().createFile(file_path, .{ .read = true }); |
| 1127 | defer file.close(); |
| 1128 | |
| 1129 | var bytes = try allocator.alloc(u8, 0); |
| 1130 | |
| 1131 | _ = try os.pread(file.handle, bytes, 0); |
| 1132 | } |
| 1133 | |
| 1134 | test "write with empty buffer" { |
| 1135 | if (native_os == .wasi) return error.SkipZigTest; |
| 1136 | |
| 1137 | var tmp = tmpDir(.{}); |
| 1138 | defer tmp.cleanup(); |
| 1139 | |
| 1140 | var arena = ArenaAllocator.init(testing.allocator); |
| 1141 | defer arena.deinit(); |
| 1142 | const allocator = arena.allocator(); |
| 1143 | |
| 1144 | // Get base abs path |
| 1145 | const base_path = blk: { |
| 1146 | const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); |
| 1147 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 1148 | }; |
| 1149 | |
| 1150 | var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); |
| 1151 | var file = try fs.cwd().createFile(file_path, .{}); |
| 1152 | defer file.close(); |
| 1153 | |
| 1154 | var bytes = try allocator.alloc(u8, 0); |
| 1155 | |
| 1156 | _ = try os.write(file.handle, bytes); |
| 1157 | } |
| 1158 | |
| 1159 | test "pwrite with empty buffer" { |
| 1160 | if (native_os == .wasi) return error.SkipZigTest; |
| 1161 | |
| 1162 | var tmp = tmpDir(.{}); |
| 1163 | defer tmp.cleanup(); |
| 1164 | |
| 1165 | var arena = ArenaAllocator.init(testing.allocator); |
| 1166 | defer arena.deinit(); |
| 1167 | const allocator = arena.allocator(); |
| 1168 | |
| 1169 | // Get base abs path |
| 1170 | const base_path = blk: { |
| 1171 | const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); |
| 1172 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 1173 | }; |
| 1174 | |
| 1175 | var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); |
| 1176 | var file = try fs.cwd().createFile(file_path, .{}); |
| 1177 | defer file.close(); |
| 1178 | |
| 1179 | var bytes = try allocator.alloc(u8, 0); |
| 1180 | |
| 1181 | _ = try os.pwrite(file.handle, bytes, 0); |
| 1182 | } |