Small VMS nits from Craig A. Berry, <craig.berry@metamor.com>.
[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';
93430cb4 7 unshift @INC, '../lib';
ea368a7c 8}
9
10use Config;
11
80252599 12$Is_Dosish = ($^O eq 'MSWin32' or $^O eq 'dos' or
d493b042 13 $^O eq 'os2' or $^O eq 'mint');
39e571d4 14
6b980173 15if (defined &Win32::IsWinNT && Win32::IsWinNT()) {
16 $Is_Dosish = '' if Win32::FsType() eq 'NTFS';
17}
18
80252599 19print "1..28\n";
8d063cd8 20
68dc0745 21$wd = (($^O eq 'MSWin32') ? `cd` : `pwd`);
378cc40b 22chop($wd);
23
80252599 24if ($^O eq 'MSWin32') { `del tmp 2>nul`; `mkdir tmp`; }
68dc0745 25else { `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`; }
378cc40b 26chdir './tmp';
b8440792 27`/bin/rm -rf a b c x` if -x '/bin/rm';
8d063cd8 28
29umask(022);
30
80252599 31if ($^O eq 'MSWin32') { print "ok 1 # skipped: bogus umask()\n"; }
32elsif ((umask(0)&0777) == 022) {print "ok 1\n";} else {print "not ok 1\n";}
8d063cd8 33open(fh,'>x') || die "Can't create x";
34close(fh);
35open(fh,'>a') || die "Can't create a";
36close(fh);
37
a245ea2d 38if ($Is_Dosish) {print "ok 2 # skipped: no link\n";}
39elsif (eval {link('a','b')}) {print "ok 2\n";}
40else {print "not ok 2\n";}
8d063cd8 41
a245ea2d 42if ($Is_Dosish) {print "ok 3 # skipped: no link\n";}
43elsif (eval {link('b','c')}) {print "ok 3\n";}
44else {print "not ok 3\n";}
8d063cd8 45
46($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
47 $blksize,$blocks) = stat('c');
48
a245ea2d 49if ($Config{dont_use_nlink} || $Is_Dosish)
50 {print "ok 4 # skipped: no link\n";}
51elsif ($nlink == 3)
52 {print "ok 4\n";}
53else {print "not ok 4\n";}
ea368a7c 54
a245ea2d 55if ($^O eq 'amigaos' || $Is_Dosish)
56 {print "ok 5 # skipped: no link\n";}
57elsif (($mode & 0777) == 0666)
58 {print "ok 5\n";}
59else {print "not ok 5\n";}
8d063cd8 60
6b980173 61$newmode = $^O eq 'MSWin32' ? 0444 : 0777;
62if ((chmod $newmode,'a') == 1) {print "ok 6\n";} else {print "not ok 6\n";}
8d063cd8 63
64($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
65 $blksize,$blocks) = stat('c');
a245ea2d 66if ($Is_Dosish) {print "ok 7 # skipped: no link\n";}
6b980173 67elsif (($mode & 0777) == $newmode) {print "ok 7\n";}
a245ea2d 68else {print "not ok 7\n";}
8d063cd8 69
6b980173 70$newmode = 0700;
71if ($^O eq 'MSWin32') {
72 chmod 0444, 'x';
73 $newmode = 0666;
74}
75
a245ea2d 76if ($Is_Dosish) {print "ok 8 # skipped: no link\n";}
6b980173 77elsif ((chmod $newmode,'c','x') == 2) {print "ok 8\n";}
a245ea2d 78else {print "not ok 8\n";}
8d063cd8 79
80($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
81 $blksize,$blocks) = stat('c');
a245ea2d 82if ($Is_Dosish) {print "ok 9 # skipped: no link\n";}
6b980173 83elsif (($mode & 0777) == $newmode) {print "ok 9\n";}
a245ea2d 84else {print "not ok 9\n";}
85
8d063cd8 86($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
87 $blksize,$blocks) = stat('x');
a245ea2d 88if ($Is_Dosish) {print "ok 10 # skipped: no link\n";}
6b980173 89elsif (($mode & 0777) == $newmode) {print "ok 10\n";}
a245ea2d 90else {print "not ok 10\n";}
8d063cd8 91
a245ea2d 92if ($Is_Dosish) {print "ok 11 # skipped: no link\n"; unlink 'b','x'; }
93elsif ((unlink 'b','x') == 2) {print "ok 11\n";}
94else {print "not ok 11\n";}
8d063cd8 95($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
96 $blksize,$blocks) = stat('b');
97if ($ino == 0) {print "ok 12\n";} else {print "not ok 12\n";}
98($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
99 $blksize,$blocks) = stat('x');
100if ($ino == 0) {print "ok 13\n";} else {print "not ok 13\n";}
101
102if (rename('a','b')) {print "ok 14\n";} else {print "not ok 14\n";}
103($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
104 $blksize,$blocks) = stat('a');
105if ($ino == 0) {print "ok 15\n";} else {print "not ok 15\n";}
a245ea2d 106$delta = $Is_Dosish ? 2 : 1; # Granularity of time on the filesystem
107$foo = (utime 500000000,500000000 + $delta,'b');
378cc40b 108if ($foo == 1) {print "ok 16\n";} else {print "not ok 16 $foo\n";}
8d063cd8 109($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
110 $blksize,$blocks) = stat('b');
80252599 111if ($^O eq 'MSWin32') { print "ok 17 # skipped: bogus (stat)[1]\n"; }
112elsif ($ino) {print "ok 17\n";} else {print "not ok 17\n";}
113if ($wd =~ m#/afs/# || $^O eq 'amigaos' || $^O eq 'dos' || $^O eq 'MSWin32')
a245ea2d 114 {print "ok 18 # skipped: granularity of the filetime\n";}
115elsif ($atime == 500000000 && $mtime == 500000000 + $delta)
6eb13c3b 116 {print "ok 18\n";}
117else
118 {print "not ok 18 $atime $mtime\n";}
8d063cd8 119
378cc40b 120if ((unlink 'b') == 1) {print "ok 19\n";} else {print "not ok 19\n";}
8d063cd8 121($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
122 $blksize,$blocks) = stat('b');
378cc40b 123if ($ino == 0) {print "ok 20\n";} else {print "not ok 20\n";}
124unlink 'c';
125
126chdir $wd || die "Can't cd back to $wd";
127
8d063cd8 128unlink 'c';
68dc0745 129if ($^O ne 'MSWin32' and `ls -l perl 2>/dev/null` =~ /^l.*->/) {
130 # we have symbolic links
378cc40b 131 if (symlink("TEST","c")) {print "ok 21\n";} else {print "not ok 21\n";}
132 $foo = `grep perl c`;
133 if ($foo) {print "ok 22\n";} else {print "not ok 22\n";}
44a8e56a 134 unlink 'c';
378cc40b 135}
136else {
137 print "ok 21\nok 22\n";
138}
f783569b 139
140# truncate (may not be implemented everywhere)
141unlink "Iofs.tmp";
142`echo helloworld > Iofs.tmp`;
143eval { truncate "Iofs.tmp", 5; };
144if ($@ =~ /not implemented/) {
145 print "# truncate not implemented -- skipping tests 23 through 26\n";
146 for (23 .. 26) {
147 print "ok $_\n";
148 }
149}
150else {
151 if (-s "Iofs.tmp" == 5) {print "ok 23\n"} else {print "not ok 23\n"}
152 truncate "Iofs.tmp", 0;
153 if (-z "Iofs.tmp") {print "ok 24\n"} else {print "not ok 24\n"}
f783569b 154 open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp";
1bcfde30 155 { select FH; $| = 1; select STDOUT }
bb53490d 156 {
157 use strict;
158 print FH "helloworld\n";
159 truncate FH, 5;
160 }
ed344e4f 161 if ($^O eq 'dos'
162 # Not needed on HPFS, but needed on HPFS386 ?!
163 or $^O eq 'os2')
164 {
39e571d4 165 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
166 }
f783569b 167 if (-s "Iofs.tmp" == 5) {print "ok 25\n"} else {print "not ok 25\n"}
168 truncate FH, 0;
ed344e4f 169 if ($^O eq 'dos'
170 # Not needed on HPFS, but needed on HPFS386 ?!
171 or $^O eq 'os2')
172 {
39e571d4 173 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
174 }
f783569b 175 if (-z "Iofs.tmp") {print "ok 26\n"} else {print "not ok 26\n"}
176 close FH;
177}
80252599 178
179# check if rename() works on directories
180rename 'tmp', 'tmp1' or print "not ";
181print "ok 27\n";
182-d 'tmp1' or print "not ";
183print "ok 28\n";
184
185END { rmdir 'tmp1'; unlink "Iofs.tmp"; }