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