Skip to content

test: Fix windows_spawn tmp directory cleanup #15471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/std/fs/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 1 addition & 0 deletions test/standalone/windows_spawn/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down