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