authorgravatar for 27089165+DivergentClouds@users.noreply.github.comDivergentClouds <27089165+DivergentClouds@users.noreply.github.com> 2024-09-04 07:28:55-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-03-10 00:10:48-07:00
log416ef983c40cf96b522fd976b8fbaf82eaf63906
tree00961e05e43d914deffb44d8f920c21a46eae83c
parentf16eb18ce8c24ed743aae1faa4980052cb9f4f36

add test for Lock.none


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

lib/std/fs/test.zig+27
...@@ -1843,6 +1843,33 @@ test "read from locked file" {...@@ -1843,6 +1843,33 @@ test "read from locked file" {
1843 }.impl);1843 }.impl);
1844}1844}
18451845
1846test "use Lock.none to unlock files" {
1847 if (native_os == .wasi) return error.SkipZigTest;
1848
1849 const io = testing.io;
1850
1851 var tmp = tmpDir(.{});
1852 defer tmp.cleanup();
1853
1854 // Create a locked file.
1855 const test_file = try tmp.dir.createFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true });
1856 defer test_file.close(io);
1857
1858 // Attempt to unlock the file via fs.lock with Lock.none.
1859 try test_file.lock(io, .none);
1860
1861 // Attempt to open the file now that it should be unlocked.
1862 const test_file2 = try tmp.dir.openFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true });
1863 defer test_file2.close(io);
1864
1865 // Make sure Lock.none works with tryLock as well.
1866 try testing.expect(try test_file2.tryLock(io, .none));
1867
1868 // Attempt to open the file since it should be unlocked again.
1869 const test_file3 = try tmp.dir.openFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true });
1870 test_file3.close(io);
1871}
1872
1846test "walker" {1873test "walker" {
1847 const io = testing.io;1874 const io = testing.io;
18481875