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(../lib/File/stat.t): $!" 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 }
47 my $stat = File::stat::stat( $file ); # This is the OO stat.
48 isa_ok($stat, 'File::stat', 'should build a stat object' );
51 foreach ([dev => 'device number'],
52 [ino => 'inode number'],
53 [mode => 'file mode'],
54 [nlink => 'number of links'],
57 [rdev => 'device identifier'],
58 [size => 'file size'],
59 [atime => 'last access time'],
60 [mtime => 'last modify time'],
61 [ctime => 'change time'],
62 [blksize => 'IO block size'],
63 [blocks => 'number of blocks']) {
64 my ($meth, $desc) = @$_;
65 # On OS/2 (fake) ino is not constant, it is incremented each time
67 skip('inode number is not constant on OS/2', 1)
68 if $i == 1 && $^O eq 'os2';
69 is($stat->$meth, $stat[$i], "$desc in position $i");
74 for (split //, "rwxoRWXOezsfdlpSbcugkMCA") {
76 $^O eq "VMS" and index("rwxRWX", $_) >= 0
77 and skip "File::stat ignores VMS ACLs", 2;
79 my $rv = eval "-$_ \$stat";
80 ok( !$@, "-$_ overload succeeds" )
82 is( $rv, eval "-$_ \$file", "correct -$_ overload" );
88 -e $file && -x $file or skip "$file is not present and executable", 4;
89 $^O eq "VMS" and skip "File::stat ignores VMS ACLs", 4;
91 my $stat = File::stat::stat( $file ); # This is the OO stat.
93 my $rv = eval "-$_ \$stat";
94 ok( !$@, "-$_ overload succeeds" )
96 is( $rv, eval "-$_ \$file", "correct -$_ overload" );
101 for (split //, "tTB") {
103 like( $@, qr/\Q-$_ is not implemented/, "-$_ overload fails" );
108 skip("Could not open file: $!", 2) unless open(STAT, $file);
109 ok( File::stat::stat('STAT'), '... should be able to find filehandle' );
112 local *STAT = *main::STAT;
113 main::ok( my $stat2 = File::stat::stat('STAT'),
114 '... and filehandle in another package' );
117 # VOS open() updates atime; ignore this error (posix-975).
120 $$stat3[8] = $$stat[8];
123 main::skip("Win32: different stat-info on filehandle", 1) if $^O eq 'MSWin32';
124 main::skip("dos: inode number is fake on dos", 1) if $^O eq 'dos';
126 main::skip("OS/2: inode number is not constant on os/2", 1) if $^O eq 'os2';
128 main::is( "@$stat", "@$stat3", '... and must match normal stat' );
131 { # 111640 - File::stat bogus index check in overload
133 use filetest "access";
135 for my $op (split //, "rwxRXW") {
136 # these should all warn with filetest access
138 local $SIG{__WARN__} = sub { $w .= shift };
140 like($w, qr/^File::stat ignores use filetest 'access'/,
141 "-$op produced the right warning under use filetest 'access'");
145 # -d and others shouldn't warn
147 local $SIG{__WARN__} = sub { $w = shift };
149 is($w, undef, "Should be no warning from -d under filetest access");
155 skip "We can't check for FIFOs", 2 unless defined &Fcntl::S_ISFIFO;
156 skip "No pipes", 2 unless defined $Config{d_pipe};
158 or skip "Couldn't create a pipe: $!", 2;
159 skip "Built-in -p doesn't detect a pipe", 2 unless -p $rh;
161 my $pstat = File::stat::stat($rh);
162 ok(!-p($stat), "-p should be false on a file");
163 ok(-p($pstat), "check -p detects a pipe");
167 $stat = stat '/notafile';
168 isnt( $!, '', 'should populate $!, given invalid file' );
170 # Testing pretty much anything else is unportable.
175 # cperl-indent-level: 4
176 # indent-tabs-mode: nil
179 # ex: set ts=8 sts=4 sw=4 et: