| ... | @@ -59,137 +59,10 @@ test "readlinkat" { | ... | @@ -59,137 +59,10 @@ test "readlinkat" { |
| 59 | expect(mem.eql(u8, "file.txt", read_link)); | 59 | expect(mem.eql(u8, "file.txt", read_link)); |
| 60 | } | 60 | } |
| 61 | | 61 | |
| 62 | test "makePath, put some files in it, deleteTree" { | | |
| 63 | var tmp = tmpDir(.{}); | | |
| 64 | defer tmp.cleanup(); | | |
| 65 | | | |
| 66 | try tmp.dir.makePath("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c"); | | |
| 67 | try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense"); | | |
| 68 | try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah"); | | |
| 69 | try tmp.dir.deleteTree("os_test_tmp"); | | |
| 70 | if (tmp.dir.openDir("os_test_tmp", .{})) |dir| { | | |
| 71 | @panic("expected error"); | | |
| 72 | } else |err| { | | |
| 73 | expect(err == error.FileNotFound); | | |
| 74 | } | | |
| 75 | } | | |
| 76 | | | |
| 77 | test "access file" { | | |
| 78 | if (builtin.os.tag == .wasi) return error.SkipZigTest; | | |
| 79 | | | |
| 80 | var tmp = tmpDir(.{}); | | |
| 81 | defer tmp.cleanup(); | | |
| 82 | | | |
| 83 | try tmp.dir.makePath("os_test_tmp"); | | |
| 84 | if (tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{})) |ok| { | | |
| 85 | @panic("expected error"); | | |
| 86 | } else |err| { | | |
| 87 | expect(err == error.FileNotFound); | | |
| 88 | } | | |
| 89 | | | |
| 90 | try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", ""); | | |
| 91 | try tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{}); | | |
| 92 | try tmp.dir.deleteTree("os_test_tmp"); | | |
| 93 | } | | |
| 94 | | | |
| 95 | fn testThreadIdFn(thread_id: *Thread.Id) void { | 62 | fn testThreadIdFn(thread_id: *Thread.Id) void { |
| 96 | thread_id.* = Thread.getCurrentId(); | 63 | thread_id.* = Thread.getCurrentId(); |
| 97 | } | 64 | } |
| 98 | | 65 | |
| 99 | test "sendfile" { | | |
| 100 | var tmp = tmpDir(.{}); | | |
| 101 | defer tmp.cleanup(); | | |
| 102 | | | |
| 103 | try tmp.dir.makePath("os_test_tmp"); | | |
| 104 | defer tmp.dir.deleteTree("os_test_tmp") catch {}; | | |
| 105 | | | |
| 106 | var dir = try tmp.dir.openDir("os_test_tmp", .{}); | | |
| 107 | defer dir.close(); | | |
| 108 | | | |
| 109 | const line1 = "line1\n"; | | |
| 110 | const line2 = "second line\n"; | | |
| 111 | var vecs = [_]os.iovec_const{ | | |
| 112 | .{ | | |
| 113 | .iov_base = line1, | | |
| 114 | .iov_len = line1.len, | | |
| 115 | }, | | |
| 116 | .{ | | |
| 117 | .iov_base = line2, | | |
| 118 | .iov_len = line2.len, | | |
| 119 | }, | | |
| 120 | }; | | |
| 121 | | | |
| 122 | var src_file = try dir.createFile("sendfile1.txt", .{ .read = true }); | | |
| 123 | defer src_file.close(); | | |
| 124 | | | |
| 125 | try src_file.writevAll(&vecs); | | |
| 126 | | | |
| 127 | var dest_file = try dir.createFile("sendfile2.txt", .{ .read = true }); | | |
| 128 | defer dest_file.close(); | | |
| 129 | | | |
| 130 | const header1 = "header1\n"; | | |
| 131 | const header2 = "second header\n"; | | |
| 132 | const trailer1 = "trailer1\n"; | | |
| 133 | const trailer2 = "second trailer\n"; | | |
| 134 | var hdtr = [_]os.iovec_const{ | | |
| 135 | .{ | | |
| 136 | .iov_base = header1, | | |
| 137 | .iov_len = header1.len, | | |
| 138 | }, | | |
| 139 | .{ | | |
| 140 | .iov_base = header2, | | |
| 141 | .iov_len = header2.len, | | |
| 142 | }, | | |
| 143 | .{ | | |
| 144 | .iov_base = trailer1, | | |
| 145 | .iov_len = trailer1.len, | | |
| 146 | }, | | |
| 147 | .{ | | |
| 148 | .iov_base = trailer2, | | |
| 149 | .iov_len = trailer2.len, | | |
| 150 | }, | | |
| 151 | }; | | |
| 152 | | | |
| 153 | var written_buf: [100]u8 = undefined; | | |
| 154 | try dest_file.writeFileAll(src_file, .{ | | |
| 155 | .in_offset = 1, | | |
| 156 | .in_len = 10, | | |
| 157 | .headers_and_trailers = &hdtr, | | |
| 158 | .header_count = 2, | | |
| 159 | }); | | |
| 160 | const amt = try dest_file.preadAll(&written_buf, 0); | | |
| 161 | expect(mem.eql(u8, written_buf[0..amt], "header1\nsecond header\nine1\nsecontrailer1\nsecond trailer\n")); | | |
| 162 | } | | |
| 163 | | | |
| 164 | test "fs.copyFile" { | | |
| 165 | const data = "u6wj+JmdF3qHsFPE BUlH2g4gJCmEz0PP"; | | |
| 166 | const src_file = "tmp_test_copy_file.txt"; | | |
| 167 | const dest_file = "tmp_test_copy_file2.txt"; | | |
| 168 | const dest_file2 = "tmp_test_copy_file3.txt"; | | |
| 169 | | | |
| 170 | var tmp = tmpDir(.{}); | | |
| 171 | defer tmp.cleanup(); | | |
| 172 | | | |
| 173 | try tmp.dir.writeFile(src_file, data); | | |
| 174 | defer tmp.dir.deleteFile(src_file) catch {}; | | |
| 175 | | | |
| 176 | try tmp.dir.copyFile(src_file, tmp.dir, dest_file, .{}); | | |
| 177 | defer tmp.dir.deleteFile(dest_file) catch {}; | | |
| 178 | | | |
| 179 | try tmp.dir.copyFile(src_file, tmp.dir, dest_file2, .{ .override_mode = File.default_mode }); | | |
| 180 | defer tmp.dir.deleteFile(dest_file2) catch {}; | | |
| 181 | | | |
| 182 | try expectFileContents(tmp.dir, dest_file, data); | | |
| 183 | try expectFileContents(tmp.dir, dest_file2, data); | | |
| 184 | } | | |
| 185 | | | |
| 186 | fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void { | | |
| 187 | const contents = try dir.readFileAlloc(testing.allocator, file_path, 1000); | | |
| 188 | defer testing.allocator.free(contents); | | |
| 189 | | | |
| 190 | testing.expectEqualSlices(u8, data, contents); | | |
| 191 | } | | |
| 192 | | | |
| 193 | test "std.Thread.getCurrentId" { | 66 | test "std.Thread.getCurrentId" { |
| 194 | if (builtin.single_threaded) return error.SkipZigTest; | 67 | if (builtin.single_threaded) return error.SkipZigTest; |
| 195 | | 68 | |
| ... | @@ -242,29 +115,6 @@ test "cpu count" { | ... | @@ -242,29 +115,6 @@ test "cpu count" { |
| 242 | expect(cpu_count >= 1); | 115 | expect(cpu_count >= 1); |
| 243 | } | 116 | } |
| 244 | | 117 | |
| 245 | test "AtomicFile" { | | |
| 246 | const test_out_file = "tmp_atomic_file_test_dest.txt"; | | |
| 247 | const test_content = | | |
| 248 | \\ hello! | | |
| 249 | \\ this is a test file | | |
| 250 | ; | | |
| 251 | | | |
| 252 | var tmp = tmpDir(.{}); | | |
| 253 | defer tmp.cleanup(); | | |
| 254 | | | |
| 255 | { | | |
| 256 | var af = try tmp.dir.atomicFile(test_out_file, .{}); | | |
| 257 | defer af.deinit(); | | |
| 258 | try af.file.writeAll(test_content); | | |
| 259 | try af.finish(); | | |
| 260 | } | | |
| 261 | const content = try tmp.dir.readFileAlloc(testing.allocator, test_out_file, 9999); | | |
| 262 | defer testing.allocator.free(content); | | |
| 263 | expect(mem.eql(u8, content, test_content)); | | |
| 264 | | | |
| 265 | try tmp.dir.deleteFile(test_out_file); | | |
| 266 | } | | |
| 267 | | | |
| 268 | test "thread local storage" { | 118 | test "thread local storage" { |
| 269 | if (builtin.single_threaded) return error.SkipZigTest; | 119 | if (builtin.single_threaded) return error.SkipZigTest; |
| 270 | const thread1 = try Thread.spawn({}, testTls); | 120 | const thread1 = try Thread.spawn({}, testTls); |
| ... | @@ -299,13 +149,6 @@ test "getcwd" { | ... | @@ -299,13 +149,6 @@ test "getcwd" { |
| 299 | _ = os.getcwd(&buf) catch undefined; | 149 | _ = os.getcwd(&buf) catch undefined; |
| 300 | } | 150 | } |
| 301 | | 151 | |
| 302 | test "realpath" { | | |
| 303 | if (builtin.os.tag == .wasi) return error.SkipZigTest; | | |
| 304 | | | |
| 305 | var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; | | |
| 306 | testing.expectError(error.FileNotFound, fs.realpath("definitely_bogus_does_not_exist1234", &buf)); | | |
| 307 | } | | |
| 308 | | | |
| 309 | test "sigaltstack" { | 152 | test "sigaltstack" { |
| 310 | if (builtin.os.tag == .windows or builtin.os.tag == .wasi) return error.SkipZigTest; | 153 | if (builtin.os.tag == .windows or builtin.os.tag == .wasi) return error.SkipZigTest; |
| 311 | | 154 | |