diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index c953b529fa18..15c8307f586c 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -1434,3 +1434,18 @@ test "delete a read-only file on windows" { file.close(); try tmp.dir.deleteFile("test_file"); } + +test "delete a setAsCwd directory on Windows" { + if (builtin.os.tag != .windows) return error.SkipZigTest; + + var tmp = tmpDir(.{}); + // Set tmp dir as current working directory. + try tmp.dir.setAsCwd(); + tmp.dir.close(); + try testing.expectError(error.FileBusy, tmp.parent_dir.deleteTree(&tmp.sub_path)); + // Now set the parent dir as the current working dir for clean up. + try tmp.parent_dir.setAsCwd(); + try tmp.parent_dir.deleteTree(&tmp.sub_path); + // Close the parent "tmp" so we don't leak the HANDLE. + tmp.parent_dir.close(); +} diff --git a/test/standalone/windows_spawn/main.zig b/test/standalone/windows_spawn/main.zig index eb60236587c6..1706a5a8497c 100644 --- a/test/standalone/windows_spawn/main.zig +++ b/test/standalone/windows_spawn/main.zig @@ -116,6 +116,7 @@ pub fn main() anyerror!void { // Now let's set the tmp dir as the cwd and set the path only include the "something" sub dir try tmp.dir.setAsCwd(); + defer tmp.parent_dir.setAsCwd() catch {}; const something_subdir_abs_path = try std.mem.concatWithSentinel(allocator, u16, &.{ tmp_absolute_path_w, utf16Literal("\\something") }, 0); defer allocator.free(something_subdir_abs_path);