1*0Sstevel@tonic-gate#!./perl 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gate# 4*0Sstevel@tonic-gate# test glob() in File::DosGlob 5*0Sstevel@tonic-gate# 6*0Sstevel@tonic-gate 7*0Sstevel@tonic-gateBEGIN { 8*0Sstevel@tonic-gate chdir 't' if -d 't'; 9*0Sstevel@tonic-gate @INC = '../lib'; 10*0Sstevel@tonic-gate} 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gateprint "1..10\n"; 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gate# override it in main:: 15*0Sstevel@tonic-gateuse File::DosGlob 'glob'; 16*0Sstevel@tonic-gate 17*0Sstevel@tonic-gate# test if $_ takes as the default 18*0Sstevel@tonic-gatemy $expected; 19*0Sstevel@tonic-gateif ($^O eq 'MacOS') { 20*0Sstevel@tonic-gate $expected = $_ = ":op:a*.t"; 21*0Sstevel@tonic-gate} else { 22*0Sstevel@tonic-gate $expected = $_ = "op/a*.t"; 23*0Sstevel@tonic-gate} 24*0Sstevel@tonic-gatemy @r = glob; 25*0Sstevel@tonic-gateprint "not " if $_ ne $expected; 26*0Sstevel@tonic-gateprint "ok 1\n"; 27*0Sstevel@tonic-gateprint "# |@r|\nnot " if @r < 9; 28*0Sstevel@tonic-gateprint "ok 2\n"; 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate# check if <*/*> works 31*0Sstevel@tonic-gateif ($^O eq 'MacOS') { 32*0Sstevel@tonic-gate @r = <:*:a*.t>; 33*0Sstevel@tonic-gate} else { 34*0Sstevel@tonic-gate @r = <*/a*.t>; 35*0Sstevel@tonic-gate} 36*0Sstevel@tonic-gate# atleast {argv,abbrev,anydbm,autoloader,append,arith,array,assignwarn,auto}.t 37*0Sstevel@tonic-gateprint "# |@r|\nnot " if @r < 9; 38*0Sstevel@tonic-gateprint "ok 3\n"; 39*0Sstevel@tonic-gatemy $r = scalar @r; 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate# check if scalar context works 42*0Sstevel@tonic-gate@r = (); 43*0Sstevel@tonic-gatewhile (defined($_ = ($^O eq 'MacOS') ? <:*:a*.t> : <*/a*.t>)) { 44*0Sstevel@tonic-gate print "# $_\n"; 45*0Sstevel@tonic-gate push @r, $_; 46*0Sstevel@tonic-gate} 47*0Sstevel@tonic-gateprint "not " if @r != $r; 48*0Sstevel@tonic-gateprint "ok 4\n"; 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate# check if list context works 51*0Sstevel@tonic-gate@r = (); 52*0Sstevel@tonic-gateif ($^O eq 'MacOS') { 53*0Sstevel@tonic-gate for (<:*:a*.t>) { 54*0Sstevel@tonic-gate print "# $_\n"; 55*0Sstevel@tonic-gate push @r, $_; 56*0Sstevel@tonic-gate } 57*0Sstevel@tonic-gate} else { 58*0Sstevel@tonic-gate for (<*/a*.t>) { 59*0Sstevel@tonic-gate print "# $_\n"; 60*0Sstevel@tonic-gate push @r, $_; 61*0Sstevel@tonic-gate } 62*0Sstevel@tonic-gate} 63*0Sstevel@tonic-gateprint "not " if @r != $r; 64*0Sstevel@tonic-gateprint "ok 5\n"; 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate# test if implicit assign to $_ in while() works 67*0Sstevel@tonic-gate@r = (); 68*0Sstevel@tonic-gateif ($^O eq 'MacOS') { 69*0Sstevel@tonic-gate while (<:*:a*.t>) { 70*0Sstevel@tonic-gate print "# $_\n"; 71*0Sstevel@tonic-gate push @r, $_; 72*0Sstevel@tonic-gate } 73*0Sstevel@tonic-gate} else { 74*0Sstevel@tonic-gate while (<*/a*.t>) { 75*0Sstevel@tonic-gate print "# $_\n"; 76*0Sstevel@tonic-gate push @r, $_; 77*0Sstevel@tonic-gate } 78*0Sstevel@tonic-gate} 79*0Sstevel@tonic-gateprint "not " if @r != $r; 80*0Sstevel@tonic-gateprint "ok 6\n"; 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate# test if explicit glob() gets assign magic too 83*0Sstevel@tonic-gatemy @s = (); 84*0Sstevel@tonic-gatemy $pat = ($^O eq 'MacOS') ? ':*:a*.t': '*/a*.t'; 85*0Sstevel@tonic-gatewhile (glob ($pat)) { 86*0Sstevel@tonic-gate print "# $_\n"; 87*0Sstevel@tonic-gate push @s, $_; 88*0Sstevel@tonic-gate} 89*0Sstevel@tonic-gateprint "not " if "@r" ne "@s"; 90*0Sstevel@tonic-gateprint "ok 7\n"; 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate# how about in a different package, like? 93*0Sstevel@tonic-gatepackage Foo; 94*0Sstevel@tonic-gateuse File::DosGlob 'glob'; 95*0Sstevel@tonic-gate@s = (); 96*0Sstevel@tonic-gate$pat = $^O eq 'MacOS' ? ':*:a*.t' : '*/a*.t'; 97*0Sstevel@tonic-gatewhile (glob($pat)) { 98*0Sstevel@tonic-gate print "# $_\n"; 99*0Sstevel@tonic-gate push @s, $_; 100*0Sstevel@tonic-gate} 101*0Sstevel@tonic-gateprint "not " if "@r" ne "@s"; 102*0Sstevel@tonic-gateprint "ok 8\n"; 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate# test if different glob ops maintain independent contexts 105*0Sstevel@tonic-gate@s = (); 106*0Sstevel@tonic-gateif ($^O eq 'MacOS') { 107*0Sstevel@tonic-gate while (<:*:a*.t>) { 108*0Sstevel@tonic-gate my $i = 0; 109*0Sstevel@tonic-gate print "# $_ <"; 110*0Sstevel@tonic-gate push @s, $_; 111*0Sstevel@tonic-gate while (<:*:b*.t>) { 112*0Sstevel@tonic-gate print " $_"; 113*0Sstevel@tonic-gate $i++; 114*0Sstevel@tonic-gate } 115*0Sstevel@tonic-gate print " >\n"; 116*0Sstevel@tonic-gate } 117*0Sstevel@tonic-gate} else { 118*0Sstevel@tonic-gate while (<*/a*.t>) { 119*0Sstevel@tonic-gate my $i = 0; 120*0Sstevel@tonic-gate print "# $_ <"; 121*0Sstevel@tonic-gate push @s, $_; 122*0Sstevel@tonic-gate while (<*/b*.t>) { 123*0Sstevel@tonic-gate print " $_"; 124*0Sstevel@tonic-gate $i++; 125*0Sstevel@tonic-gate } 126*0Sstevel@tonic-gate print " >\n"; 127*0Sstevel@tonic-gate } 128*0Sstevel@tonic-gate} 129*0Sstevel@tonic-gateprint "not " if "@r" ne "@s"; 130*0Sstevel@tonic-gateprint "ok 9\n"; 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate# how about a global override, hm? 133*0Sstevel@tonic-gateeval <<'EOT'; 134*0Sstevel@tonic-gateuse File::DosGlob 'GLOBAL_glob'; 135*0Sstevel@tonic-gatepackage Bar; 136*0Sstevel@tonic-gate@s = (); 137*0Sstevel@tonic-gateif ($^O eq 'MacOS') { 138*0Sstevel@tonic-gate while (<:*:a*.t>) { 139*0Sstevel@tonic-gate my $i = 0; 140*0Sstevel@tonic-gate print "# $_ <"; 141*0Sstevel@tonic-gate push @s, $_; 142*0Sstevel@tonic-gate while (glob ':*:b*.t') { 143*0Sstevel@tonic-gate print " $_"; 144*0Sstevel@tonic-gate $i++; 145*0Sstevel@tonic-gate } 146*0Sstevel@tonic-gate print " >\n"; 147*0Sstevel@tonic-gate } 148*0Sstevel@tonic-gate} else { 149*0Sstevel@tonic-gate while (<*/a*.t>) { 150*0Sstevel@tonic-gate my $i = 0; 151*0Sstevel@tonic-gate print "# $_ <"; 152*0Sstevel@tonic-gate push @s, $_; 153*0Sstevel@tonic-gate while (glob '*/b*.t') { 154*0Sstevel@tonic-gate print " $_"; 155*0Sstevel@tonic-gate $i++; 156*0Sstevel@tonic-gate } 157*0Sstevel@tonic-gate print " >\n"; 158*0Sstevel@tonic-gate } 159*0Sstevel@tonic-gate} 160*0Sstevel@tonic-gateprint "not " if "@r" ne "@s"; 161*0Sstevel@tonic-gateprint "ok 10\n"; 162*0Sstevel@tonic-gateEOT 163