[RESEND] [PATCH] Mac OS lib patches for bleadperl
[p5sagit/p5-mst-13.2.git] / t / lib / io_dir.t
CommitLineData
cf7fe8a2 1#!./perl
2
3BEGIN {
4 unless(grep /blib/, @INC) {
5 chdir 't' if -d 't';
20822f61 6 @INC = '../lib';
cf7fe8a2 7 }
8 require Config; import Config;
9 if ($] < 5.00326 || not $Config{'d_readdir'}) {
10 print "1..0\n";
11 exit 0;
12 }
13}
14
15select(STDERR); $| = 1;
16select(STDOUT); $| = 1;
17
18use IO::Dir qw(DIR_UNLINK);
19
20print "1..10\n";
21
6c254d95 22my $DIR = $^O eq 'MacOS' ? ":" : ".";
23
24$dot = new IO::Dir $DIR;
cf7fe8a2 25print defined($dot) ? "ok" : "not ok", " 1\n";
26
27@a = sort <*>;
28do { $first = $dot->read } while defined($first) && $first =~ /^\./;
29print +(grep { $_ eq $first } @a) ? "ok" : "not ok", " 2\n";
30
31@b = sort($first, (grep {/^[^.]/} $dot->read));
32print +(join("\0", @a) eq join("\0", @b)) ? "ok" : "not ok", " 3\n";
33
34$dot->rewind;
35@c = sort grep {/^[^.]/} $dot->read;
36print +(join("\0", @b) eq join("\0", @c)) ? "ok" : "not ok", " 4\n";
37
38$dot->close;
39$dot->rewind;
40print defined($dot->read) ? "not ok" : "ok", " 5\n";
41
42open(FH,'>X') || die "Can't create x";
43print FH "X";
44close(FH);
45
6c254d95 46tie %dir, IO::Dir, $DIR;
cf7fe8a2 47my @files = keys %dir;
48
49# I hope we do not have an empty dir :-)
50print @files ? "ok" : "not ok", " 6\n";
51
52my $stat = $dir{'X'};
53print defined($stat) && UNIVERSAL::isa($stat,'File::stat') && $stat->size == 1
54 ? "ok" : "not ok", " 7\n";
55
56delete $dir{'X'};
57
58print -f 'X' ? "ok" : "not ok", " 8\n";
59
6c254d95 60tie %dirx, IO::Dir, $DIR, DIR_UNLINK;
cf7fe8a2 61
62my $statx = $dirx{'X'};
63print defined($statx) && UNIVERSAL::isa($statx,'File::stat') && $statx->size == 1
64 ? "ok" : "not ok", " 9\n";
65
66delete $dirx{'X'};
67
68print -f 'X' ? "not ok" : "ok", " 10\n";