Skip to content

Commit 8327a6c

Browse files
authored
Merge pull request #127 from JohnTitor/harden-test-symlink
2 parents 4ab7f0f + 7aaff21 commit 8327a6c

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
}
@@ -52,6 +65,10 @@ fn main() {
5265
mk_file("bbb", true);
5366
mk_file("bbb/specials", true);
5467
mk_file("bbb/specials/!", false);
68+
// a valid symlink
69+
mk_symlink_file("aaa/apple", "aaa/green_apple");
70+
// a broken symlink
71+
mk_symlink_file("aaa/setsuna", "aaa/kazusa");
5572

5673
// windows does not allow `*` or `?` characters to exist in filenames
5774
if env::consts::FAMILY != "windows" {
@@ -246,15 +263,19 @@ fn main() {
246263
glob_vec("aaa/*"),
247264
vec!(
248265
PathBuf::from("aaa/apple"),
266+
PathBuf::from("aaa/green_apple"),
267+
PathBuf::from("aaa/kazusa"),
249268
PathBuf::from("aaa/orange"),
250-
PathBuf::from("aaa/tomato")
269+
PathBuf::from("aaa/tomato"),
251270
)
252271
);
253272

254273
assert_eq!(
255274
glob_vec("aaa/*a*"),
256275
vec!(
257276
PathBuf::from("aaa/apple"),
277+
PathBuf::from("aaa/green_apple"),
278+
PathBuf::from("aaa/kazusa"),
258279
PathBuf::from("aaa/orange"),
259280
PathBuf::from("aaa/tomato")
260281
)
@@ -285,6 +306,9 @@ fn main() {
285306

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

309+
// Ensure to find a broken symlink.
310+
assert_eq!(glob_vec("aaa/kazusa"), vec!(PathBuf::from("aaa/kazusa")));
311+
288312
assert_eq!(glob_vec("aa[a]"), vec!(PathBuf::from("aaa")));
289313
assert_eq!(glob_vec("aa[abc]"), vec!(PathBuf::from("aaa")));
290314
assert_eq!(glob_vec("a[bca]a"), vec!(PathBuf::from("aaa")));

0 commit comments

Comments
 (0)