t/op/my_stash.t should use test.pl instead of Test.pm
[p5sagit/p5-mst-13.2.git] / t / op / glob.t
old mode 100755 (executable)
new mode 100644 (file)
index 4c27445..fd542cb
@@ -2,39 +2,93 @@
 
 BEGIN {
     chdir 't' if -d 't';
-    unshift @INC, '../lib';
+    @INC = qw(. ../lib);
 }
 
-print "1..6\n";
+require 'test.pl';
+plan( tests => 15 );
 
 @oops = @ops = <op/*>;
 
 if ($^O eq 'MSWin32') {
   map { $files{lc($_)}++ } <op/*>;
-  map { delete $files{"op/$_"} } split /[\s\n]/, `cmd /c "dir /b /l op & dir /b /l /ah op 2>nul"`,
+  map { delete $files{"op/$_"} } split /[\s\n]/, `dir /b /l op & dir /b /l /ah op 2>nul`,
+}
+elsif ($^O eq 'VMS') {
+  map { $files{lc($_)}++ } <[.op]*>;
+  map { s/;.*$//; delete $files{lc($_)}; } split /[\n]/, `directory/noheading/notrailing/versions=1 [.op]`,
+}
+elsif ($^O eq 'MacOS') {
+  @oops = @ops = <:op:*>;
+  map { $files{$_}++ } <:op:*>;
+  map { delete $files{$_} } split /[\s\n]/, `echo :op:\xc5`;
 }
 else {
   map { $files{$_}++ } <op/*>;
   map { delete $files{$_} } split /[\s\n]/, `echo op/*`;
 }
-if (keys %files) {
-       print "not ok 1\t(",join(' ', sort keys %files),"\n";
-} else { print "ok 1\n"; }
+ok( !(keys(%files)),'leftover op/* files' ) or diag(join(' ',sort keys %files));
 
-print $/ eq "\n" ? "ok 2\n" : "not ok 2\n";
+cmp_ok($/,'eq',"\n",'sane input record separator');
 
-while (<jskdfjskdfj* op/* jskdjfjkosvk*>) {
-    $not = "not " unless $_ eq shift @ops;
-    $not = "not at all " if $/ eq "\0";
+$not = '';
+if ($^O eq 'MacOS') {
+    while (<jskdfjskdfj* :op:* jskdjfjkosvk*>) {
+       $not = "not " unless $_ eq shift @ops;
+       $not = "not at all " if $/ eq "\0";
+    }
+} else {
+    while (<jskdfjskdfj* op/* jskdjfjkosvk*>) {
+       $not = "not " unless $_ eq shift @ops;
+       $not = "not at all " if $/ eq "\0";
+    }
 }
-print "${not}ok 3\n";
+ok(!$not,"glob amid garbage [$not]");
 
-print $/ eq "\n" ? "ok 4\n" : "not ok 4\n";
+cmp_ok($/,'eq',"\n",'input record separator still sane');
 
-# test the "glob" operator
-$_ = "op/*";
+$_ = $^O eq 'MacOS' ? ":op:*" : "op/*";
 @glops = glob $_;
-print "@glops" eq "@oops" ? "ok 5\n" : "not ok 5\n";
+cmp_ok("@glops",'eq',"@oops",'glob operator 1');
 
 @glops = glob;
-print "@glops" eq "@oops" ? "ok 6\n" : "not ok 6\n";
+cmp_ok("@glops",'eq',"@oops",'glob operator 2');
+
+# glob should still work even after the File::Glob stash has gone away
+# (this used to dump core)
+my $i = 0;
+for (1..2) {
+    eval "<.>";
+    ok(!length($@),"eval'ed a glob $_");
+    undef %File::Glob::;
+    ++$i;
+}
+cmp_ok($i,'==',2,'remore File::Glob stash');
+
+# ... while ($var = glob(...)) should test definedness not truth
+
+SKIP: {
+    skip('no File::Glob to emulate Unix-ism', 1)
+       unless $INC{'File/Glob.pm'};
+    my $ok = 0;
+    $ok = 1 while my $var = glob("0");
+    ok($ok,'define versus truth');
+}
+
+# The formerly-broken test for the situation above would accidentally
+# test definedness for an assignment with a LOGOP on the right:
+{
+    my $f = 0;
+    my $ok = 1;
+    $ok = 0, undef $f while $x = $f||$f;
+    ok($ok,'test definedness with LOGOP');
+}
+
+cmp_ok(scalar(@oops),'>',0,'glob globbed something');
+
+*aieee = 4;
+pass('Can assign integers to typeglobs');
+*aieee = 3.14;
+pass('Can assign floats to typeglobs');
+*aieee = 'pi';
+pass('Can assign strings to typeglobs');