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