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 | |
6d738113 |
12 | my $Is_VMSish = ($^O eq 'VMS'); |
2986a63f |
13 | $Is_Dosish = ($^O eq 'MSWin32' or $^O eq 'NetWare' or $^O eq 'dos' or |
c9ff6e92 |
14 | $^O eq 'os2' or $^O eq 'mint' or $^O eq 'cygwin' or |
15 | $^O eq 'mpeix'); |
39e571d4 |
16 | |
6b980173 |
17 | if (defined &Win32::IsWinNT && Win32::IsWinNT()) { |
18 | $Is_Dosish = '' if Win32::FsType() eq 'NTFS'; |
19 | } |
20 | |
65cb15a1 |
21 | print "1..29\n"; |
8d063cd8 |
22 | |
6d738113 |
23 | $wd = ((($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? `cd` : ($Is_VMSish) ? `show default` : `pwd`); |
378cc40b |
24 | chop($wd); |
25 | |
6d738113 |
26 | if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { |
27 | `rmdir /s /q tmp 2>nul`; |
28 | `mkdir tmp`; |
29 | } |
30 | elsif ($Is_VMSish) { |
31 | `if f\$search("[.tmp]*.*") .nes. "" then delete/nolog/noconfirm [.tmp]*.*.*`; |
32 | `if f\$search("tmp.dir") .nes. "" then delete/nolog/noconfirm tmp.dir;`; |
33 | `create/directory [.tmp]`; |
34 | } |
35 | else { |
36 | `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`; |
37 | } |
378cc40b |
38 | chdir './tmp'; |
b8440792 |
39 | `/bin/rm -rf a b c x` if -x '/bin/rm'; |
8d063cd8 |
40 | |
41 | umask(022); |
42 | |
2986a63f |
43 | if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { print "ok 1 # skipped: bogus umask()\n"; } |
80252599 |
44 | elsif ((umask(0)&0777) == 022) {print "ok 1\n";} else {print "not ok 1\n";} |
8d063cd8 |
45 | open(fh,'>x') || die "Can't create x"; |
46 | close(fh); |
47 | open(fh,'>a') || die "Can't create a"; |
48 | close(fh); |
49 | |
6d738113 |
50 | if ($Is_Dosish || $Is_VMSish) {print "ok 2 # skipped: no link\n";} |
a245ea2d |
51 | elsif (eval {link('a','b')}) {print "ok 2\n";} |
52 | else {print "not ok 2\n";} |
8d063cd8 |
53 | |
6d738113 |
54 | if ($Is_Dosish || $Is_VMSish) {print "ok 3 # skipped: no link\n";} |
a245ea2d |
55 | elsif (eval {link('b','c')}) {print "ok 3\n";} |
56 | else {print "not ok 3\n";} |
8d063cd8 |
57 | |
58 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
59 | $blksize,$blocks) = stat('c'); |
60 | |
6d738113 |
61 | if ($Config{dont_use_nlink} || $Is_Dosish || $Is_VMSish) |
a245ea2d |
62 | {print "ok 4 # skipped: no link\n";} |
63 | elsif ($nlink == 3) |
64 | {print "ok 4\n";} |
65 | else {print "not ok 4\n";} |
ea368a7c |
66 | |
6d738113 |
67 | if ($^O eq 'amigaos' || $Is_Dosish || $Is_VMSish) |
a245ea2d |
68 | {print "ok 5 # skipped: no link\n";} |
69 | elsif (($mode & 0777) == 0666) |
70 | {print "ok 5\n";} |
71 | else {print "not ok 5\n";} |
8d063cd8 |
72 | |
2986a63f |
73 | $newmode = (($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? 0444 : 0777; |
6b980173 |
74 | if ((chmod $newmode,'a') == 1) {print "ok 6\n";} else {print "not ok 6\n";} |
8d063cd8 |
75 | |
76 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
77 | $blksize,$blocks) = stat('c'); |
6d738113 |
78 | if ($Is_Dosish || $Is_VMSish) {print "ok 7 # skipped: no link\n";} |
6b980173 |
79 | elsif (($mode & 0777) == $newmode) {print "ok 7\n";} |
a245ea2d |
80 | else {print "not ok 7\n";} |
8d063cd8 |
81 | |
6b980173 |
82 | $newmode = 0700; |
2986a63f |
83 | if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { |
6b980173 |
84 | chmod 0444, 'x'; |
85 | $newmode = 0666; |
86 | } |
87 | |
6d738113 |
88 | if ($Is_Dosish || $Is_VMSish) {print "ok 8 # skipped: no link\n";} |
6b980173 |
89 | elsif ((chmod $newmode,'c','x') == 2) {print "ok 8\n";} |
a245ea2d |
90 | else {print "not ok 8\n";} |
8d063cd8 |
91 | |
92 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
93 | $blksize,$blocks) = stat('c'); |
6d738113 |
94 | if ($Is_Dosish || $Is_VMSish) {print "ok 9 # skipped: no link\n";} |
6b980173 |
95 | elsif (($mode & 0777) == $newmode) {print "ok 9\n";} |
a245ea2d |
96 | else {print "not ok 9\n";} |
97 | |
8d063cd8 |
98 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
99 | $blksize,$blocks) = stat('x'); |
6d738113 |
100 | if ($Is_Dosish || $Is_VMSish) {print "ok 10 # skipped: no link\n";} |
6b980173 |
101 | elsif (($mode & 0777) == $newmode) {print "ok 10\n";} |
a245ea2d |
102 | else {print "not ok 10\n";} |
8d063cd8 |
103 | |
6d738113 |
104 | if ($Is_Dosish || $Is_VMSish) {print "ok 11 # skipped: no link\n"; unlink 'b','x'; } |
a245ea2d |
105 | elsif ((unlink 'b','x') == 2) {print "ok 11\n";} |
106 | else {print "not ok 11\n";} |
8d063cd8 |
107 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
108 | $blksize,$blocks) = stat('b'); |
109 | if ($ino == 0) {print "ok 12\n";} else {print "not ok 12\n";} |
110 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
111 | $blksize,$blocks) = stat('x'); |
112 | if ($ino == 0) {print "ok 13\n";} else {print "not ok 13\n";} |
113 | |
114 | if (rename('a','b')) {print "ok 14\n";} else {print "not ok 14\n";} |
115 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
116 | $blksize,$blocks) = stat('a'); |
117 | if ($ino == 0) {print "ok 15\n";} else {print "not ok 15\n";} |
a245ea2d |
118 | $delta = $Is_Dosish ? 2 : 1; # Granularity of time on the filesystem |
1d825fcc |
119 | chmod 0777, 'b'; |
a245ea2d |
120 | $foo = (utime 500000000,500000000 + $delta,'b'); |
378cc40b |
121 | if ($foo == 1) {print "ok 16\n";} else {print "not ok 16 $foo\n";} |
8d063cd8 |
122 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
123 | $blksize,$blocks) = stat('b'); |
2986a63f |
124 | if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { print "ok 17 # skipped: bogus (stat)[1]\n"; } |
80252599 |
125 | elsif ($ino) {print "ok 17\n";} else {print "not ok 17\n";} |
897bbb29 |
126 | if ($wd =~ m#$Config{'afsroot'}/# || $^O eq 'amigaos' || $^O eq 'dos' || $^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'cygwin') |
a245ea2d |
127 | {print "ok 18 # skipped: granularity of the filetime\n";} |
128 | elsif ($atime == 500000000 && $mtime == 500000000 + $delta) |
6eb13c3b |
129 | {print "ok 18\n";} |
da93fe49 |
130 | elsif ($^O =~ /\blinux\b/i) { |
131 | # Maybe stat() cannot get the correct atime, as happens via NFS on linux? |
132 | $foo = (utime 400000000,500000000 + 2*$delta,'b'); |
133 | my ($new_atime, $new_mtime) = (stat('b'))[8,9]; |
134 | if ($new_atime == $atime && $new_mtime - $mtime == $delta) |
135 | {print "ok 18 # accounted for possible NFS/glibc2.2 bug on linux\n";} |
136 | else |
137 | {print "not ok 18 $atime/$new_atime $mtime/$new_mtime\n";} |
6d738113 |
138 | } |
139 | elsif ($Is_VMSish) { |
140 | if ($atime == 500000001 && $mtime == 500000000 + $delta) |
141 | {print "ok 18\n";} |
142 | else |
143 | {print "not ok 18 $atime $mtime\n";} |
da93fe49 |
144 | } else |
6eb13c3b |
145 | {print "not ok 18 $atime $mtime\n";} |
8d063cd8 |
146 | |
378cc40b |
147 | if ((unlink 'b') == 1) {print "ok 19\n";} else {print "not ok 19\n";} |
8d063cd8 |
148 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
149 | $blksize,$blocks) = stat('b'); |
378cc40b |
150 | if ($ino == 0) {print "ok 20\n";} else {print "not ok 20\n";} |
151 | unlink 'c'; |
152 | |
153 | chdir $wd || die "Can't cd back to $wd"; |
154 | |
8d063cd8 |
155 | unlink 'c'; |
7054c437 |
156 | # Yet another way to look for links (perhaps those that cannot be created by perl?). |
157 | # Hopefully there is an ls utility in your %PATH%. N.B. that $^O is 'cygwin' on Cygwin. |
158 | if ((($^O eq 'MSWin32') || ($^O eq 'NetWare')) and `ls -l perl 2>nul` =~ /^l.*->/) { |
68dc0745 |
159 | # we have symbolic links |
4ba7095c |
160 | system("cp TEST TEST$$"); |
161 | # we have to copy because e.g. GNU grep gets huffy if we have |
162 | # a symlink forest to another disk (it complains about too many |
163 | # levels of symbolic links, even if we have only two) |
164 | if (symlink("TEST$$","c")) {print "ok 21\n";} else {print "not ok 21\n";} |
165 | $foo = `grep perl c 2>&1`; |
378cc40b |
166 | if ($foo) {print "ok 22\n";} else {print "not ok 22\n";} |
44a8e56a |
167 | unlink 'c'; |
4ba7095c |
168 | unlink("TEST$$"); |
378cc40b |
169 | } |
170 | else { |
7054c437 |
171 | if ( ($^O eq 'MSWin32') || ($^O eq 'NetWare') ) { |
172 | print "ok 21 # skipped: no link\nok 22 # skipped: no link\n"; |
173 | } |
174 | else { |
79316e73 |
175 | print "ok 21 # skipped: '$^O' is neither 'MSWin32' nor 'NetWare'\nok 22 # skipped: $^O is neither 'MSWin32' nor 'NetWare'\n"; |
7054c437 |
176 | } |
378cc40b |
177 | } |
f783569b |
178 | |
179 | # truncate (may not be implemented everywhere) |
180 | unlink "Iofs.tmp"; |
6d738113 |
181 | if ($Is_VMSish) { |
182 | open IOFSCOM, ">Iofs.tmp" or die "Could not write IOfs.tmp: $!"; |
183 | print IOFSCOM 'helloworld'; |
184 | close(IOFSCOM); |
185 | } |
186 | else { |
187 | `echo helloworld > Iofs.tmp`; |
188 | } |
189 | # |
190 | # Perhaps the eval would be better written with a construct such as?: |
191 | #if (defined($Config{d_truncate}) && $Config{d_truncate} eq 'define') { |
192 | # |
f783569b |
193 | eval { truncate "Iofs.tmp", 5; }; |
62b86938 |
194 | if ($@) { |
195 | if ($@ =~ /not implemented/) { |
196 | print "# truncate not implemented -- skipping tests 23 through 26\n"; |
197 | for (23 .. 26) { |
198 | print "ok $_ # Skip: no truncate\n"; |
199 | } |
200 | } else { |
201 | warn "io/fs before test 23: truncate dies with \$\@[$@]"; |
f783569b |
202 | } |
203 | } |
204 | else { |
62b86938 |
205 | if (-s "Iofs.tmp" == 5) { |
206 | print "ok 23\n"; |
207 | } else { |
208 | my $s = -s "Iofs.tmp"; |
209 | printf "# -s Iofs.tmp: %s\n", defined($s) ? $s : "UNDEFINED"; |
210 | print "not ok 23\n"; |
211 | } |
f783569b |
212 | truncate "Iofs.tmp", 0; |
213 | if (-z "Iofs.tmp") {print "ok 24\n"} else {print "not ok 24\n"} |
f783569b |
214 | open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp"; |
2f3b6ae4 |
215 | binmode FH; |
1bcfde30 |
216 | { select FH; $| = 1; select STDOUT } |
bb53490d |
217 | { |
218 | use strict; |
2f3b6ae4 |
219 | print FH "x\n" x 200; |
220 | truncate(FH, 200) or die "Can't truncate FH: $!"; |
bb53490d |
221 | } |
ed344e4f |
222 | if ($^O eq 'dos' |
223 | # Not needed on HPFS, but needed on HPFS386 ?! |
224 | or $^O eq 'os2') |
225 | { |
39e571d4 |
226 | close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp"; |
227 | } |
6d738113 |
228 | if (-s "Iofs.tmp" == 200) { |
229 | print "ok 25\n" |
230 | } |
231 | else { |
232 | my $s = -s "Iofs.tmp"; |
233 | printf "# -s Iofs.tmp: %s\n", defined($s) ? $s : "UNDEFINED"; |
234 | print "not ok 25\n"; |
235 | } |
f783569b |
236 | truncate FH, 0; |
ed344e4f |
237 | if ($^O eq 'dos' |
238 | # Not needed on HPFS, but needed on HPFS386 ?! |
239 | or $^O eq 'os2') |
240 | { |
39e571d4 |
241 | close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp"; |
242 | } |
f783569b |
243 | if (-z "Iofs.tmp") {print "ok 26\n"} else {print "not ok 26\n"} |
244 | close FH; |
245 | } |
80252599 |
246 | |
65cb15a1 |
247 | # check if rename() can be used to just change case of filename |
73077d53 |
248 | if ($^O eq 'cygwin') { |
249 | print "ok 27 # skipped: works only if check_case is set to relaxed.\n"; |
250 | } else { |
251 | chdir './tmp'; |
252 | open(fh,'>x') || die "Can't create x"; |
253 | close(fh); |
254 | rename('x', 'X'); |
255 | |
256 | # this works on win32 only, because fs isn't casesensitive |
257 | print 'not ' unless -e 'X'; |
258 | |
259 | print "ok 27\n"; |
260 | unlink 'X'; |
261 | chdir $wd || die "Can't cd back to $wd"; |
262 | } |
65cb15a1 |
263 | |
80252599 |
264 | # check if rename() works on directories |
6d738113 |
265 | if ($Is_VMSish) { |
9df548ee |
266 | # must have delete access to rename a directory |
267 | `set file tmp.dir/protection=o:d`; |
6d738113 |
268 | rename 'tmp.dir', 'tmp1.dir' or print "not "; |
269 | } |
270 | else { |
271 | rename 'tmp', 'tmp1' or print "not "; |
272 | } |
80252599 |
273 | print "ok 28\n"; |
65cb15a1 |
274 | -d 'tmp1' or print "not "; |
275 | print "ok 29\n"; |
80252599 |
276 | |
73077d53 |
277 | # need to remove 'tmp' if rename() in test 28 failed! |
278 | END { rmdir 'tmp1'; rmdir 'tmp'; unlink "Iofs.tmp"; } |