Major changes to the DOS/djgpp port (including threading):
[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';
7 @INC = '../lib';
8}
9
10use Config;
11
39e571d4 12$Is_Dos=$^O eq 'dos';
13
5aabfad6 14# avoid win32 (for now)
15do { print "1..0\n"; exit(0); } if $^O eq 'MSWin32';
16
f783569b 17print "1..26\n";
8d063cd8 18
68dc0745 19$wd = (($^O eq 'MSWin32') ? `cd` : `pwd`);
378cc40b 20chop($wd);
21
68dc0745 22if ($^O eq 'MSWin32') { `del tmp`; `mkdir tmp`; }
23else { `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`; }
378cc40b 24chdir './tmp';
b8440792 25`/bin/rm -rf a b c x` if -x '/bin/rm';
8d063cd8 26
27umask(022);
28
e334a159 29if ((umask(0)&0777) == 022) {print "ok 1\n";} else {print "not ok 1\n";}
8d063cd8 30open(fh,'>x') || die "Can't create x";
31close(fh);
32open(fh,'>a') || die "Can't create a";
33close(fh);
34
39e571d4 35if (eval {link('a','b')} || $Is_Dos) {print "ok 2\n";} else {print "not ok 2\n";}
8d063cd8 36
39e571d4 37if (eval {link('b','c')} || $Is_Dos) {print "ok 3\n";} else {print "not ok 3\n";}
8d063cd8 38
39($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
40 $blksize,$blocks) = stat('c');
41
39e571d4 42if ($Config{dont_use_nlink} || $nlink == 3 || $Is_Dos)
ea368a7c 43 {print "ok 4\n";} else {print "not ok 4\n";}
44
39e571d4 45if (($mode & 0777) == 0666 || $^O eq 'amigaos' || $Is_Dos)
b971f6e4 46 {print "ok 5\n";} else {print "not ok 5\n";}
8d063cd8 47
48if ((chmod 0777,'a') == 1) {print "ok 6\n";} else {print "not ok 6\n";}
49
50($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
51 $blksize,$blocks) = stat('c');
39e571d4 52if (($mode & 0777) == 0777 || $Is_Dos) {print "ok 7\n";} else {print "not ok 7\n";}
8d063cd8 53
39e571d4 54if ((chmod 0700,'c','x') == 2 || $Is_Dos) {print "ok 8\n";} else {print "not ok 8\n";}
8d063cd8 55
56($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
57 $blksize,$blocks) = stat('c');
39e571d4 58if (($mode & 0777) == 0700 || $Is_Dos) {print "ok 9\n";} else {print "not ok 9\n";}
8d063cd8 59($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
60 $blksize,$blocks) = stat('x');
39e571d4 61if (($mode & 0777) == 0700 || $Is_Dos) {print "ok 10\n";} else {print "not ok 10\n";}
8d063cd8 62
39e571d4 63if ((unlink 'b','x') == 2 || $Is_Dos) {print "ok 11\n";} else {print "not ok 11\n";}
8d063cd8 64($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
65 $blksize,$blocks) = stat('b');
66if ($ino == 0) {print "ok 12\n";} else {print "not ok 12\n";}
67($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
68 $blksize,$blocks) = stat('x');
69if ($ino == 0) {print "ok 13\n";} else {print "not ok 13\n";}
70
71if (rename('a','b')) {print "ok 14\n";} else {print "not ok 14\n";}
72($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
73 $blksize,$blocks) = stat('a');
74if ($ino == 0) {print "ok 15\n";} else {print "not ok 15\n";}
a687059c 75$foo = (utime 500000000,500000001,'b');
378cc40b 76if ($foo == 1) {print "ok 16\n";} else {print "not ok 16 $foo\n";}
8d063cd8 77($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
78 $blksize,$blocks) = stat('b');
378cc40b 79if ($ino) {print "ok 17\n";} else {print "not ok 17\n";}
b971f6e4 80if (($atime == 500000000 && $mtime == 500000001)
39e571d4 81 || $wd =~ m#/afs/# || $^O eq 'amigaos' || $Is_Dos)
6eb13c3b 82 {print "ok 18\n";}
83else
84 {print "not ok 18 $atime $mtime\n";}
8d063cd8 85
378cc40b 86if ((unlink 'b') == 1) {print "ok 19\n";} else {print "not ok 19\n";}
8d063cd8 87($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
88 $blksize,$blocks) = stat('b');
378cc40b 89if ($ino == 0) {print "ok 20\n";} else {print "not ok 20\n";}
90unlink 'c';
91
92chdir $wd || die "Can't cd back to $wd";
44a8e56a 93rmdir 'tmp';
378cc40b 94
8d063cd8 95unlink 'c';
68dc0745 96if ($^O ne 'MSWin32' and `ls -l perl 2>/dev/null` =~ /^l.*->/) {
97 # we have symbolic links
378cc40b 98 if (symlink("TEST","c")) {print "ok 21\n";} else {print "not ok 21\n";}
99 $foo = `grep perl c`;
100 if ($foo) {print "ok 22\n";} else {print "not ok 22\n";}
44a8e56a 101 unlink 'c';
378cc40b 102}
103else {
104 print "ok 21\nok 22\n";
105}
f783569b 106
107# truncate (may not be implemented everywhere)
108unlink "Iofs.tmp";
109`echo helloworld > Iofs.tmp`;
110eval { truncate "Iofs.tmp", 5; };
111if ($@ =~ /not implemented/) {
112 print "# truncate not implemented -- skipping tests 23 through 26\n";
113 for (23 .. 26) {
114 print "ok $_\n";
115 }
116}
117else {
118 if (-s "Iofs.tmp" == 5) {print "ok 23\n"} else {print "not ok 23\n"}
119 truncate "Iofs.tmp", 0;
120 if (-z "Iofs.tmp") {print "ok 24\n"} else {print "not ok 24\n"}
f783569b 121 open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp";
1bcfde30 122 { select FH; $| = 1; select STDOUT }
123 print FH "helloworld\n";
f783569b 124 truncate FH, 5;
39e571d4 125 if ($Is_Dos) {
126 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
127 }
f783569b 128 if (-s "Iofs.tmp" == 5) {print "ok 25\n"} else {print "not ok 25\n"}
129 truncate FH, 0;
39e571d4 130 if ($Is_Dos) {
131 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
132 }
f783569b 133 if (-z "Iofs.tmp") {print "ok 26\n"} else {print "not ok 26\n"}
134 close FH;
135}
136unlink "Iofs.tmp";