print "1..0 # Skip: readdir() not available\n";
exit 0;
}
-}
-
-select(STDERR); $| = 1;
-select(STDOUT); $| = 1;
-use IO::Dir qw(DIR_UNLINK);
+ require($ENV{PERL_CORE} ? "./test.pl" : "./t/test.pl");
+ plan(16);
-my $tcount = 0;
-
-sub ok {
- $tcount++;
- my $not = $_[0] ? '' : 'not ';
- print "${not}ok $tcount\n";
+ use_ok('IO::Dir');
+ IO::Dir->import(DIR_UNLINK);
}
-print "1..10\n";
+use strict;
my $DIR = $^O eq 'MacOS' ? ":" : ".";
-$dot = new IO::Dir $DIR;
+my $CLASS = "IO::Dir";
+my $dot = $CLASS->new($DIR);
ok(defined($dot));
-@a = sort <*>;
+my @a = sort <*>;
+my $first;
do { $first = $dot->read } while defined($first) && $first =~ /^\./;
ok(+(grep { $_ eq $first } @a));
-@b = sort($first, (grep {/^[^.]/} $dot->read));
+my @b = sort($first, (grep {/^[^.]/} $dot->read));
ok(+(join("\0", @a) eq join("\0", @b)));
-$dot->rewind;
-@c = sort grep {/^[^.]/} $dot->read;
+ok($dot->rewind,'rewind');
+my @c = sort grep {/^[^.]/} $dot->read;
ok(+(join("\0", @b) eq join("\0", @c)));
-$dot->close;
-$dot->rewind;
+ok($dot->close,'close');
+{ local $^W; # avoid warnings on invalid dirhandle
+ok(!$dot->rewind, "rewind on closed");
ok(!defined($dot->read));
+}
open(FH,'>X') || die "Can't create x";
print FH "X";
close(FH) or die "Can't close: $!";
-tie %dir, IO::Dir, $DIR;
+my %dir;
+tie %dir, $CLASS, $DIR;
my @files = keys %dir;
# I hope we do not have an empty dir :-)
ok(scalar @files);
my $stat = $dir{'X'};
-ok(defined($stat) && UNIVERSAL::isa($stat,'File::stat') && $stat->size == 1);
+isa_ok($stat,'File::stat');
+ok(defined($stat) && $stat->size == 1);
delete $dir{'X'};
ok(-f 'X');
-tie %dirx, IO::Dir, $DIR, DIR_UNLINK;
+my %dirx;
+tie %dirx, $CLASS, $DIR, DIR_UNLINK;
my $statx = $dirx{'X'};
-ok(defined($statx) && UNIVERSAL::isa($statx,'File::stat') && $statx->size == 1);
+isa_ok($statx,'File::stat');
+ok(defined($statx) && $statx->size == 1);
delete $dirx{'X'};
}
}
+use strict;
+if ($ENV{PERL_CORE}) {
+ require("./test.pl");
+}
+else {
+ require("./t/test.pl");
+}
+plan(tests => 5);
+
END { unlink "./__taint__$$" }
-print "1..5\n";
use IO::File;
-$x = new IO::File "> ./__taint__$$" || die("Cannot open ./__taint__$$\n");
+my $x = new IO::File "> ./__taint__$$" || die("Cannot open ./__taint__$$\n");
print $x "$$\n";
$x->close;
$x = new IO::File "< ./__taint__$$" || die("Cannot open ./__taint__$$\n");
-chop($unsafe = <$x>);
+chop(my $unsafe = <$x>);
eval { kill 0 * $unsafe };
-print "not " if ((($^O ne 'MSWin32') && ($^O ne 'NetWare')) and ($@ !~ /^Insecure/o));
-print "ok 1\n";
+SKIP: {
+ skip($^O) if $^O eq 'MSWin32' or $^O eq 'NetWare';
+ like($@, '^Insecure');
+}
$x->close;
# We could have just done a seek on $x, but technically we haven't tested
# seek yet...
$x = new IO::File "< ./__taint__$$" || die("Cannot open ./__taint__$$\n");
$x->untaint;
-print "not " if ($?);
-print "ok 2\n"; # Calling the method worked
+ok(!$?); # Calling the method worked
chop($unsafe = <$x>);
eval { kill 0 * $unsafe };
-print "not " if ($@ =~ /^Insecure/o);
-print "ok 3\n"; # No Insecure message from using the data
+unlike($@,'^Insecure');
$x->close;
-# this will segfault if it fails
+TODO: {
+ todo_skip("Known bug in 5.10.0",2) if $] >= 5.010 and $] < 5.010_001;
+
+ # this will segfault if it fails
-sub PVBM () { 'foo' }
-{ my $dummy = index 'foo', PVBM }
+ sub PVBM () { 'foo' }
+ { my $dummy = index 'foo', PVBM }
-eval { IO::Handle::untaint(PVBM) };
-print "ok 4\n";
+ eval { IO::Handle::untaint(PVBM) };
+ pass();
-eval { IO::Handle::untaint(\PVBM) };
-print "ok 5\n";
+ eval { IO::Handle::untaint(\PVBM) };
+ pass();
+}
exit 0;