@@ -556,194 +556,6 @@ mod test {
556
556
use super::*;
557
557
use tempfile;
558
558
559
- #[test]
560
- fn test_relative_pattern() {
561
-
562
- fn change_then_remove(p: &Path, f: &fn()) {
563
- do (|| {
564
- unstable::change_dir_locked(p, || f());
565
- }).finally {
566
- os::remove_dir_recursive(p);
567
- }
568
- }
569
-
570
- fn mk_file(path: &str, directory: bool) {
571
- if directory {
572
- os::make_dir(&Path(path), 0xFFFF);
573
- } else {
574
- io::mk_file_writer(&Path(path), [io::Create]);
575
- }
576
- }
577
-
578
- fn abs_path(path: &str) -> Path {
579
- os::getcwd().push_many(Path(path).components)
580
- }
581
-
582
- fn glob_vec(pattern: &str) -> ~[Path] {
583
- glob(pattern).collect()
584
- }
585
-
586
- let root = tempfile::mkdtemp(&os::tmpdir(), "glob-tests");
587
- let root = root.expect("Should have created a temp directory");
588
-
589
- do change_then_remove(&root) {
590
-
591
- mk_file("aaa", true);
592
- mk_file("aaa/apple", true);
593
- mk_file("aaa/orange", true);
594
- mk_file("aaa/tomato", true);
595
- mk_file("aaa/tomato/tomato.txt", false);
596
- mk_file("aaa/tomato/tomoto.txt", false);
597
- mk_file("bbb", true);
598
- mk_file("bbb/specials", true);
599
- mk_file("bbb/specials/!", false);
600
-
601
- // windows does not allow `*` or `?` characters to exist in filenames
602
- if os::consts::FAMILY != os::consts::windows::FAMILY {
603
- mk_file("bbb/specials/*", false);
604
- mk_file("bbb/specials/?", false);
605
- }
606
-
607
- mk_file("bbb/specials/[", false);
608
- mk_file("bbb/specials/]", false);
609
- mk_file("ccc", true);
610
- mk_file("xyz", true);
611
- mk_file("xyz/x", false);
612
- mk_file("xyz/y", false);
613
- mk_file("xyz/z", false);
614
-
615
- assert_eq!(glob_vec(""), ~[]);
616
- assert_eq!(glob_vec("."), ~[]);
617
- assert_eq!(glob_vec(".."), ~[]);
618
-
619
- assert_eq!(glob_vec("aaa"), ~[abs_path("aaa")]);
620
- assert_eq!(glob_vec("aaa/"), ~[abs_path("aaa")]);
621
- assert_eq!(glob_vec("a"), ~[]);
622
- assert_eq!(glob_vec("aa"), ~[]);
623
- assert_eq!(glob_vec("aaaa"), ~[]);
624
-
625
- assert_eq!(glob_vec("aaa/apple"), ~[abs_path("aaa/apple")]);
626
- assert_eq!(glob_vec("aaa/apple/nope"), ~[]);
627
-
628
- // windows should support both / and \ as directory separators
629
- if os::consts::FAMILY == os::consts::windows::FAMILY {
630
- assert_eq!(glob_vec("aaa\\apple"), ~[abs_path("aaa/apple")]);
631
- }
632
-
633
- assert_eq!(glob_vec("???/"), ~[
634
- abs_path("aaa"),
635
- abs_path("bbb"),
636
- abs_path("ccc"),
637
- abs_path("xyz")]);
638
-
639
- assert_eq!(glob_vec("aaa/tomato/tom?to.txt"), ~[
640
- abs_path("aaa/tomato/tomato.txt"),
641
- abs_path("aaa/tomato/tomoto.txt")]);
642
-
643
- assert_eq!(glob_vec("xyz/?"), ~[
644
- abs_path("xyz/x"),
645
- abs_path("xyz/y"),
646
- abs_path("xyz/z")]);
647
-
648
- assert_eq!(glob_vec("a*"), ~[abs_path("aaa")]);
649
- assert_eq!(glob_vec("*a*"), ~[abs_path("aaa")]);
650
- assert_eq!(glob_vec("a*a"), ~[abs_path("aaa")]);
651
- assert_eq!(glob_vec("aaa*"), ~[abs_path("aaa")]);
652
- assert_eq!(glob_vec("*aaa"), ~[abs_path("aaa")]);
653
- assert_eq!(glob_vec("*aaa*"), ~[abs_path("aaa")]);
654
- assert_eq!(glob_vec("*a*a*a*"), ~[abs_path("aaa")]);
655
- assert_eq!(glob_vec("aaa*/"), ~[abs_path("aaa")]);
656
-
657
- assert_eq!(glob_vec("aaa/*"), ~[
658
- abs_path("aaa/apple"),
659
- abs_path("aaa/orange"),
660
- abs_path("aaa/tomato")]);
661
-
662
- assert_eq!(glob_vec("aaa/*a*"), ~[
663
- abs_path("aaa/apple"),
664
- abs_path("aaa/orange"),
665
- abs_path("aaa/tomato")]);
666
-
667
- assert_eq!(glob_vec("*/*/*.txt"), ~[
668
- abs_path("aaa/tomato/tomato.txt"),
669
- abs_path("aaa/tomato/tomoto.txt")]);
670
-
671
- assert_eq!(glob_vec("*/ * /t[ aob] m?to[ . ] t[ !y] t") , ~[
672
- abs_path ( "aaa/tomato/tomato.txt" ) ,
673
- abs_path ( "aaa/tomato/tomoto.txt" ) ] ) ;
674
-
675
- assert_eq ! ( glob_vec( "aa[a]" ) , ~[ abs_path( "aaa" ) ] ) ;
676
- assert_eq ! ( glob_vec( "aa[abc]" ) , ~[ abs_path( "aaa" ) ] ) ;
677
- assert_eq ! ( glob_vec( "a[bca]a" ) , ~[ abs_path( "aaa" ) ] ) ;
678
- assert_eq ! ( glob_vec( "aa[b]" ) , ~[ ] ) ;
679
- assert_eq ! ( glob_vec( "aa[xyz]" ) , ~[ ] ) ;
680
- assert_eq ! ( glob_vec( "aa[]]" ) , ~[ ] ) ;
681
-
682
- assert_eq ! ( glob_vec( "aa[!b]" ) , ~[ abs_path( "aaa" ) ] ) ;
683
- assert_eq ! ( glob_vec( "aa[!bcd]" ) , ~[ abs_path( "aaa" ) ] ) ;
684
- assert_eq ! ( glob_vec( "a[!bcd]a" ) , ~[ abs_path( "aaa" ) ] ) ;
685
- assert_eq ! ( glob_vec( "aa[!a]" ) , ~[ ] ) ;
686
- assert_eq ! ( glob_vec( "aa[!abc]" ) , ~[ ] ) ;
687
-
688
- assert_eq ! ( glob_vec( "bbb/specials/[[]" ) , ~[ abs_path( "bbb/specials/[" ) ] ) ;
689
- assert_eq ! ( glob_vec( "bbb/specials/!" ) , ~[ abs_path( "bbb/specials/!" ) ] ) ;
690
- assert_eq ! ( glob_vec( "bbb/specials/[]]" ) , ~[ abs_path( "bbb/specials/]" ) ] ) ;
691
-
692
- if os:: consts:: FAMILY != os:: consts:: windows:: FAMILY {
693
- assert_eq ! ( glob_vec( "bbb/specials/[*]" ) , ~[ abs_path( "bbb/specials/*" ) ] ) ;
694
- assert_eq ! ( glob_vec( "bbb/specials/[?]" ) , ~[ abs_path( "bbb/specials/?" ) ] ) ;
695
- }
696
-
697
- if os:: consts:: FAMILY == os:: consts:: windows:: FAMILY {
698
-
699
- assert_eq ! ( glob_vec( "bbb/specials/[![]" ) , ~[
700
- abs_path( "bbb/specials/!" ) ,
701
- abs_path( "bbb/specials/]" ) ] ) ;
702
-
703
- assert_eq ! ( glob_vec( "bbb/specials/[!]]" ) , ~[
704
- abs_path( "bbb/specials/!" ) ,
705
- abs_path( "bbb/specials/[" ) ] ) ;
706
-
707
- assert_eq ! ( glob_vec( "bbb/specials/[!!]" ) , ~[
708
- abs_path( "bbb/specials/[" ) ,
709
- abs_path( "bbb/specials/]" ) ] ) ;
710
-
711
- } else {
712
-
713
- assert_eq ! ( glob_vec( "bbb/specials/[![]" ) , ~[
714
- abs_path( "bbb/specials/!" ) ,
715
- abs_path( "bbb/specials/*" ) ,
716
- abs_path( "bbb/specials/?" ) ,
717
- abs_path( "bbb/specials/]" ) ] ) ;
718
-
719
- assert_eq ! ( glob_vec( "bbb/specials/[!]]" ) , ~[
720
- abs_path( "bbb/specials/!" ) ,
721
- abs_path( "bbb/specials/*" ) ,
722
- abs_path( "bbb/specials/?" ) ,
723
- abs_path( "bbb/specials/[" ) ] ) ;
724
-
725
- assert_eq ! ( glob_vec( "bbb/specials/[!!]" ) , ~[
726
- abs_path( "bbb/specials/*" ) ,
727
- abs_path( "bbb/specials/?" ) ,
728
- abs_path( "bbb/specials/[" ) ,
729
- abs_path( "bbb/specials/]" ) ] ) ;
730
-
731
- assert_eq ! ( glob_vec( "bbb/specials/[!*]" ) , ~[
732
- abs_path( "bbb/specials/!" ) ,
733
- abs_path( "bbb/specials/?" ) ,
734
- abs_path( "bbb/specials/[" ) ,
735
- abs_path( "bbb/specials/]" ) ] ) ;
736
-
737
- assert_eq ! ( glob_vec( "bbb/specials/[!?]" ) , ~[
738
- abs_path( "bbb/specials/!" ) ,
739
- abs_path( "bbb/specials/*" ) ,
740
- abs_path( "bbb/specials/[" ) ,
741
- abs_path( "bbb/specials/]" ) ] ) ;
742
-
743
- }
744
- } ;
745
- }
746
-
747
559
#[test]
748
560
fn test_absolute_pattern() {
749
561
// assume that the filesystem is not empty!
0 commit comments