4 # test glob() in File::DosGlob
7 # Make sure it can load before other XS extensions
11 use File::Spec::Functions;
13 chdir catdir $FindBin::Bin, (updir)x3, 't';
17 use Test::More tests => 21;
19 # override it in main::
20 use File::DosGlob 'glob';
25 $expected = $_ = "op/a*.t";
27 is ($_, $expected, 'test if $_ takes as the default');
28 cmp_ok(@r, '>=', 9) or diag("|@r|");
31 # atleast {argv,abbrev,anydbm,autoloader,append,arith,array,assignwarn,auto}.t
32 cmp_ok(@r, '>=', 9, 'check <*/*>') or diag("|@r|");
36 while (defined($_ = <*/a*.t>)) {
40 is(scalar @r, $r, 'check scalar context');
47 is(scalar @r, $r, 'check list context');
54 is(scalar @r, $r, 'implicit assign to $_ in while()');
62 is("@r", "@s", 'explicit glob() gets assign magic too');
65 use File::DosGlob 'glob';
73 is("@r", "@s", 'in a different package');
86 is("@r", "@s", 'different glob ops maintain independent contexts');
90 use File::DosGlob 'GLOBAL_glob';
96 while (glob '*/b*.t') {
103 is("@r", "@s", 'global override');
105 # Test that a glob pattern containing ()'s works.
106 # NB. The spaces in the glob patterns need to be backslash escaped.
107 my $filename_containing_parens = "foo (123) bar";
109 skip("can't create '$filename_containing_parens': $!", 9)
110 unless open my $touch, ">", $filename_containing_parens;
113 foreach my $pattern ("foo\\ (*", "*)\\ bar", "foo\\ (1*3)\\ bar") {
115 eval { @r = File::DosGlob::glob($pattern) };
116 is($@, "", "eval for glob($pattern)");
118 is($r[0], $filename_containing_parens);
121 1 while unlink $filename_containing_parens;
124 # Test the globbing of a drive relative pattern such as "c:*.pl".
125 # NB. previous versions of DosGlob inserted "./ after the drive letter to
126 # make the expansion process work correctly. However, while it is harmless,
127 # there is no reason for it to be in the result.
128 my $cwd = Cwd::cwd();
129 if ($cwd =~ /^([a-zA-Z]:)/) {
132 # This assumes we're in the "t" directory.
133 eval { @r = File::DosGlob::glob("${drive}io/*.t") };
134 ok(@r and !grep !m|^${drive}io/[^/]*\.t$|, @r);
139 # Test that our internal data are freed when the caller’s op tree is freed,
140 # even if iteration has not finished.
141 # Using XS::APItest is the only simple way to test this. Since this is a
142 # core-only module, this should be OK.
145 skip "no XS::APItest"
146 unless eval { require XS::APItest; import XS::APItest "sv_count"; 1 };
147 # Use a random number of ops, so that the glob op does not reuse the
148 # same address each time, giving us false passes.
150 eval '$x+'x(1+rand() * 100) . '<*>';
152 eval '$x+'x(1+rand() * 100) . '<*>';
153 $count2 = sv_count();
154 is $count2, $count, 'no leak when partly iterated caller is freed';