Skip to content

Commit 7aaff21

Browse files
committed
Harden tests for symlink
This ensures the changes in #105. Signed-off-by: Yuki Okushi <jtitor@2k36.org>
1 parent 949a5b0 commit 7aaff21

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/glob-std.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ fn main() {
3131
}
3232
}
3333

34+
fn mk_symlink_file(original: &str, link: &str) {
35+
#[cfg(unix)]
36+
{
37+
use std::os::unix::fs::symlink;
38+
symlink(original, link).unwrap();
39+
}
40+
#[cfg(windows)]
41+
{
42+
use std::os::windows::fs::symlink_file;
43+
symlink_file(original, link).unwrap();
44+
}
45+
}
46+
3447
fn glob_vec(pattern: &str) -> Vec<PathBuf> {
3548
glob(pattern).unwrap().map(|r| r.unwrap()).collect()
3649
}
@@ -48,6 +61,10 @@ fn main() {
4861
mk_file("bbb", true);
4962
mk_file("bbb/specials", true);
5063
mk_file("bbb/specials/!", false);
64+
// a valid symlink
65+
mk_symlink_file("aaa/apple", "aaa/green_apple");
66+
// a broken symlink
67+
mk_symlink_file("aaa/setsuna", "aaa/kazusa");
5168

5269
// windows does not allow `*` or `?` characters to exist in filenames
5370
if env::consts::FAMILY != "windows" {
@@ -223,15 +240,19 @@ fn main() {
223240
glob_vec("aaa/*"),
224241
vec!(
225242
PathBuf::from("aaa/apple"),
243+
PathBuf::from("aaa/green_apple"),
244+
PathBuf::from("aaa/kazusa"),
226245
PathBuf::from("aaa/orange"),
227-
PathBuf::from("aaa/tomato")
246+
PathBuf::from("aaa/tomato"),
228247
)
229248
);
230249

231250
assert_eq!(
232251
glob_vec("aaa/*a*"),
233252
vec!(
234253
PathBuf::from("aaa/apple"),
254+
PathBuf::from("aaa/green_apple"),
255+
PathBuf::from("aaa/kazusa"),
235256
PathBuf::from("aaa/orange"),
236257
PathBuf::from("aaa/tomato")
237258
)
@@ -262,6 +283,9 @@ fn main() {
262283

263284
assert_eq!(glob_vec("aaa/tomato/tomato.txt/"), Vec::<PathBuf>::new());
264285

286+
// Ensure to find a broken symlink.
287+
assert_eq!(glob_vec("aaa/kazusa"), vec!(PathBuf::from("aaa/kazusa")));
288+
265289
assert_eq!(glob_vec("aa[a]"), vec!(PathBuf::from("aaa")));
266290
assert_eq!(glob_vec("aa[abc]"), vec!(PathBuf::from("aaa")));
267291
assert_eq!(glob_vec("a[bca]a"), vec!(PathBuf::from("aaa")));

0 commit comments

Comments
 (0)