Typo in #11432.
[p5sagit/p5-mst-13.2.git] / t / io / fs.t
CommitLineData
8d063cd8 1#!./perl
2
79072805 3# $RCSfile: fs.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:28 $
8d063cd8 4
ea368a7c 5BEGIN {
6 chdir 't' if -d 't';
20822f61 7 @INC = '../lib';
ea368a7c 8}
9
10use Config;
11
2986a63f 12$Is_Dosish = ($^O eq 'MSWin32' or $^O eq 'NetWare' or $^O eq 'dos' or
c9ff6e92 13 $^O eq 'os2' or $^O eq 'mint' or $^O eq 'cygwin' or
14 $^O eq 'mpeix');
39e571d4 15
6b980173 16if (defined &Win32::IsWinNT && Win32::IsWinNT()) {
17 $Is_Dosish = '' if Win32::FsType() eq 'NTFS';
18}
19
65cb15a1 20print "1..29\n";
8d063cd8 21
2986a63f 22$wd = ((($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? `cd` : `pwd`);
378cc40b 23chop($wd);
24
2986a63f 25if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { `rmdir /s /q tmp 2>nul`; `mkdir tmp`; }
68dc0745 26else { `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`; }
378cc40b 27chdir './tmp';
b8440792 28`/bin/rm -rf a b c x` if -x '/bin/rm';
8d063cd8 29
30umask(022);
31
2986a63f 32if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { print "ok 1 # skipped: bogus umask()\n"; }
80252599 33elsif ((umask(0)&0777) == 022) {print "ok 1\n";} else {print "not ok 1\n";}
8d063cd8 34open(fh,'>x') || die "Can't create x";
35close(fh);
36open(fh,'>a') || die "Can't create a";
37close(fh);
38
a245ea2d 39if ($Is_Dosish) {print "ok 2 # skipped: no link\n";}
40elsif (eval {link('a','b')}) {print "ok 2\n";}
41else {print "not ok 2\n";}
8d063cd8 42
a245ea2d 43if ($Is_Dosish) {print "ok 3 # skipped: no link\n";}
44elsif (eval {link('b','c')}) {print "ok 3\n";}
45else {print "not ok 3\n";}
8d063cd8 46
47($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
48 $blksize,$blocks) = stat('c');
49
a245ea2d 50if ($Config{dont_use_nlink} || $Is_Dosish)
51 {print "ok 4 # skipped: no link\n";}
52elsif ($nlink == 3)
53 {print "ok 4\n";}
54else {print "not ok 4\n";}
ea368a7c 55
a245ea2d 56if ($^O eq 'amigaos' || $Is_Dosish)
57 {print "ok 5 # skipped: no link\n";}
58elsif (($mode & 0777) == 0666)
59 {print "ok 5\n";}
60else {print "not ok 5\n";}
8d063cd8 61
2986a63f 62$newmode = (($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? 0444 : 0777;
6b980173 63if ((chmod $newmode,'a') == 1) {print "ok 6\n";} else {print "not ok 6\n";}
8d063cd8 64
65($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
66 $blksize,$blocks) = stat('c');
a245ea2d 67if ($Is_Dosish) {print "ok 7 # skipped: no link\n";}
6b980173 68elsif (($mode & 0777) == $newmode) {print "ok 7\n";}
a245ea2d 69else {print "not ok 7\n";}
8d063cd8 70
6b980173 71$newmode = 0700;
2986a63f 72if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
6b980173 73 chmod 0444, 'x';
74 $newmode = 0666;
75}
76
a245ea2d 77if ($Is_Dosish) {print "ok 8 # skipped: no link\n";}
6b980173 78elsif ((chmod $newmode,'c','x') == 2) {print "ok 8\n";}
a245ea2d 79else {print "not ok 8\n";}
8d063cd8 80
81($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
82 $blksize,$blocks) = stat('c');
a245ea2d 83if ($Is_Dosish) {print "ok 9 # skipped: no link\n";}
6b980173 84elsif (($mode & 0777) == $newmode) {print "ok 9\n";}
a245ea2d 85else {print "not ok 9\n";}
86
8d063cd8 87($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
88 $blksize,$blocks) = stat('x');
a245ea2d 89if ($Is_Dosish) {print "ok 10 # skipped: no link\n";}
6b980173 90elsif (($mode & 0777) == $newmode) {print "ok 10\n";}
a245ea2d 91else {print "not ok 10\n";}
8d063cd8 92
a245ea2d 93if ($Is_Dosish) {print "ok 11 # skipped: no link\n"; unlink 'b','x'; }
94elsif ((unlink 'b','x') == 2) {print "ok 11\n";}
95else {print "not ok 11\n";}
8d063cd8 96($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
97 $blksize,$blocks) = stat('b');
98if ($ino == 0) {print "ok 12\n";} else {print "not ok 12\n";}
99($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
100 $blksize,$blocks) = stat('x');
101if ($ino == 0) {print "ok 13\n";} else {print "not ok 13\n";}
102
103if (rename('a','b')) {print "ok 14\n";} else {print "not ok 14\n";}
104($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
105 $blksize,$blocks) = stat('a');
106if ($ino == 0) {print "ok 15\n";} else {print "not ok 15\n";}
a245ea2d 107$delta = $Is_Dosish ? 2 : 1; # Granularity of time on the filesystem
1d825fcc 108chmod 0777, 'b';
a245ea2d 109$foo = (utime 500000000,500000000 + $delta,'b');
378cc40b 110if ($foo == 1) {print "ok 16\n";} else {print "not ok 16 $foo\n";}
8d063cd8 111($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
112 $blksize,$blocks) = stat('b');
2986a63f 113if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { print "ok 17 # skipped: bogus (stat)[1]\n"; }
80252599 114elsif ($ino) {print "ok 17\n";} else {print "not ok 17\n";}
897bbb29 115if ($wd =~ m#$Config{'afsroot'}/# || $^O eq 'amigaos' || $^O eq 'dos' || $^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'cygwin')
a245ea2d 116 {print "ok 18 # skipped: granularity of the filetime\n";}
117elsif ($atime == 500000000 && $mtime == 500000000 + $delta)
6eb13c3b 118 {print "ok 18\n";}
da93fe49 119elsif ($^O =~ /\blinux\b/i) {
120 # Maybe stat() cannot get the correct atime, as happens via NFS on linux?
121 $foo = (utime 400000000,500000000 + 2*$delta,'b');
122 my ($new_atime, $new_mtime) = (stat('b'))[8,9];
123 if ($new_atime == $atime && $new_mtime - $mtime == $delta)
124 {print "ok 18 # accounted for possible NFS/glibc2.2 bug on linux\n";}
125 else
126 {print "not ok 18 $atime/$new_atime $mtime/$new_mtime\n";}
127} else
6eb13c3b 128 {print "not ok 18 $atime $mtime\n";}
8d063cd8 129
378cc40b 130if ((unlink 'b') == 1) {print "ok 19\n";} else {print "not ok 19\n";}
8d063cd8 131($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
132 $blksize,$blocks) = stat('b');
378cc40b 133if ($ino == 0) {print "ok 20\n";} else {print "not ok 20\n";}
134unlink 'c';
135
136chdir $wd || die "Can't cd back to $wd";
137
8d063cd8 138unlink 'c';
2986a63f 139if ((($^O eq 'MSWin32') || ($^O eq 'NetWare')) and `ls -l perl 2>/dev/null` =~ /^l.*->/) {
68dc0745 140 # we have symbolic links
4ba7095c 141 system("cp TEST TEST$$");
142 # we have to copy because e.g. GNU grep gets huffy if we have
143 # a symlink forest to another disk (it complains about too many
144 # levels of symbolic links, even if we have only two)
145 if (symlink("TEST$$","c")) {print "ok 21\n";} else {print "not ok 21\n";}
146 $foo = `grep perl c 2>&1`;
378cc40b 147 if ($foo) {print "ok 22\n";} else {print "not ok 22\n";}
44a8e56a 148 unlink 'c';
4ba7095c 149 unlink("TEST$$");
378cc40b 150}
151else {
152 print "ok 21\nok 22\n";
153}
f783569b 154
155# truncate (may not be implemented everywhere)
156unlink "Iofs.tmp";
157`echo helloworld > Iofs.tmp`;
158eval { truncate "Iofs.tmp", 5; };
62b86938 159if ($@) {
160 if ($@ =~ /not implemented/) {
161 print "# truncate not implemented -- skipping tests 23 through 26\n";
162 for (23 .. 26) {
163 print "ok $_ # Skip: no truncate\n";
164 }
165 } else {
166 warn "io/fs before test 23: truncate dies with \$\@[$@]";
f783569b 167 }
168}
169else {
62b86938 170 if (-s "Iofs.tmp" == 5) {
171 print "ok 23\n";
172 } else {
173 my $s = -s "Iofs.tmp";
174 printf "# -s Iofs.tmp: %s\n", defined($s) ? $s : "UNDEFINED";
175 print "not ok 23\n";
176 }
f783569b 177 truncate "Iofs.tmp", 0;
178 if (-z "Iofs.tmp") {print "ok 24\n"} else {print "not ok 24\n"}
f783569b 179 open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp";
2f3b6ae4 180 binmode FH;
1bcfde30 181 { select FH; $| = 1; select STDOUT }
bb53490d 182 {
183 use strict;
2f3b6ae4 184 print FH "x\n" x 200;
185 truncate(FH, 200) or die "Can't truncate FH: $!";
bb53490d 186 }
ed344e4f 187 if ($^O eq 'dos'
188 # Not needed on HPFS, but needed on HPFS386 ?!
189 or $^O eq 'os2')
190 {
39e571d4 191 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
192 }
2f3b6ae4 193 if (-s "Iofs.tmp" == 200) {print "ok 25\n"} else {print "not ok 25\n"}
f783569b 194 truncate FH, 0;
ed344e4f 195 if ($^O eq 'dos'
196 # Not needed on HPFS, but needed on HPFS386 ?!
197 or $^O eq 'os2')
198 {
39e571d4 199 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
200 }
f783569b 201 if (-z "Iofs.tmp") {print "ok 26\n"} else {print "not ok 26\n"}
202 close FH;
203}
80252599 204
65cb15a1 205# check if rename() can be used to just change case of filename
206chdir './tmp';
207open(fh,'>x') || die "Can't create x";
208close(fh);
209rename('x', 'X');
210print 'not ' unless -e 'X';
211print "ok 27\n";
212unlink 'X';
213chdir $wd || die "Can't cd back to $wd";
214
80252599 215# check if rename() works on directories
216rename 'tmp', 'tmp1' or print "not ";
80252599 217print "ok 28\n";
65cb15a1 218-d 'tmp1' or print "not ";
219print "ok 29\n";
80252599 220
221END { rmdir 'tmp1'; unlink "Iofs.tmp"; }