4 # test glob() in File::DosGlob
14 # override it in main::
15 use File::DosGlob 'glob';
19 # test if $_ takes as the default
22 $expected = $_ = ":op:a*.t";
24 $expected = $_ = "op/a*.t";
27 print "not " if $_ ne $expected;
29 print "# |@r|\nnot " if @r < 9;
32 # check if <*/*> works
38 # atleast {argv,abbrev,anydbm,autoloader,append,arith,array,assignwarn,auto}.t
39 print "# |@r|\nnot " if @r < 9;
43 # check if scalar context works
45 while (defined($_ = ($^O eq 'MacOS') ? <:*:a*.t> : <*/a*.t>)) {
49 print "not " if @r != $r;
52 # check if list context works
65 print "not " if @r != $r;
68 # test if implicit assign to $_ in while() works
81 print "not " if @r != $r;
84 # test if explicit glob() gets assign magic too
86 my $pat = ($^O eq 'MacOS') ? ':*:a*.t': '*/a*.t';
91 print "not " if "@r" ne "@s";
94 # how about in a different package, like?
96 use File::DosGlob 'glob';
98 $pat = $^O eq 'MacOS' ? ':*:a*.t' : '*/a*.t';
103 print "not " if "@r" ne "@s";
106 # test if different glob ops maintain independent contexts
108 if ($^O eq 'MacOS') {
131 print "not " if "@r" ne "@s";
134 # how about a global override, hm?
136 use File::DosGlob 'GLOBAL_glob';
139 if ($^O eq 'MacOS') {
144 while (glob ':*:b*.t') {
155 while (glob '*/b*.t') {
162 print "not " if "@r" ne "@s";
166 # Test that a glob pattern containing ()'s works.
167 # NB. The spaces in the glob patterns need to be backslash escaped.
168 my $filename_containing_parens = "foo (123) bar";
169 if (open(TOUCH, ">", $filename_containing_parens)) {
173 eval { @r = File::DosGlob::glob("foo\\ (*") };
174 print +($@ ? "not " : ""), "ok 11\n";
175 print "not " unless (@r == 1 and $r[0] eq $filename_containing_parens);
179 eval { @r = File::DosGlob::glob("*)\\ bar") };
180 print +($@ ? "not " : ""), "ok 13\n";
181 print "not " unless (@r == 1 and $r[0] eq $filename_containing_parens);
185 eval { @r = File::DosGlob::glob("foo\\ (1*3)\\ bar") };
186 print +($@ ? "not " : ""), "ok 15\n";
187 print "not " unless (@r == 1 and $r[0] eq $filename_containing_parens);
190 1 while unlink $filename_containing_parens;
194 print "ok $_ # skip - can't create '$filename_containing_parens': $!\n";
198 # Test the globbing of a drive relative pattern such as "c:*.pl".
199 # NB. previous versions of DosGlob inserted "./ after the drive letter to
200 # make the expansion process work correctly. However, while it is harmless,
201 # there is no reason for it to be in the result.
202 my $cwd = Cwd::cwd();
203 if ($cwd =~ /^([a-zA-Z]:)/) {
206 # This assumes we're in the "t" directory.
207 eval { @r = File::DosGlob::glob("${drive}io/*.t") };
208 print +((@r and !grep !m|^${drive}io/[^/]*\.t$|, @r) ? "" : "not "), "ok 17\n";