This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
integrate cfgperl changes into mainline
[perl5.git] / t / io / fs.t
CommitLineData
8d063cd8
LW
1#!./perl
2
79072805 3# $RCSfile: fs.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:28 $
8d063cd8 4
ea368a7c
CS
5BEGIN {
6 chdir 't' if -d 't';
7 @INC = '../lib';
8}
9
10use Config;
11
61ae2fbf 12$Is_Dosish = ($^O eq 'dos' or $^O eq 'os2' or $^O eq 'mint');
39e571d4 13
5aabfad6
PP
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
LW
20chop($wd);
21
68dc0745
PP
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
LW
26
27umask(022);
28
e334a159 29if ((umask(0)&0777) == 022) {print "ok 1\n";} else {print "not ok 1\n";}
8d063cd8
LW
30open(fh,'>x') || die "Can't create x";
31close(fh);
32open(fh,'>a') || die "Can't create a";
33close(fh);
34
a245ea2d
IZ
35if ($Is_Dosish) {print "ok 2 # skipped: no link\n";}
36elsif (eval {link('a','b')}) {print "ok 2\n";}
37else {print "not ok 2\n";}
8d063cd8 38
a245ea2d
IZ
39if ($Is_Dosish) {print "ok 3 # skipped: no link\n";}
40elsif (eval {link('b','c')}) {print "ok 3\n";}
41else {print "not ok 3\n";}
8d063cd8
LW
42
43($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
44 $blksize,$blocks) = stat('c');
45
a245ea2d
IZ
46if ($Config{dont_use_nlink} || $Is_Dosish)
47 {print "ok 4 # skipped: no link\n";}
48elsif ($nlink == 3)
49 {print "ok 4\n";}
50else {print "not ok 4\n";}
ea368a7c 51
a245ea2d
IZ
52if ($^O eq 'amigaos' || $Is_Dosish)
53 {print "ok 5 # skipped: no link\n";}
54elsif (($mode & 0777) == 0666)
55 {print "ok 5\n";}
56else {print "not ok 5\n";}
8d063cd8
LW
57
58if ((chmod 0777,'a') == 1) {print "ok 6\n";} else {print "not ok 6\n";}
59
60($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
61 $blksize,$blocks) = stat('c');
a245ea2d
IZ
62if ($Is_Dosish) {print "ok 7 # skipped: no link\n";}
63elsif (($mode & 0777) == 0777) {print "ok 7\n";}
64else {print "not ok 7\n";}
8d063cd8 65
a245ea2d
IZ
66if ($Is_Dosish) {print "ok 8 # skipped: no link\n";}
67elsif ((chmod 0700,'c','x') == 2) {print "ok 8\n";}
68else {print "not ok 8\n";}
8d063cd8
LW
69
70($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
71 $blksize,$blocks) = stat('c');
a245ea2d
IZ
72if ($Is_Dosish) {print "ok 9 # skipped: no link\n";}
73elsif (($mode & 0777) == 0700) {print "ok 9\n";}
74else {print "not ok 9\n";}
75
8d063cd8
LW
76($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
77 $blksize,$blocks) = stat('x');
a245ea2d
IZ
78if ($Is_Dosish) {print "ok 10 # skipped: no link\n";}
79elsif (($mode & 0777) == 0700) {print "ok 10\n";}
80else {print "not ok 10\n";}
8d063cd8 81
a245ea2d
IZ
82if ($Is_Dosish) {print "ok 11 # skipped: no link\n"; unlink 'b','x'; }
83elsif ((unlink 'b','x') == 2) {print "ok 11\n";}
84else {print "not ok 11\n";}
8d063cd8
LW
85($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
86 $blksize,$blocks) = stat('b');
87if ($ino == 0) {print "ok 12\n";} else {print "not ok 12\n";}
88($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
89 $blksize,$blocks) = stat('x');
90if ($ino == 0) {print "ok 13\n";} else {print "not ok 13\n";}
91
92if (rename('a','b')) {print "ok 14\n";} else {print "not ok 14\n";}
93($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
94 $blksize,$blocks) = stat('a');
95if ($ino == 0) {print "ok 15\n";} else {print "not ok 15\n";}
a245ea2d
IZ
96$delta = $Is_Dosish ? 2 : 1; # Granularity of time on the filesystem
97$foo = (utime 500000000,500000000 + $delta,'b');
378cc40b 98if ($foo == 1) {print "ok 16\n";} else {print "not ok 16 $foo\n";}
8d063cd8
LW
99($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
100 $blksize,$blocks) = stat('b');
378cc40b 101if ($ino) {print "ok 17\n";} else {print "not ok 17\n";}
891521e2 102if ($wd =~ m#/afs/# || $^O eq 'amigaos' || $^O eq 'dos')
a245ea2d
IZ
103 {print "ok 18 # skipped: granularity of the filetime\n";}
104elsif ($atime == 500000000 && $mtime == 500000000 + $delta)
6eb13c3b
LW
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
LW
110($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
111 $blksize,$blocks) = stat('b');
378cc40b
LW
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";
44a8e56a 116rmdir 'tmp';
378cc40b 117
8d063cd8 118unlink 'c';
68dc0745
PP
119if ($^O ne 'MSWin32' and `ls -l perl 2>/dev/null` =~ /^l.*->/) {
120 # we have symbolic links
378cc40b
LW
121 if (symlink("TEST","c")) {print "ok 21\n";} else {print "not ok 21\n";}
122 $foo = `grep perl c`;
123 if ($foo) {print "ok 22\n";} else {print "not ok 22\n";}
44a8e56a 124 unlink 'c';
378cc40b
LW
125}
126else {
127 print "ok 21\nok 22\n";
128}
f783569b
PP
129
130# truncate (may not be implemented everywhere)
131unlink "Iofs.tmp";
132`echo helloworld > Iofs.tmp`;
133eval { truncate "Iofs.tmp", 5; };
134if ($@ =~ /not implemented/) {
135 print "# truncate not implemented -- skipping tests 23 through 26\n";
136 for (23 .. 26) {
137 print "ok $_\n";
138 }
139}
140else {
141 if (-s "Iofs.tmp" == 5) {print "ok 23\n"} else {print "not ok 23\n"}
142 truncate "Iofs.tmp", 0;
143 if (-z "Iofs.tmp") {print "ok 24\n"} else {print "not ok 24\n"}
f783569b 144 open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp";
1bcfde30
CS
145 { select FH; $| = 1; select STDOUT }
146 print FH "helloworld\n";
f783569b 147 truncate FH, 5;
a245ea2d 148 if ($^O eq 'dos') {
39e571d4
ML
149 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
150 }
f783569b
PP
151 if (-s "Iofs.tmp" == 5) {print "ok 25\n"} else {print "not ok 25\n"}
152 truncate FH, 0;
a245ea2d 153 if ($^O eq 'dos') {
39e571d4
ML
154 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
155 }
f783569b
PP
156 if (-z "Iofs.tmp") {print "ok 26\n"} else {print "not ok 26\n"}
157 close FH;
158}
159unlink "Iofs.tmp";