This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Convert all File::Glob tests to Test::More.
[perl5.git] / ext / File-Glob / t / global.t
CommitLineData
72b16652
GS
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
1d89eaef 5 @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}
12
92361f5e
NC
13use Test::More tests => 11;
14
72b16652
GS
15BEGIN {
16 *CORE::GLOBAL::glob = sub { "Just another Perl hacker," };
17}
18
19BEGIN {
20 if ("Just another Perl hacker," ne (<*>)[0]) {
21 die <<EOMessage;
22Your version of perl ($]) doesn't seem to allow extensions to override
23the core glob operator.
24EOMessage
25 }
26}
27
92361f5e
NC
28BEGIN {
29 use_ok('File::Glob', ':globally');
30}
72b16652 31
1d89eaef 32$_ = "op/*.t";
72b16652 33my @r = glob;
92361f5e 34is($_, "op/*.t");
72b16652 35
92361f5e 36cmp_ok(scalar @r, '>=', 3);
72b16652 37
1d89eaef 38@r = <*/*.t>;
72b16652 39# at least t/global.t t/basic.t, t/taint.t
92361f5e 40cmp_ok(scalar @r, '>=', 3, 'check if <*/*> works');
72b16652
GS
41my $r = scalar @r;
42
72b16652 43@r = ();
1d89eaef
NC
44while (defined($_ = <*/*.t>)) {
45 #print "# $_\n";
46 push @r, $_;
72b16652 47}
92361f5e 48is(scalar @r, $r, 'check if scalar context works');
72b16652 49
72b16652 50@r = ();
1d89eaef
NC
51for (<*/*.t>) {
52 #print "# $_\n";
53 push @r, $_;
72b16652 54}
92361f5e 55is(scalar @r, $r, 'check if list context works');
72b16652 56
72b16652 57@r = ();
1d89eaef
NC
58while (<*/*.t>) {
59 #print "# $_\n";
60 push @r, $_;
72b16652 61}
92361f5e 62is(scalar @r, $r, 'implicit assign to $_ in while()');
72b16652 63
72b16652 64my @s = ();
1d89eaef 65while (glob('*/*.t')) {
72b16652
GS
66 #print "# $_\n";
67 push @s, $_;
68}
92361f5e 69is("@r", "@s", 'explicit glob() gets assign magic too');
72b16652 70
72b16652 71package Foo;
220398a0 72use File::Glob ':globally';
72b16652 73@s = ();
1d89eaef 74while (glob('*/*.t')) {
72b16652
GS
75 #print "# $_\n";
76 push @s, $_;
77}
92361f5e 78main::is("@r", "@s", 'in a different package');
72b16652
GS
79
80# test if different glob ops maintain independent contexts
81@s = ();
82my $i = 0;
1d89eaef
NC
83while (<*/*.t>) {
84 #print "# $_ <";
85 push @s, $_;
86 while (<bas*/*.t>) {
87 #print " $_";
88 $i++;
89 }
90 #print " >\n";
72b16652 91}
92361f5e
NC
92
93main::is("@r", "@s", 'different glob ops maintain independent contexts');
94main::isnt($i, 0, 'different glob ops maintain independent contexts');