zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 416ef983c40cf96b522fd976b8fbaf82eaf63906 (tree)
parent f16eb18ce8c24ed743aae1faa4980052cb9f4f36
Author: DivergentClouds <27089165+DivergentClouds@users.noreply.github.com>
Date:   Wed,  4 Sep 2024 07:28:55 -0700

add test for Lock.none

Diffstat:
Mlib/std/fs/test.zig | 27+++++++++++++++++++++++++++
1 file changed, 27 insertions(+), 0 deletions(-)

diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig @@ -1843,6 +1843,33 @@ test "read from locked file" { }.impl); } +test "use Lock.none to unlock files" { + if (native_os == .wasi) return error.SkipZigTest; + + const io = testing.io; + + var tmp = tmpDir(.{}); + defer tmp.cleanup(); + + // Create a locked file. + const test_file = try tmp.dir.createFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true }); + defer test_file.close(io); + + // Attempt to unlock the file via fs.lock with Lock.none. + try test_file.lock(io, .none); + + // Attempt to open the file now that it should be unlocked. + const test_file2 = try tmp.dir.openFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true }); + defer test_file2.close(io); + + // Make sure Lock.none works with tryLock as well. + try testing.expect(try test_file2.tryLock(io, .none)); + + // Attempt to open the file since it should be unlocked again. + const test_file3 = try tmp.dir.openFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true }); + test_file3.close(io); +} + test "walker" { const io = testing.io;