summaryrefslogtreecommitdiffstats
path: root/contrib/perl5/t/lib/io_dir.t
blob: 11ec8bcbf92ad127f3a558bea362579005946e52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!./perl

BEGIN {
    unless(grep /blib/, @INC) {
        chdir 't' if -d 't';
        unshift @INC, '../lib' if -d '../lib';
    }
    require Config; import Config;
    if ($] < 5.00326 || not $Config{'d_readdir'}) {
	print "1..0\n";
	exit 0;
    }
}

select(STDERR); $| = 1;
select(STDOUT); $| = 1;

use IO::Dir qw(DIR_UNLINK);

print "1..10\n";

$dot = new IO::Dir ".";
print defined($dot) ? "ok" : "not ok", " 1\n";

@a = sort <*>;
do { $first = $dot->read } while defined($first) && $first =~ /^\./;
print +(grep { $_ eq $first } @a) ? "ok" : "not ok", " 2\n";

@b = sort($first, (grep {/^[^.]/} $dot->read));
print +(join("\0", @a) eq join("\0", @b)) ? "ok" : "not ok", " 3\n";

$dot->rewind;
@c = sort grep {/^[^.]/} $dot->read;
print +(join("\0", @b) eq join("\0", @c)) ? "ok" : "not ok", " 4\n";

$dot->close;
$dot->rewind;
print defined($dot->read) ? "not ok" : "ok", " 5\n";

open(FH,'>X') || die "Can't create x";
print FH "X";
close(FH);

tie %dir, IO::Dir, ".";
my @files = keys %dir;

# I hope we do not have an empty dir :-)
print @files ? "ok" : "not ok", " 6\n";

my $stat = $dir{'X'};
print defined($stat) && UNIVERSAL::isa($stat,'File::stat') && $stat->size == 1
	? "ok" : "not ok", " 7\n";

delete $dir{'X'};

print -f 'X' ? "ok" : "not ok", " 8\n";

tie %dirx, IO::Dir, ".", DIR_UNLINK;

my $statx = $dirx{'X'};
print defined($statx) && UNIVERSAL::isa($statx,'File::stat') && $statx->size == 1
	? "ok" : "not ok", " 9\n";

delete $dirx{'X'};

print -f 'X' ? "not ok" : "ok", " 10\n";
OpenPOWER on IntegriCloud