Commit | Line | Data |
8d063cd8 |
1 | #!./perl |
2 | |
79072805 |
3 | # $RCSfile: fs.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:28 $ |
8d063cd8 |
4 | |
ea368a7c |
5 | BEGIN { |
6 | chdir 't' if -d 't'; |
20822f61 |
7 | @INC = '../lib'; |
ea368a7c |
8 | } |
9 | |
10 | use 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 |
16 | if (defined &Win32::IsWinNT && Win32::IsWinNT()) { |
17 | $Is_Dosish = '' if Win32::FsType() eq 'NTFS'; |
18 | } |
19 | |
65cb15a1 |
20 | print "1..29\n"; |
8d063cd8 |
21 | |
2986a63f |
22 | $wd = ((($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? `cd` : `pwd`); |
378cc40b |
23 | chop($wd); |
24 | |
2986a63f |
25 | if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { `rmdir /s /q tmp 2>nul`; `mkdir tmp`; } |
68dc0745 |
26 | else { `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`; } |
378cc40b |
27 | chdir './tmp'; |
b8440792 |
28 | `/bin/rm -rf a b c x` if -x '/bin/rm'; |
8d063cd8 |
29 | |
30 | umask(022); |
31 | |
2986a63f |
32 | if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { print "ok 1 # skipped: bogus umask()\n"; } |
80252599 |
33 | elsif ((umask(0)&0777) == 022) {print "ok 1\n";} else {print "not ok 1\n";} |
8d063cd8 |
34 | open(fh,'>x') || die "Can't create x"; |
35 | close(fh); |
36 | open(fh,'>a') || die "Can't create a"; |
37 | close(fh); |
38 | |
a245ea2d |
39 | if ($Is_Dosish) {print "ok 2 # skipped: no link\n";} |
40 | elsif (eval {link('a','b')}) {print "ok 2\n";} |
41 | else {print "not ok 2\n";} |
8d063cd8 |
42 | |
a245ea2d |
43 | if ($Is_Dosish) {print "ok 3 # skipped: no link\n";} |
44 | elsif (eval {link('b','c')}) {print "ok 3\n";} |
45 | else {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 |
50 | if ($Config{dont_use_nlink} || $Is_Dosish) |
51 | {print "ok 4 # skipped: no link\n";} |
52 | elsif ($nlink == 3) |
53 | {print "ok 4\n";} |
54 | else {print "not ok 4\n";} |
ea368a7c |
55 | |
a245ea2d |
56 | if ($^O eq 'amigaos' || $Is_Dosish) |
57 | {print "ok 5 # skipped: no link\n";} |
58 | elsif (($mode & 0777) == 0666) |
59 | {print "ok 5\n";} |
60 | else {print "not ok 5\n";} |
8d063cd8 |
61 | |
2986a63f |
62 | $newmode = (($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? 0444 : 0777; |
6b980173 |
63 | if ((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 |
67 | if ($Is_Dosish) {print "ok 7 # skipped: no link\n";} |
6b980173 |
68 | elsif (($mode & 0777) == $newmode) {print "ok 7\n";} |
a245ea2d |
69 | else {print "not ok 7\n";} |
8d063cd8 |
70 | |
6b980173 |
71 | $newmode = 0700; |
2986a63f |
72 | if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { |
6b980173 |
73 | chmod 0444, 'x'; |
74 | $newmode = 0666; |
75 | } |
76 | |
a245ea2d |
77 | if ($Is_Dosish) {print "ok 8 # skipped: no link\n";} |
6b980173 |
78 | elsif ((chmod $newmode,'c','x') == 2) {print "ok 8\n";} |
a245ea2d |
79 | else {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 |
83 | if ($Is_Dosish) {print "ok 9 # skipped: no link\n";} |
6b980173 |
84 | elsif (($mode & 0777) == $newmode) {print "ok 9\n";} |
a245ea2d |
85 | else {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 |
89 | if ($Is_Dosish) {print "ok 10 # skipped: no link\n";} |
6b980173 |
90 | elsif (($mode & 0777) == $newmode) {print "ok 10\n";} |
a245ea2d |
91 | else {print "not ok 10\n";} |
8d063cd8 |
92 | |
a245ea2d |
93 | if ($Is_Dosish) {print "ok 11 # skipped: no link\n"; unlink 'b','x'; } |
94 | elsif ((unlink 'b','x') == 2) {print "ok 11\n";} |
95 | else {print "not ok 11\n";} |
8d063cd8 |
96 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
97 | $blksize,$blocks) = stat('b'); |
98 | if ($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'); |
101 | if ($ino == 0) {print "ok 13\n";} else {print "not ok 13\n";} |
102 | |
103 | if (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'); |
106 | if ($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 |
108 | chmod 0777, 'b'; |
a245ea2d |
109 | $foo = (utime 500000000,500000000 + $delta,'b'); |
378cc40b |
110 | if ($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 |
113 | if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { print "ok 17 # skipped: bogus (stat)[1]\n"; } |
80252599 |
114 | elsif ($ino) {print "ok 17\n";} else {print "not ok 17\n";} |
897bbb29 |
115 | if ($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";} |
117 | elsif ($atime == 500000000 && $mtime == 500000000 + $delta) |
6eb13c3b |
118 | {print "ok 18\n";} |
da93fe49 |
119 | elsif ($^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 |
130 | if ((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 |
133 | if ($ino == 0) {print "ok 20\n";} else {print "not ok 20\n";} |
134 | unlink 'c'; |
135 | |
136 | chdir $wd || die "Can't cd back to $wd"; |
137 | |
8d063cd8 |
138 | unlink 'c'; |
7054c437 |
139 | # Yet another way to look for links (perhaps those that cannot be created by perl?). |
140 | # Hopefully there is an ls utility in your %PATH%. N.B. that $^O is 'cygwin' on Cygwin. |
141 | if ((($^O eq 'MSWin32') || ($^O eq 'NetWare')) and `ls -l perl 2>nul` =~ /^l.*->/) { |
68dc0745 |
142 | # we have symbolic links |
4ba7095c |
143 | system("cp TEST TEST$$"); |
144 | # we have to copy because e.g. GNU grep gets huffy if we have |
145 | # a symlink forest to another disk (it complains about too many |
146 | # levels of symbolic links, even if we have only two) |
147 | if (symlink("TEST$$","c")) {print "ok 21\n";} else {print "not ok 21\n";} |
148 | $foo = `grep perl c 2>&1`; |
378cc40b |
149 | if ($foo) {print "ok 22\n";} else {print "not ok 22\n";} |
44a8e56a |
150 | unlink 'c'; |
4ba7095c |
151 | unlink("TEST$$"); |
378cc40b |
152 | } |
153 | else { |
7054c437 |
154 | if ( ($^O eq 'MSWin32') || ($^O eq 'NetWare') ) { |
155 | print "ok 21 # skipped: no link\nok 22 # skipped: no link\n"; |
156 | } |
157 | else { |
158 | print "ok 21 # skipped: $^O is neither 'MSWin32' nor 'NetWare'\nok 22 # skipped: $^O is neither 'MSWin32' nor 'NetWare'\n"; |
159 | } |
378cc40b |
160 | } |
f783569b |
161 | |
162 | # truncate (may not be implemented everywhere) |
163 | unlink "Iofs.tmp"; |
164 | `echo helloworld > Iofs.tmp`; |
165 | eval { truncate "Iofs.tmp", 5; }; |
62b86938 |
166 | if ($@) { |
167 | if ($@ =~ /not implemented/) { |
168 | print "# truncate not implemented -- skipping tests 23 through 26\n"; |
169 | for (23 .. 26) { |
170 | print "ok $_ # Skip: no truncate\n"; |
171 | } |
172 | } else { |
173 | warn "io/fs before test 23: truncate dies with \$\@[$@]"; |
f783569b |
174 | } |
175 | } |
176 | else { |
62b86938 |
177 | if (-s "Iofs.tmp" == 5) { |
178 | print "ok 23\n"; |
179 | } else { |
180 | my $s = -s "Iofs.tmp"; |
181 | printf "# -s Iofs.tmp: %s\n", defined($s) ? $s : "UNDEFINED"; |
182 | print "not ok 23\n"; |
183 | } |
f783569b |
184 | truncate "Iofs.tmp", 0; |
185 | if (-z "Iofs.tmp") {print "ok 24\n"} else {print "not ok 24\n"} |
f783569b |
186 | open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp"; |
2f3b6ae4 |
187 | binmode FH; |
1bcfde30 |
188 | { select FH; $| = 1; select STDOUT } |
bb53490d |
189 | { |
190 | use strict; |
2f3b6ae4 |
191 | print FH "x\n" x 200; |
192 | truncate(FH, 200) or die "Can't truncate FH: $!"; |
bb53490d |
193 | } |
ed344e4f |
194 | if ($^O eq 'dos' |
195 | # Not needed on HPFS, but needed on HPFS386 ?! |
196 | or $^O eq 'os2') |
197 | { |
39e571d4 |
198 | close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp"; |
199 | } |
2f3b6ae4 |
200 | if (-s "Iofs.tmp" == 200) {print "ok 25\n"} else {print "not ok 25\n"} |
f783569b |
201 | truncate FH, 0; |
ed344e4f |
202 | if ($^O eq 'dos' |
203 | # Not needed on HPFS, but needed on HPFS386 ?! |
204 | or $^O eq 'os2') |
205 | { |
39e571d4 |
206 | close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp"; |
207 | } |
f783569b |
208 | if (-z "Iofs.tmp") {print "ok 26\n"} else {print "not ok 26\n"} |
209 | close FH; |
210 | } |
80252599 |
211 | |
65cb15a1 |
212 | # check if rename() can be used to just change case of filename |
213 | chdir './tmp'; |
214 | open(fh,'>x') || die "Can't create x"; |
215 | close(fh); |
216 | rename('x', 'X'); |
217 | print 'not ' unless -e 'X'; |
218 | print "ok 27\n"; |
219 | unlink 'X'; |
220 | chdir $wd || die "Can't cd back to $wd"; |
221 | |
80252599 |
222 | # check if rename() works on directories |
223 | rename 'tmp', 'tmp1' or print "not "; |
80252599 |
224 | print "ok 28\n"; |
65cb15a1 |
225 | -d 'tmp1' or print "not "; |
226 | print "ok 29\n"; |
80252599 |
227 | |
228 | END { rmdir 'tmp1'; unlink "Iofs.tmp"; } |