Skip to content

Commit d8d7cde

Browse files
committed
test
1 parent dfab6f9 commit d8d7cde

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

tests/windows-open.rs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ fn windows_open_one() {
1818

1919
let dir = tmpdir.open_dir("aaa");
2020

21+
// Attempts to remove or rename the open directory should fail.
2122
tmpdir.remove_dir("aaa").unwrap_err();
2223
tmpdir.rename("aaa", &tmpdir, "zzz").unwrap_err();
2324

2425
drop(dir);
26+
27+
// Now that we've droped the handle, the same operations should succeed.
28+
check!(tmpdir.rename("aaa", &tmpdir, "xxx"));
29+
check!(tmpdir.remove_dir("xxx"));
2530
}
2631

2732
#[test]
@@ -32,10 +37,58 @@ fn windows_open_multiple() {
3237

3338
let dir = tmpdir.open_dir("aaa/bbb");
3439

40+
// Attempts to remove or rename any component of the open directory should fail.
3541
tmpdir.remove_dir("aaa/bbb").unwrap_err();
3642
tmpdir.remove_dir("aaa").unwrap_err();
37-
tmpdir.rename("aaa/bbb", &tmpdir, "aaa/zzz").unwrap_err();
43+
tmpdir.rename("aaa/bbb", &tmpdir, "aaa/yyy").unwrap_err();
3844
tmpdir.rename("aaa", &tmpdir, "zzz").unwrap_err();
3945

4046
drop(dir);
47+
48+
// Now that we've droped the handle, the same operations should succeed.
49+
check!(tmpdir.rename("aaa/bbb", &tmpdir, "aaa/www"));
50+
check!(tmpdir.rename("aaa", &tmpdir, "xxx"));
51+
check!(tmpdir.remove_dir("xxx/www"));
52+
check!(tmpdir.remove_dir("xxx"));
53+
}
54+
55+
/// Like `windows_open_multiple`, but does so within a directory that we
56+
/// can close and then independently mutate.
57+
#[test]
58+
#[cfg(windows)]
59+
fn windows_open_tricky() {
60+
let tmpdir = tmpdir();
61+
check!(tmpdir.create_dir("qqq"));
62+
63+
let qqq = check!(tmpdir.open_dir("qqq"));
64+
check!(qqq.create_dir_all("aaa/bbb"));
65+
66+
let dir = check!(qqq.open_dir("aaa/bbb"));
67+
68+
// Now drop `qqq`.
69+
drop(qqq);
70+
71+
// Attempts to remove or rename any component of the open directory should fail.
72+
dir.remove_dir("aaa/bbb").unwrap_err();
73+
dir.remove_dir("aaa").unwrap_err();
74+
dir.rename("aaa/bbb", &tmpdir, "aaa/yyy").unwrap_err();
75+
dir.rename("aaa", &tmpdir, "zzz").unwrap_err();
76+
tmpdir.remove_dir("qqq/aaa/bbb").unwrap_err();
77+
tmpdir.remove_dir("qqq/aaa").unwrap_err();
78+
tmpdir.remove_dir("qqq").unwrap_err();
79+
tmpdir
80+
.rename("qqq/aaa/bbb", &tmpdir, "qqq/aaa/yyy")
81+
.unwrap_err();
82+
tmpdir.rename("qqq/aaa", &tmpdir, "qqq/zzz").unwrap_err();
83+
tmpdir.rename("qqq", &tmpdir, "vvv").unwrap_err();
84+
85+
drop(dir);
86+
87+
// Now that we've droped the handle, the same operations should succeed.
88+
check!(tmpdir.rename("qqq/aaa/bbb", &tmpdir, "qqq/aaa/www"));
89+
check!(tmpdir.rename("qqq/aaa", &tmpdir, "qqq/xxx"));
90+
check!(tmpdir.rename("qqq", &tmpdir, "uuu"));
91+
check!(tmpdir.remove_dir("uuu/xxx/www"));
92+
check!(tmpdir.remove_dir("uuu/xxx"));
93+
check!(tmpdir.remove_dir("uuu"));
4194
}

0 commit comments

Comments
 (0)