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