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