Skip to content

Commit 3c21e22

Browse files
add test for Lock.none on Windows
1 parent 0ce8a01 commit 3c21e22

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/std/fs/test.zig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,31 @@ test "delete a setAsCwd directory on Windows" {
19691969
tmp.parent_dir.close();
19701970
}
19711971

1972+
test "use Lock.none on Windows" {
1973+
if (native_os != .windows) return error.SkipZigTest;
1974+
1975+
var tmp = tmpDir(.{});
1976+
defer tmp.cleanup();
1977+
1978+
// Create a locked file.
1979+
const test_file = try tmp.dir.createFile("test_file", .{ .lock = .exclusive, .lock_nonblocking = true });
1980+
defer test_file.close();
1981+
1982+
// Attempt to unlock the file via fs.lock with Lock.none.
1983+
try File.lock(test_file, .none);
1984+
1985+
// Attempt to open the file now that it should be unlocked.
1986+
const test_file2 = try tmp.dir.openFile("test_file", .{ .lock = .exclusive, .lock_nonblocking = true });
1987+
defer test_file2.close();
1988+
1989+
// Make sure Lock.none works with tryLock as well.
1990+
try testing.expect(try File.tryLock(test_file2, .none));
1991+
1992+
// Attempt to open the file since it should be unlocked again.
1993+
const test_file3 = try tmp.dir.openFile("test_file", .{});
1994+
test_file3.close();
1995+
}
1996+
19721997
test "invalid UTF-8/WTF-8 paths" {
19731998
const expected_err = switch (native_os) {
19741999
.wasi => error.InvalidUtf8,

0 commit comments

Comments
 (0)