4 # test glob() in File::DosGlob
12 use Test::More tests => 20;
14 # override it in main::
15 use File::DosGlob 'glob';
20 $expected = $_ = "op/a*.t";
22 is ($_, $expected, 'test if $_ takes as the default');
23 cmp_ok(@r, '>=', 9) or diag("|@r|");
26 # atleast {argv,abbrev,anydbm,autoloader,append,arith,array,assignwarn,auto}.t
27 cmp_ok(@r, '>=', 9, 'check <*/*>') or diag("|@r|");
31 while (defined($_ = <*/a*.t>)) {
35 is(scalar @r, $r, 'check scalar context');
42 is(scalar @r, $r, 'check list context');
49 is(scalar @r, $r, 'implicit assign to $_ in while()');
57 is("@r", "@s", 'explicit glob() gets assign magic too');
60 use File::DosGlob 'glob';
68 is("@r", "@s", 'in a different package');
81 is("@r", "@s", 'different glob ops maintain independent contexts');
85 use File::DosGlob 'GLOBAL_glob';
91 while (glob '*/b*.t') {
98 is("@r", "@s", 'global override');
100 # Test that a glob pattern containing ()'s works.
101 # NB. The spaces in the glob patterns need to be backslash escaped.
102 my $filename_containing_parens = "foo (123) bar";
104 skip("can't create '$filename_containing_parens': $!", 9)
105 unless open my $touch, ">", $filename_containing_parens;
108 foreach my $pattern ("foo\\ (*", "*)\\ bar", "foo\\ (1*3)\\ bar") {
110 eval { @r = File::DosGlob::glob($pattern) };
111 is($@, "", "eval for glob($pattern)");
113 is($r[0], $filename_containing_parens);
116 1 while unlink $filename_containing_parens;
119 # Test the globbing of a drive relative pattern such as "c:*.pl".
120 # NB. previous versions of DosGlob inserted "./ after the drive letter to
121 # make the expansion process work correctly. However, while it is harmless,
122 # there is no reason for it to be in the result.
123 my $cwd = Cwd::cwd();
124 if ($cwd =~ /^([a-zA-Z]:)/) {
127 # This assumes we're in the "t" directory.
128 eval { @r = File::DosGlob::glob("${drive}io/*.t") };
129 ok(@r and !grep !m|^${drive}io/[^/]*\.t$|, @r);