diff options
| author | Benjamin Herr <ben@0x539.de> | 2014-04-07 14:47:04 +0200 |
|---|---|---|
| committer | Benjamin Herr <ben@0x539.de> | 2014-04-08 01:21:28 +0200 |
| commit | 4051bd900abbb47557dd8928532eedbc2bca0563 (patch) | |
| tree | d9b598f7054e3b24a27e4d24573c837c10143e45 /src/test | |
| parent | f1f50565a1fda0dfd60d89fea65e2328f42cc5e0 (diff) | |
libglob: allow "." and ".." to be matched
... also don't read the whole directory if the glob for that path component doesn't contain any metacharacters. Patterns like `../*.jpg` will work now, and `.*` will match both `.` and `..` to be consistent with shell expansion. As before: Just `*` still won't match `.` and `..`, while it will still match dotfiles like `.git` by default.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/run-pass/glob-std.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/test/run-pass/glob-std.rs b/src/test/run-pass/glob-std.rs index 0a12731fb46..eec6d675295 100644 --- a/src/test/run-pass/glob-std.rs +++ b/src/test/run-pass/glob-std.rs @@ -11,13 +11,12 @@ // ignore-fast check-fast doesn't like 'extern crate extra' // ignore-win32 TempDir may cause IoError on windows: #10462 -#[feature(macro_rules)]; +#![feature(macro_rules)] extern crate glob; use glob::glob; -use std::unstable::finally::Finally; -use std::{os, unstable}; +use std::os; use std::io; use std::io::TempDir; @@ -30,9 +29,9 @@ macro_rules! assert_eq ( ($e1:expr, $e2:expr) => ( pub fn main() { fn mk_file(path: &str, directory: bool) { if directory { - io::fs::mkdir(&Path::new(path), io::UserRWX); + io::fs::mkdir(&Path::new(path), io::UserRWX).unwrap(); } else { - io::File::create(&Path::new(path)); + io::File::create(&Path::new(path)).unwrap(); } } @@ -73,8 +72,8 @@ pub fn main() { mk_file("xyz/z", false); assert_eq!(glob_vec(""), Vec::new()); - assert_eq!(glob_vec("."), Vec::new()); - assert_eq!(glob_vec(".."), Vec::new()); + assert_eq!(glob_vec("."), vec!(os::getcwd())); + assert_eq!(glob_vec(".."), vec!(os::getcwd().join(".."))); assert_eq!(glob_vec("aaa"), vec!(abs_path("aaa"))); assert_eq!(glob_vec("aaa/"), vec!(abs_path("aaa"))); @@ -132,6 +131,13 @@ pub fn main() { abs_path("aaa/tomato/tomato.txt"), abs_path("aaa/tomato/tomoto.txt"))); + assert_eq!(glob_vec("./aaa"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("./*"), glob_vec("*")); + assert_eq!(glob_vec("*/..").pop().unwrap(), abs_path(".")); + assert_eq!(glob_vec("aaa/../bbb"), vec!(abs_path("bbb"))); + assert_eq!(glob_vec("nonexistent/../bbb"), Vec::new()); + assert_eq!(glob_vec("aaa/tomato/tomato.txt/.."), Vec::new()); + assert_eq!(glob_vec("aa[a]"), vec!(abs_path("aaa"))); assert_eq!(glob_vec("aa[abc]"), vec!(abs_path("aaa"))); assert_eq!(glob_vec("a[bca]a"), vec!(abs_path("aaa"))); |
