9 use Config qw( %Config );
12 # Check whether the build is configured with -Dmksymlinks
14 grep { /^config_arg\d+$/ && $Config{$_} eq '-Dmksymlinks' }
17 # Resolve symlink to ./lib/File/stat.t if this build is configured
19 # Originally we worked with ./TEST, but other test scripts read from
20 # that file and modify its access time.
21 our $file = '../lib/File/stat.t';
23 $file = readlink $file;
24 die "Can't readlink(TEST): $!" if ! defined $file;
28 eval { my @n = stat $file };
29 $hasst = 1 unless $@ && $@ =~ /unimplemented/;
30 unless ($hasst) { plan skip_all => "no stat"; exit 0 }
32 $hasst = 0 unless $Config{'i_sysstat'} eq 'define';
33 unless ($hasst) { plan skip_all => "no sys/stat.h"; exit 0 }
36 # Originally this was done in the BEGIN block, but perl is still
37 # compiling (and hence reading) the script at that point, which can
38 # change the file's access time, causing a different in the comparison
39 # tests if the clock ticked over the second between the stat() and the
41 # At this point all of the reading is done.
42 our @stat = stat $file; # This is the function stat.
43 unless (@stat) { plan skip_all => "1..0 # Skip: no file $file"; exit 0 }
45 plan tests => 19 + 24*2 + 3;
47 use_ok( 'File::stat' );
49 my $stat = File::stat::stat( $file ); # This is the OO stat.
50 ok( ref($stat), 'should build a stat object' );
52 is( $stat->dev, $stat[0], "device number in position 0" );
54 # On OS/2 (fake) ino is not constant, it is incremented each time
56 skip('inode number is not constant on OS/2', 1) if $^O eq 'os2';
57 is( $stat->ino, $stat[1], "inode number in position 1" );
60 is( $stat->mode, $stat[2], "file mode in position 2" );
62 is( $stat->nlink, $stat[3], "number of links in position 3" );
64 is( $stat->uid, $stat[4], "owner uid in position 4" );
66 is( $stat->gid, $stat[5], "group id in position 5" );
68 is( $stat->rdev, $stat[6], "device identifier in position 6" );
70 is( $stat->size, $stat[7], "file size in position 7" );
72 is( $stat->atime, $stat[8], "last access time in position 8" );
74 is( $stat->mtime, $stat[9], "last modify time in position 9" );
76 is( $stat->ctime, $stat[10], "change time in position 10" );
78 is( $stat->blksize, $stat[11], "IO block size in position 11" );
80 is( $stat->blocks, $stat[12], "number of blocks in position 12" );
82 for (split //, "rwxoRWXOezsfdlpSbcugkMCA") {
84 $^O eq "VMS" and index("rwxRWX", $_) >= 0
85 and skip "File::stat ignores VMS ACLs", 2;
87 my $rv = eval "-$_ \$stat";
88 ok( !$@, "-$_ overload succeeds" )
90 is( $rv, eval "-$_ \$file", "correct -$_ overload" );
94 for (split //, "tTB") {
96 like( $@, qr/\Q-$_ is not implemented/, "-$_ overload fails" );
101 skip("Could not open file: $!", 2) unless open(STAT, $file);
102 ok( File::stat::stat('STAT'), '... should be able to find filehandle' );
105 local *STAT = *main::STAT;
106 main::ok( my $stat2 = File::stat::stat('STAT'),
107 '... and filehandle in another package' );
110 # VOS open() updates atime; ignore this error (posix-975).
113 $$stat3[8] = $$stat[8];
116 main::skip("Win32: different stat-info on filehandle", 1) if $^O eq 'MSWin32';
117 main::skip("dos: inode number is fake on dos", 1) if $^O eq 'dos';
119 main::skip("OS/2: inode number is not constant on os/2", 1) if $^O eq 'os2';
121 main::is( "@$stat", "@$stat3", '... and must match normal stat' );
126 $stat = stat '/notafile';
127 isnt( $!, '', 'should populate $!, given invalid file' );
129 # Testing pretty much anything else is unportable.