Commit | Line | Data |
---|---|---|
8d063cd8 LW |
1 | #!./perl |
2 | ||
ea368a7c CS |
3 | BEGIN { |
4 | chdir 't' if -d 't'; | |
20822f61 | 5 | @INC = '../lib'; |
2bc69dc4 | 6 | require './test.pl'; # for which_perl() etc |
ea368a7c CS |
7 | } |
8 | ||
9 | use Config; | |
de5a37b2 | 10 | use File::Spec; |
ea368a7c | 11 | |
20c932f8 | 12 | plan tests => 107; |
8d063cd8 | 13 | |
2bc69dc4 | 14 | my $Perl = which_perl(); |
b5fe401b | 15 | |
cc25fa79 MS |
16 | $Is_Amiga = $^O eq 'amigaos'; |
17 | $Is_Cygwin = $^O eq 'cygwin'; | |
be4e88b6 | 18 | $Is_Darwin = $^O eq 'darwin'; |
cc25fa79 MS |
19 | $Is_Dos = $^O eq 'dos'; |
20 | $Is_MPE = $^O eq 'mpeix'; | |
68dc0745 | 21 | $Is_MSWin32 = $^O eq 'MSWin32'; |
2986a63f | 22 | $Is_NetWare = $^O eq 'NetWare'; |
cc25fa79 MS |
23 | $Is_OS2 = $^O eq 'os2'; |
24 | $Is_Solaris = $^O eq 'solaris'; | |
de5a37b2 | 25 | $Is_VMS = $^O eq 'VMS'; |
95036ac7 | 26 | $Is_DGUX = $^O eq 'dgux'; |
ca37ab50 | 27 | $Is_MPRAS = $^O =~ /svr4/ && -f '/etc/.relid'; |
61967be2 | 28 | $Is_Rhapsody= $^O eq 'rhapsody'; |
cc25fa79 MS |
29 | |
30 | $Is_Dosish = $Is_Dos || $Is_OS2 || $Is_MSWin32 || $Is_NetWare || $Is_Cygwin; | |
cc25fa79 | 31 | |
822f7be5 | 32 | $Is_UFS = $Is_Darwin && (() = `df -t ufs . 2>/dev/null`) == 2; |
be4e88b6 | 33 | |
cc25fa79 MS |
34 | my($DEV, $INO, $MODE, $NLINK, $UID, $GID, $RDEV, $SIZE, |
35 | $ATIME, $MTIME, $CTIME, $BLKSIZE, $BLOCKS) = (0..12); | |
d48672a2 | 36 | |
de5a37b2 MS |
37 | my $Curdir = File::Spec->curdir; |
38 | ||
4435c477 | 39 | |
1c25d394 NC |
40 | my $tmpfile = tempfile(); |
41 | my $tmpfile_link = tempfile(); | |
4435c477 | 42 | |
295d5f02 | 43 | chmod 0666, $tmpfile; |
98a392ec | 44 | 1 while unlink $tmpfile; |
c4fbe247 | 45 | open(FOO, ">$tmpfile") || DIE("Can't open temp test file: $!"); |
de5a37b2 | 46 | close FOO; |
8d220878 | 47 | |
c4fbe247 | 48 | open(FOO, ">$tmpfile") || DIE("Can't open temp test file: $!"); |
4435c477 | 49 | |
cc25fa79 | 50 | my($nlink, $mtime, $ctime) = (stat(FOO))[$NLINK, $MTIME, $CTIME]; |
16ed4686 | 51 | |
67fcfcf9 JL |
52 | # The clock on a network filesystem might be different from the |
53 | # system clock. | |
54 | my $Filesystem_Time_Offset = abs($mtime - time); | |
55 | ||
9accb295 | 56 | #nlink should if link support configured in Perl. |
b5bfebd7 | 57 | SKIP: { |
9accb295 CB |
58 | skip "No link count - Hard link support not built in.", 1 |
59 | unless $Config{d_link}; | |
b5bfebd7 MS |
60 | |
61 | is($nlink, 1, 'nlink on regular file'); | |
62 | } | |
8d220878 | 63 | |
cc25fa79 | 64 | SKIP: { |
d5b53b20 | 65 | skip "mtime and ctime not reliable", 2 |
7b903762 | 66 | if $Is_MSWin32 or $Is_NetWare or $Is_Cygwin or $Is_Dos or $Is_Darwin; |
cc25fa79 MS |
67 | |
68 | ok( $mtime, 'mtime' ); | |
69 | is( $mtime, $ctime, 'mtime == ctime' ); | |
4435c477 | 70 | } |
8d063cd8 | 71 | |
cc25fa79 MS |
72 | |
73 | # Cygwin seems to have a 3 second granularity on its timestamps. | |
74 | my $funky_FAT_timestamps = $Is_Cygwin; | |
75 | sleep 3 if $funky_FAT_timestamps; | |
76 | ||
77 | print FOO "Now is the time for all good men to come to.\n"; | |
78 | close(FOO); | |
79 | ||
151269f6 | 80 | sleep 2; |
cc25fa79 MS |
81 | |
82 | ||
83 | SKIP: { | |
84 | unlink $tmpfile_link; | |
de5a37b2 MS |
85 | my $lnk_result = eval { link $tmpfile, $tmpfile_link }; |
86 | skip "link() unimplemented", 6 if $@ =~ /unimplemented/; | |
cc25fa79 | 87 | |
de5a37b2 MS |
88 | is( $@, '', 'link() implemented' ); |
89 | ok( $lnk_result, 'linked tmp testfile' ); | |
cc25fa79 MS |
90 | ok( chmod(0644, $tmpfile), 'chmoded tmp testfile' ); |
91 | ||
92 | my($nlink, $mtime, $ctime) = (stat($tmpfile))[$NLINK, $MTIME, $CTIME]; | |
93 | ||
94 | SKIP: { | |
95 | skip "No link count", 1 if $Config{dont_use_nlink}; | |
f672c027 | 96 | skip "Cygwin9X fakes hard links by copying", 1 |
7d38e28d | 97 | if $Config{myuname} =~ /^cygwin_(?:9\d|me)\b/i; |
f672c027 | 98 | |
cc25fa79 MS |
99 | is($nlink, 2, 'Link count on hard linked file' ); |
100 | } | |
101 | ||
102 | SKIP: { | |
de5a37b2 | 103 | my $cwd = File::Spec->rel2abs($Curdir); |
d5b53b20 NIS |
104 | skip "Solaris tmpfs has different mtime/ctime link semantics", 2 |
105 | if $Is_Solaris and $cwd =~ m#^/tmp# and | |
cc25fa79 MS |
106 | $mtime && $mtime == $ctime; |
107 | skip "AFS has different mtime/ctime link semantics", 2 | |
108 | if $cwd =~ m#$Config{'afsroot'}/#; | |
109 | skip "AmigaOS has different mtime/ctime link semantics", 2 | |
110 | if $Is_Amiga; | |
d5b53b20 NIS |
111 | # Win32 could pass $mtime test but as FAT and NTFS have |
112 | # no ctime concept $ctime is ALWAYS == $mtime | |
113 | # expect netware to be the same ... | |
114 | skip "No ctime concept on this OS", 2 | |
be4e88b6 MS |
115 | if $Is_MSWin32 || |
116 | ($Is_Darwin && $Is_UFS); | |
117 | ||
cc25fa79 MS |
118 | if( !ok($mtime, 'hard link mtime') || |
119 | !isnt($mtime, $ctime, 'hard link ctime != mtime') ) { | |
be4e88b6 | 120 | print STDERR <<DIAG; |
d5b53b20 | 121 | # Check if you are on a tmpfs of some sort. Building in /tmp sometimes |
61967be2 | 122 | # has this problem. Building on the ClearCase VOBS filesystem may also |
cc25fa79 | 123 | # cause this failure. |
61967be2 AL |
124 | # |
125 | # Darwin's UFS doesn't have a ctime concept, and thus is expected to fail | |
126 | # this test. | |
cc25fa79 MS |
127 | DIAG |
128 | } | |
129 | } | |
130 | ||
3fe9a6f1 | 131 | } |
8d063cd8 | 132 | |
cc25fa79 | 133 | # truncate and touch $tmpfile. |
c4fbe247 | 134 | open(F, ">$tmpfile") || DIE("Can't open temp test file: $!"); |
bda6ed21 PM |
135 | ok(-z \*F, '-z on empty filehandle'); |
136 | ok(! -s \*F, ' and -s'); | |
cc25fa79 MS |
137 | close F; |
138 | ||
139 | ok(-z $tmpfile, '-z on empty file'); | |
140 | ok(! -s $tmpfile, ' and -s'); | |
141 | ||
c4fbe247 | 142 | open(F, ">$tmpfile") || DIE("Can't open temp test file: $!"); |
cc25fa79 MS |
143 | print F "hi\n"; |
144 | close F; | |
145 | ||
bda6ed21 PM |
146 | open(F, "<$tmpfile") || DIE("Can't open temp test file: $!"); |
147 | ok(!-z *F, '-z on empty filehandle'); | |
148 | ok( -s *F, ' and -s'); | |
149 | close F; | |
150 | ||
cc25fa79 MS |
151 | ok(! -z $tmpfile, '-z on non-empty file'); |
152 | ok(-s $tmpfile, ' and -s'); | |
153 | ||
154 | ||
155 | # Strip all access rights from the file. | |
156 | ok( chmod(0000, $tmpfile), 'chmod 0000' ); | |
157 | ||
158 | SKIP: { | |
de5a37b2 | 159 | skip "-r, -w and -x have different meanings on VMS", 3 if $Is_VMS; |
cc25fa79 MS |
160 | |
161 | SKIP: { | |
de5a37b2 MS |
162 | # Going to try to switch away from root. Might not work. |
163 | my $olduid = $>; | |
164 | eval { $> = 1; }; | |
d5b53b20 | 165 | skip "Can't test -r or -w meaningfully if you're superuser", 2 |
de5a37b2 MS |
166 | if $> == 0; |
167 | ||
168 | SKIP: { | |
169 | skip "Can't test -r meaningfully?", 1 if $Is_Dos || $Is_Cygwin; | |
170 | ok(!-r $tmpfile, " -r"); | |
171 | } | |
cc25fa79 | 172 | |
de5a37b2 | 173 | ok(!-w $tmpfile, " -w"); |
cc25fa79 | 174 | |
de5a37b2 MS |
175 | # switch uid back (may not be implemented) |
176 | eval { $> = $olduid; }; | |
177 | } | |
178 | ||
179 | ok(! -x $tmpfile, ' -x'); | |
a245ea2d | 180 | } |
cc25fa79 | 181 | |
de5a37b2 | 182 | |
cc25fa79 | 183 | |
cc25fa79 MS |
184 | ok(chmod(0700,$tmpfile), 'chmod 0700'); |
185 | ok(-r $tmpfile, ' -r'); | |
186 | ok(-w $tmpfile, ' -w'); | |
187 | ||
188 | SKIP: { | |
61967be2 | 189 | skip "-x simply determines if a file ends in an executable suffix", 1 |
7b903762 | 190 | if $Is_Dosish; |
cc25fa79 MS |
191 | |
192 | ok(-x $tmpfile, ' -x'); | |
6eb13c3b | 193 | } |
cc25fa79 MS |
194 | |
195 | ok( -f $tmpfile, ' -f'); | |
196 | ok(! -d $tmpfile, ' !-d'); | |
197 | ||
198 | # Is this portable? | |
de5a37b2 MS |
199 | ok( -d $Curdir, '-d cwd' ); |
200 | ok(! -f $Curdir, '!-f cwd' ); | |
201 | ||
cc25fa79 MS |
202 | |
203 | SKIP: { | |
de5a37b2 MS |
204 | unlink($tmpfile_link); |
205 | my $symlink_rslt = eval { symlink $tmpfile, $tmpfile_link }; | |
206 | skip "symlink not implemented", 3 if $@ =~ /unimplemented/; | |
cc25fa79 | 207 | |
de5a37b2 MS |
208 | is( $@, '', 'symlink() implemented' ); |
209 | ok( $symlink_rslt, 'symlink() ok' ); | |
210 | ok(-l $tmpfile_link, '-l'); | |
6eb13c3b | 211 | } |
cc25fa79 MS |
212 | |
213 | ok(-o $tmpfile, '-o'); | |
214 | ||
215 | ok(-e $tmpfile, '-e'); | |
de5a37b2 MS |
216 | |
217 | unlink($tmpfile_link); | |
cc25fa79 MS |
218 | ok(! -e $tmpfile_link, ' -e on unlinked file'); |
219 | ||
220 | SKIP: { | |
feef4889 | 221 | skip "No character, socket or block special files", 6 |
cc25fa79 | 222 | if $Is_MSWin32 || $Is_NetWare || $Is_Dos; |
feef4889 | 223 | skip "/dev isn't available to test against", 6 |
3fcc9fea | 224 | unless -d '/dev' && -r '/dev' && -x '/dev'; |
61967be2 | 225 | skip "Skipping: unexpected ls output in MP-RAS", 6 |
ca37ab50 | 226 | if $Is_MPRAS; |
de5a37b2 | 227 | |
16ed4686 JM |
228 | # VMS problem: If GNV or other UNIX like tool is installed, then |
229 | # sometimes Perl will find /bin/ls, and will try to run it. | |
230 | # But since Perl on VMS does not know to run it under Bash, it will | |
231 | # try to run the DCL verb LS. And if the VMS product Language | |
232 | # Sensitive Editor is installed, or some other LS verb, that will | |
233 | # be run instead. So do not do this until we can teach Perl | |
234 | # when to use BASH on VMS. | |
235 | skip "ls command not available to Perl in OpenVMS right now.", 6 | |
236 | if $Is_VMS; | |
237 | ||
d5b53b20 | 238 | my $LS = $Config{d_readlink} ? "ls -lL" : "ls -l"; |
eb1102fc | 239 | my $CMD = "$LS /dev 2>/dev/null"; |
a7ec4029 JH |
240 | my $DEV = qx($CMD); |
241 | ||
feef4889 | 242 | skip "$CMD failed", 6 if $DEV eq ''; |
a7ec4029 | 243 | |
3fcc9fea JH |
244 | my @DEV = do { my $dev; opendir($dev, "/dev") ? readdir($dev) : () }; |
245 | ||
feef4889 | 246 | skip "opendir failed: $!", 6 if @DEV == 0; |
3fcc9fea | 247 | |
9aa9a1a6 | 248 | # /dev/stdout might be either character special or a named pipe, |
db8ab41e JH |
249 | # or a symlink, or a socket, depending on which OS and how are |
250 | # you running the test, so let's censor that one away. | |
6320a86a | 251 | # Similar remarks hold for stderr. |
db8ab41e | 252 | $DEV =~ s{^[cpls].+?\sstdout$}{}m; |
267513dc | 253 | @DEV = grep { $_ ne 'stdout' } @DEV; |
6320a86a AD |
254 | $DEV =~ s{^[cpls].+?\sstderr$}{}m; |
255 | @DEV = grep { $_ ne 'stderr' } @DEV; | |
267513dc | 256 | |
c7974a0a JH |
257 | # /dev/printer is also naughty: in IRIX it shows up as |
258 | # Srwx-----, not srwx------. | |
259 | $DEV =~ s{^.+?\sprinter$}{}m; | |
260 | @DEV = grep { $_ ne 'printer' } @DEV; | |
261 | ||
267513dc JH |
262 | # If running as root, we will see .files in the ls result, |
263 | # and readdir() will see them always. Potential for conflict, | |
264 | # so let's weed them out. | |
265 | $DEV =~ s{^.+?\s\..+?$}{}m; | |
266 | @DEV = grep { ! m{^\..+$} } @DEV; | |
9aa9a1a6 | 267 | |
085a16fc JH |
268 | # Irix ls -l marks sockets with 'S' while 's' is a 'XENIX semaphore'. |
269 | if ($^O eq 'irix') { | |
270 | $DEV =~ s{^S(.+?)}{s$1}mg; | |
271 | } | |
272 | ||
3fcc9fea | 273 | my $try = sub { |
9f966f7a | 274 | my @c1 = eval qq[\$DEV =~ /^$_[0].*/mg]; |
3fcc9fea JH |
275 | my @c2 = eval qq[grep { $_[1] "/dev/\$_" } \@DEV]; |
276 | my $c1 = scalar @c1; | |
277 | my $c2 = scalar @c2; | |
9aa9a1a6 | 278 | is($c1, $c2, "ls and $_[1] agreeing on /dev ($c1 $c2)"); |
3fcc9fea JH |
279 | }; |
280 | ||
95036ac7 JH |
281 | SKIP: { |
282 | skip("DG/UX ls -L broken", 3) if $Is_DGUX; | |
283 | ||
3fcc9fea JH |
284 | $try->('b', '-b'); |
285 | $try->('c', '-c'); | |
286 | $try->('s', '-S'); | |
95036ac7 | 287 | |
378cc40b LW |
288 | } |
289 | ||
3fcc9fea | 290 | ok(! -b $Curdir, '!-b cwd'); |
de5a37b2 MS |
291 | ok(! -c $Curdir, '!-c cwd'); |
292 | ok(! -S $Curdir, '!-S cwd'); | |
cc25fa79 | 293 | |
95036ac7 JH |
294 | } |
295 | ||
cc25fa79 | 296 | SKIP: { |
cc25fa79 MS |
297 | my($cnt, $uid); |
298 | $cnt = $uid = 0; | |
299 | ||
300 | # Find a set of directories that's very likely to have setuid files | |
301 | # but not likely to be *all* setuid files. | |
302 | my @bin = grep {-d && -r && -x} qw(/sbin /usr/sbin /bin /usr/bin); | |
de5a37b2 | 303 | skip "Can't find a setuid file to test with", 3 unless @bin; |
cc25fa79 MS |
304 | |
305 | for my $bin (@bin) { | |
306 | opendir BIN, $bin or die "Can't opendir $bin: $!"; | |
307 | while (defined($_ = readdir BIN)) { | |
308 | $_ = "$bin/$_"; | |
309 | $cnt++; | |
310 | $uid++ if -u; | |
311 | last if $uid && $uid < $cnt; | |
312 | } | |
313 | } | |
314 | closedir BIN; | |
315 | ||
2304a331 JH |
316 | skip "No setuid programs", 3 if $uid == 0; |
317 | ||
318 | isnt($cnt, 0, 'found some programs'); | |
319 | isnt($uid, 0, ' found some setuid programs'); | |
320 | ok($uid < $cnt, " they're not all setuid"); | |
378cc40b | 321 | } |
b8440792 | 322 | |
378cc40b | 323 | |
3e3baf6d TB |
324 | # To assist in automated testing when a controlling terminal (/dev/tty) |
325 | # may not be available (at, cron rsh etc), the PERL_SKIP_TTY_TEST env var | |
326 | # can be set to skip the tests that need a tty. | |
cc25fa79 MS |
327 | SKIP: { |
328 | skip "These tests require a TTY", 4 if $ENV{PERL_SKIP_TTY_TEST}; | |
329 | ||
61967be2 | 330 | my $TTY = $Is_Rhapsody ? "/dev/ttyp0" : "/dev/tty"; |
cc25fa79 MS |
331 | |
332 | SKIP: { | |
333 | skip "Test uses unixisms", 2 if $Is_MSWin32 || $Is_NetWare; | |
334 | skip "No TTY to test -t with", 2 unless -e $TTY; | |
335 | ||
d5b53b20 | 336 | open(TTY, $TTY) || |
cc25fa79 MS |
337 | warn "Can't open $TTY--run t/TEST outside of make.\n"; |
338 | ok(-t TTY, '-t'); | |
339 | ok(-c TTY, 'tty is -c'); | |
340 | close(TTY); | |
3e3baf6d | 341 | } |
cc25fa79 | 342 | ok(! -t TTY, '!-t on closed TTY filehandle'); |
28e8237b MS |
343 | |
344 | { | |
345 | local $TODO = 'STDIN not a tty when output is to pipe' if $Is_VMS; | |
346 | ok(-t, '-t on STDIN'); | |
347 | } | |
68dc0745 | 348 | } |
cc25fa79 | 349 | |
de5a37b2 | 350 | my $Null = File::Spec->devnull; |
cc25fa79 | 351 | SKIP: { |
de5a37b2 | 352 | skip "No null device to test with", 1 unless -e $Null; |
d5b53b20 | 353 | skip "We know Win32 thinks '$Null' is a TTY", 1 if $Is_MSWin32; |
cc25fa79 | 354 | |
c4fbe247 | 355 | open(NULL, $Null) or DIE("Can't open $Null: $!"); |
de5a37b2 | 356 | ok(! -t NULL, 'null device is not a TTY'); |
cc25fa79 | 357 | close(NULL); |
378cc40b | 358 | } |
cc25fa79 | 359 | |
378cc40b LW |
360 | |
361 | # These aren't strictly "stat" calls, but so what? | |
dc459aad JH |
362 | my $statfile = File::Spec->catfile($Curdir, 'op', 'stat.t'); |
363 | ok( -T $statfile, '-T'); | |
364 | ok(! -B $statfile, '!-B'); | |
378cc40b | 365 | |
95036ac7 JH |
366 | SKIP: { |
367 | skip("DG/UX", 1) if $Is_DGUX; | |
b5fe401b | 368 | ok(-B $Perl, '-B'); |
95036ac7 JH |
369 | } |
370 | ||
b5fe401b | 371 | ok(! -T $Perl, '!-T'); |
378cc40b | 372 | |
dc459aad | 373 | open(FOO,$statfile); |
cc25fa79 MS |
374 | SKIP: { |
375 | eval { -T FOO; }; | |
de5a37b2 | 376 | skip "-T/B on filehandle not implemented", 15 if $@ =~ /not implemented/; |
cc25fa79 MS |
377 | |
378 | is( $@, '', '-T on filehandle causes no errors' ); | |
379 | ||
380 | ok(-T FOO, ' -T'); | |
381 | ok(! -B FOO, ' !-B'); | |
382 | ||
f0fcb552 | 383 | $_ = <FOO>; |
1d662fb6 | 384 | like($_, qr/perl/, 'after readline'); |
cc25fa79 MS |
385 | ok(-T FOO, ' still -T'); |
386 | ok(! -B FOO, ' still -B'); | |
f0fcb552 LW |
387 | close(FOO); |
388 | ||
dc459aad | 389 | open(FOO,$statfile); |
f0fcb552 | 390 | $_ = <FOO>; |
1d662fb6 | 391 | like($_, qr/perl/, 'reopened and after readline'); |
cc25fa79 MS |
392 | ok(-T FOO, ' still -T'); |
393 | ok(! -B FOO, ' still !-B'); | |
394 | ||
395 | ok(seek(FOO,0,0), 'after seek'); | |
de5a37b2 MS |
396 | ok(-T FOO, ' still -T'); |
397 | ok(! -B FOO, ' still !-B'); | |
398 | ||
399 | # It's documented this way in perlfunc *shrug* | |
400 | () = <FOO>; | |
401 | ok(eof FOO, 'at EOF'); | |
402 | ok(-T FOO, ' still -T'); | |
403 | ok(-B FOO, ' now -B'); | |
f0fcb552 LW |
404 | } |
405 | close(FOO); | |
378cc40b | 406 | |
cc25fa79 | 407 | |
de5a37b2 MS |
408 | SKIP: { |
409 | skip "No null device to test with", 2 unless -e $Null; | |
410 | ||
411 | ok(-T $Null, 'null device is -T'); | |
412 | ok(-B $Null, ' and -B'); | |
413 | } | |
cc25fa79 | 414 | |
108ed793 SM |
415 | |
416 | # and now, a few parsing tests: | |
cc25fa79 MS |
417 | $_ = $tmpfile; |
418 | ok(-f, 'bare -f uses $_'); | |
419 | ok(-f(), ' -f() "'); | |
108ed793 | 420 | |
cc25fa79 | 421 | unlink $tmpfile or print "# unlink failed: $!\n"; |
58d95175 RG |
422 | |
423 | # bug id 20011101.069 | |
dc459aad | 424 | my @r = \stat($Curdir); |
cc25fa79 | 425 | is(scalar @r, 13, 'stat returns full 13 elements'); |
5c9aa243 | 426 | |
049f818b YST |
427 | stat $0; |
428 | eval { lstat _ }; | |
429 | like( $@, qr/^The stat preceding lstat\(\) wasn't an lstat/, | |
430 | 'lstat _ croaks after stat' ); | |
431 | eval { -l _ }; | |
432 | like( $@, qr/^The stat preceding -l _ wasn't an lstat/, | |
433 | '-l _ croaks after stat' ); | |
434 | ||
435 | lstat $0; | |
436 | eval { lstat _ }; | |
437 | is( "$@", "", "lstat _ ok after lstat" ); | |
438 | eval { -l _ }; | |
439 | is( "$@", "", "-l _ ok after lstat" ); | |
440 | ||
5c9aa243 | 441 | SKIP: { |
049f818b | 442 | skip "No lstat", 2 unless $Config{d_lstat}; |
5c9aa243 | 443 | |
5c9aa243 RGS |
444 | # bug id 20020124.004 |
445 | # If we have d_lstat, we should have symlink() | |
446 | my $linkname = 'dolzero'; | |
447 | symlink $0, $linkname or die "# Can't symlink $0: $!"; | |
448 | lstat $linkname; | |
449 | -T _; | |
450 | eval { lstat _ }; | |
3db621ff | 451 | like( $@, qr/^The stat preceding lstat\(\) wasn't an lstat/, |
5c9aa243 RGS |
452 | 'lstat croaks after -T _' ); |
453 | eval { -l _ }; | |
3db621ff | 454 | like( $@, qr/^The stat preceding -l _ wasn't an lstat/, |
5c9aa243 RGS |
455 | '-l _ croaks after -T _' ); |
456 | unlink $linkname or print "# unlink $linkname failed: $!\n"; | |
457 | } | |
98a392ec | 458 | |
67fcfcf9 JL |
459 | SKIP: { |
460 | skip "Too much clock skew between system and filesystem", 5 | |
461 | if ($Filesystem_Time_Offset > 5); | |
462 | print "# Zzz...\n"; | |
463 | sleep($Filesystem_Time_Offset+1); | |
464 | my $f = 'tstamp.tmp'; | |
465 | unlink $f; | |
466 | ok (open(S, "> $f"), 'can create tmp file'); | |
467 | close S or die; | |
468 | my @a = stat $f; | |
469 | print "# time=$^T, stat=(@a)\n"; | |
470 | my @b = (-M _, -A _, -C _); | |
471 | print "# -MAC=(@b)\n"; | |
472 | ok( (-M _) < 0, 'negative -M works'); | |
473 | ok( (-A _) < 0, 'negative -A works'); | |
474 | ok( (-C _) < 0, 'negative -C works'); | |
475 | ok(unlink($f), 'unlink tmp file'); | |
476 | } | |
a80d47c2 | 477 | |
25988e07 NE |
478 | { |
479 | ok(open(F, ">", $tmpfile), 'can create temp file'); | |
480 | close F; | |
481 | chmod 0077, $tmpfile; | |
482 | my @a = stat($tmpfile); | |
483 | my $s1 = -s _; | |
484 | -T _; | |
485 | my $s2 = -s _; | |
486 | is($s1, $s2, q(-T _ doesn't break the statbuffer)); | |
8ca3c3a5 | 487 | unlink $tmpfile; |
25988e07 NE |
488 | } |
489 | ||
5228a96c | 490 | SKIP: { |
3497a01f | 491 | skip "No dirfd()", 9 unless $Config{d_dirfd} || $Config{d_dir_dd_fd}; |
586251be SP |
492 | ok(opendir(DIR, "."), 'Can open "." dir') || diag "Can't open '.': $!"; |
493 | ok(stat(DIR), "stat() on dirhandle works"); | |
5228a96c | 494 | ok(-d -r _ , "chained -x's on dirhandle"); |
6d6dd8fe NC |
495 | ok(-d DIR, "-d on a dirhandle works"); |
496 | ||
497 | # And now for the ambigious bareword case | |
498 | ok(open(DIR, "TEST"), 'Can open "TEST" dir') | |
499 | || diag "Can't open 'TEST': $!"; | |
500 | my $size = (stat(DIR))[7]; | |
501 | ok(defined $size, "stat() on bareword works"); | |
502 | is($size, -s "TEST", "size returned by stat of bareword is for the file"); | |
503 | ok(-f _, "ambiguous bareword uses file handle, not dir handle"); | |
504 | ok(-f DIR); | |
505 | closedir DIR or die $!; | |
506 | close DIR or die $!; | |
586251be SP |
507 | } |
508 | ||
509 | { | |
510 | # RT #8244: *FILE{IO} does not behave like *FILE for stat() and -X() operators | |
511 | ok(open(F, ">", $tmpfile), 'can create temp file'); | |
512 | my @thwap = stat *F{IO}; | |
513 | ok(@thwap, "stat(*F{IO}) works"); | |
514 | ok( -f *F{IO} , "single file tests work with *F{IO}"); | |
c84ba4c0 | 515 | close F; |
586251be SP |
516 | unlink $tmpfile; |
517 | ||
518 | #PVIO's hold dirhandle information, so let's test them too. | |
519 | ||
520 | SKIP: { | |
3497a01f | 521 | skip "No dirfd()", 9 unless $Config{d_dirfd} || $Config{d_dir_dd_fd}; |
586251be SP |
522 | ok(opendir(DIR, "."), 'Can open "." dir') || diag "Can't open '.': $!"; |
523 | ok(stat(*DIR{IO}), "stat() on *DIR{IO} works"); | |
20c932f8 | 524 | ok(-d _ , "The special file handle _ is set correctly"); |
586251be | 525 | ok(-d -r *DIR{IO} , "chained -x's on *DIR{IO}"); |
20c932f8 NC |
526 | |
527 | # And now for the ambigious bareword case | |
528 | ok(open(DIR, "TEST"), 'Can open "TEST" dir') | |
529 | || diag "Can't open 'TEST': $!"; | |
530 | my $size = (stat(*DIR{IO}))[7]; | |
531 | ok(defined $size, "stat() on *THINGY{IO} works"); | |
532 | is($size, -s "TEST", | |
533 | "size returned by stat of *THINGY{IO} is for the file"); | |
534 | ok(-f _, "ambiguous *THINGY{IO} uses file handle, not dir handle"); | |
535 | ok(-f *DIR{IO}); | |
536 | closedir DIR or die $!; | |
537 | close DIR or die $!; | |
586251be | 538 | } |
5228a96c SP |
539 | } |
540 | ||
98a392ec | 541 | END { |
295d5f02 | 542 | chmod 0666, $tmpfile; |
98a392ec CB |
543 | 1 while unlink $tmpfile; |
544 | } |