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