Commit | Line | Data |
---|---|---|
72b16652 GS |
1 | #!./perl |
2 | ||
3 | BEGIN { | |
4 | chdir 't' if -d 't'; | |
5 | unshift @INC, '../lib'; | |
d2a01882 GS |
6 | require Config; import Config; |
7 | if ($Config{'extensions'} !~ /\bFile\/Glob\b/i) { | |
8 | print "1..0\n"; | |
9 | exit 0; | |
10 | } | |
72b16652 GS |
11 | print "1..9\n"; |
12 | } | |
13 | END { | |
14 | print "not ok 1\n" unless $loaded; | |
15 | } | |
16 | use File::Glob ':glob'; | |
17 | $loaded = 1; | |
18 | print "ok 1\n"; | |
19 | ||
20 | sub array { | |
21 | return '(', join(", ", map {defined $_ ? "\"$_\"" : "undef"} @a), ")\n"; | |
22 | } | |
23 | ||
24 | # look for the contents of the current directory | |
25 | $ENV{PATH} = "/bin"; | |
26 | delete @ENV{BASH_ENV, CDPATH, ENV, IFS}; | |
27 | @correct = (); | |
28 | if (opendir(D, ".")) { | |
29 | @correct = grep { !/^\.\.?$/ } sort readdir(D); | |
30 | closedir D; | |
31 | } | |
32 | @a = File::Glob::glob("*", 0); | |
33 | @a = sort @a; | |
34 | if ("@a" ne "@correct" || GLOB_ERROR) { | |
35 | print "# |@a| ne |@correct|\nnot "; | |
36 | } | |
37 | print "ok 2\n"; | |
38 | ||
39 | # look up the user's home directory | |
40 | # should return a list with one item, and not set ERROR | |
f0963acb | 41 | if ($^O ne 'MSWin32' || $^O ne 'VMS') { |
0eb4ebd7 | 42 | eval { |
72b16652 | 43 | ($name, $home) = (getpwuid($>))[0,7]; |
0eb4ebd7 GS |
44 | 1; |
45 | } and do { | |
72b16652 GS |
46 | @a = File::Glob::glob("~$name", GLOB_TILDE); |
47 | if (scalar(@a) != 1 || $a[0] ne $home || GLOB_ERROR) { | |
48 | print "not "; | |
49 | } | |
0eb4ebd7 | 50 | }; |
72b16652 GS |
51 | } |
52 | print "ok 3\n"; | |
53 | ||
54 | # check backslashing | |
55 | # should return a list with one item, and not set ERROR | |
56 | @a = File::Glob::glob('TEST', GLOB_QUOTE); | |
57 | if (scalar @a != 1 || $a[0] ne 'TEST' || GLOB_ERROR) { | |
58 | local $/ = "]["; | |
59 | print "# [@a]\n"; | |
60 | print "not "; | |
61 | } | |
62 | print "ok 4\n"; | |
63 | ||
64 | # check nonexistent checks | |
65 | # should return an empty list | |
66 | # XXX since errfunc is NULL on win32, this test is not valid there | |
67 | @a = File::Glob::glob("asdfasdf", 0); | |
68 | if ($^O ne 'MSWin32' and scalar @a != 0) { | |
69 | print "# |@a|\nnot "; | |
70 | } | |
71 | print "ok 5\n"; | |
72 | ||
73 | # check bad protections | |
74 | # should return an empty list, and set ERROR | |
0a110db2 | 75 | if ($^O eq 'mpeix' or $^O eq 'MSWin32' or $^O eq 'os2' or $^O eq 'VMS' or $^O eq 'cygwin' or not $>) { |
1cf742e9 GS |
76 | print "ok 6 # skipped\n"; |
77 | } | |
78 | else { | |
79 | $dir = "PtEeRsLt.dir"; | |
80 | mkdir $dir, 0; | |
81 | @a = File::Glob::glob("$dir/*", GLOB_ERR); | |
82 | #print "\@a = ", array(@a); | |
83 | rmdir $dir; | |
84 | if (scalar(@a) != 0 || GLOB_ERROR == 0) { | |
85 | print "not "; | |
86 | } | |
87 | print "ok 6\n"; | |
72b16652 | 88 | } |
72b16652 GS |
89 | |
90 | # check for csh style globbing | |
91 | @a = File::Glob::glob('{a,b}', GLOB_BRACE | GLOB_NOMAGIC); | |
92 | unless (@a == 2 and $a[0] eq 'a' and $a[1] eq 'b') { | |
93 | print "not "; | |
94 | } | |
95 | print "ok 7\n"; | |
96 | ||
97 | @a = File::Glob::glob( | |
98 | '{TES*,doesntexist*,a,b}', | |
99 | GLOB_BRACE | GLOB_NOMAGIC | |
100 | ); | |
101 | unless (@a == 3 | |
f0963acb | 102 | and $a[0] eq ($^O eq 'VMS'? 'test.' : 'TEST') |
72b16652 GS |
103 | and $a[1] eq 'a' |
104 | and $a[2] eq 'b') | |
105 | { | |
106 | print "not "; | |
107 | } | |
108 | print "ok 8\n"; | |
109 | ||
110 | # "~" should expand to $ENV{HOME} | |
111 | $ENV{HOME} = "sweet home"; | |
112 | @a = File::Glob::glob('~', GLOB_TILDE | GLOB_NOMAGIC); | |
113 | unless (@a == 1 and $a[0] eq $ENV{HOME}) { | |
114 | print "not "; | |
115 | } | |
116 | print "ok 9\n"; |