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