Manual integration error in #12235.
[p5sagit/p5-mst-13.2.git] / lib / File / DosGlob.t
CommitLineData
fb73857a 1#!./perl
2
3#
4# test glob() in File::DosGlob
5#
6
7BEGIN {
8 chdir 't' if -d 't';
20822f61 9 @INC = '../lib';
fb73857a 10}
11
95d94a4f 12print "1..10\n";
fb73857a 13
14# override it in main::
15use File::DosGlob 'glob';
16
17# test if $_ takes as the default
be708cc0 18my $expected;
19if ($^O eq 'MacOS') {
0bad50db 20 $expected = $_ = ":op:a*.t";
be708cc0 21} else {
0bad50db 22 $expected = $_ = "op/a*.t";
be708cc0 23}
b695f709 24$_ = "op/a*.t";
fb73857a 25my @r = glob;
be708cc0 26print "not " if $_ ne $expected;
fb73857a 27print "ok 1\n";
b695f709 28print "# |@r|\nnot " if @r < 9;
fb73857a 29print "ok 2\n";
30
31# check if <*/*> works
be708cc0 32if ($^O eq 'MacOS') {
33 @r = <:*:a*.t>;
34} else {
35 @r = <*/a*.t>;
36}
fb73857a 37# atleast {argv,abbrev,anydbm,autoloader,append,arith,array,assignwarn,auto}.t
be708cc0 38print "# |@r|\nnot " if @r < 9;
fb73857a 39print "ok 3\n";
40my $r = scalar @r;
41
42# check if scalar context works
43@r = ();
be708cc0 44while (defined($_ = ($^O eq 'MacOS') ? <:*:a*.t> : <*/a*.t>)) {
fb73857a 45 print "# $_\n";
46 push @r, $_;
47}
48print "not " if @r != $r;
49print "ok 4\n";
50
91e74348 51# check if list context works
fb73857a 52@r = ();
be708cc0 53if ($^O eq 'MacOS') {
54 for (<:*:a*.t>) {
55 print "# $_\n";
56 push @r, $_;
57 }
58} else {
59 for (<*/a*.t>) {
60 print "# $_\n";
61 push @r, $_;
62 }
fb73857a 63}
64print "not " if @r != $r;
65print "ok 5\n";
66
67# test if implicit assign to $_ in while() works
68@r = ();
be708cc0 69if ($^O eq 'MacOS') {
70 while (<:*:a*.t>) {
71 print "# $_\n";
72 push @r, $_;
73 }
74} else {
75 while (<*/a*.t>) {
76 print "# $_\n";
77 push @r, $_;
78 }
fb73857a 79}
80print "not " if @r != $r;
81print "ok 6\n";
82
83# test if explicit glob() gets assign magic too
84my @s = ();
be708cc0 85my $pat = ($^O eq 'MacOS') ? ':*:a*.t': '*/a*.t';
86while (glob ($pat)) {
fb73857a 87 print "# $_\n";
88 push @s, $_;
89}
90print "not " if "@r" ne "@s";
91print "ok 7\n";
92
93# how about in a different package, like?
94package Foo;
95use File::DosGlob 'glob';
96@s = ();
97while (glob '*/a*.t') {
98 print "# $_\n";
99 push @s, $_;
100}
101print "not " if "@r" ne "@s";
102print "ok 8\n";
103
104# test if different glob ops maintain independent contexts
105@s = ();
106while (<*/a*.t>) {
107 my $i = 0;
108 print "# $_ <";
109 push @s, $_;
110 while (<*/b*.t>) {
111 print " $_";
112 $i++;
113 }
114 print " >\n";
115}
116print "not " if "@r" ne "@s";
117print "ok 9\n";
118
95d94a4f 119# how about a global override, hm?
120eval <<'EOT';
121use File::DosGlob 'GLOBAL_glob';
122package Bar;
123@s = ();
124while (<*/a*.t>) {
125 my $i = 0;
126 print "# $_ <";
127 push @s, $_;
128 while (glob '*/b*.t') {
129 print " $_";
130 $i++;
131 }
132 print " >\n";
133}
134print "not " if "@r" ne "@s";
135print "ok 10\n";
136EOT