authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-03-10 19:39:18+01:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-03-10 19:39:18+01:00
logb80abf0296de5034ddaf149074fe7de18347bc20
treea55f38efece0376cbdea768f433bdca2c78dc297
parentcfe5c88ad6081e284d0caf36cf8d7e80fe39b676
parenta5dd6444c39e3852962a3b1a74d832ca9fdadd32

Merge pull request 'Add a few `fs` test cases from otherwise obsoleted PRs' (#31437) from squeek502/zig:fs-test-cases into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31437

1 files changed, 49 insertions(+), 0 deletions(-)

lib/std/fs/test.zig+49
......@@ -298,6 +298,28 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {
298298 }.impl);
299299}
300300
301test "Dir.statFile on a symlink" {
302 const io = testing.io;
303
304 try testWithAllSupportedPathTypes(struct {
305 fn impl(ctx: *TestContext) !void {
306 const dir_target_path = try ctx.transformPath("test_file");
307 try ctx.dir.writeFile(io, .{
308 .sub_path = dir_target_path,
309 .data = "Some test content",
310 });
311
312 try setupSymlink(io, ctx.dir, dir_target_path, "symlink", .{});
313
314 const file_stat = try ctx.dir.statFile(io, "test_file", .{ .follow_symlinks = false });
315 try testing.expectEqual(File.Kind.file, file_stat.kind);
316
317 const link_stat = try ctx.dir.statFile(io, "symlink", .{ .follow_symlinks = false });
318 try testing.expectEqual(File.Kind.sym_link, link_stat.kind);
319 }
320 }.impl);
321}
322
301323test "openDir" {
302324 const io = testing.io;
303325
......@@ -1843,6 +1865,33 @@ test "read from locked file" {
18431865 }.impl);
18441866}
18451867
1868test "use Lock.none to unlock files" {
1869 if (native_os == .wasi) return error.SkipZigTest;
1870
1871 const io = testing.io;
1872
1873 var tmp = tmpDir(.{});
1874 defer tmp.cleanup();
1875
1876 // Create a locked file.
1877 const test_file = try tmp.dir.createFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true });
1878 defer test_file.close(io);
1879
1880 // Attempt to unlock the file via fs.lock with Lock.none.
1881 try test_file.lock(io, .none);
1882
1883 // Attempt to open the file now that it should be unlocked.
1884 const test_file2 = try tmp.dir.openFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true });
1885 defer test_file2.close(io);
1886
1887 // Make sure Lock.none works with tryLock as well.
1888 try testing.expect(try test_file2.tryLock(io, .none));
1889
1890 // Attempt to open the file since it should be unlocked again.
1891 const test_file3 = try tmp.dir.openFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true });
1892 test_file3.close(io);
1893}
1894
18461895test "walker" {
18471896 const io = testing.io;
18481897