perl 3.0 patch #32 patch #29, continued
[p5sagit/p5-mst-13.2.git] / t / op.stat
CommitLineData
8d063cd8 1#!./perl
2
d9d8d8de 3# $Header: op.stat,v 3.0.1.5 90/10/16 10:55:42 lwall Locked $
8d063cd8 4
378cc40b 5print "1..56\n";
8d063cd8 6
6eb13c3b 7chop($cwd = `pwd`);
8
a687059c 9unlink "Op.stat.tmp";
8d063cd8 10open(foo, ">Op.stat.tmp");
11
12($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
13 $blksize,$blocks) = stat(foo);
14if ($nlink == 1) {print "ok 1\n";} else {print "not ok 1\n";}
15if ($mtime && $mtime == $ctime) {print "ok 2\n";} else {print "not ok 2\n";}
16
17print foo "Now is the time for all good men to come to.\n";
18close(foo);
19
0d3e774c 20sleep 2;
8d063cd8 21
22`rm -f Op.stat.tmp2; ln Op.stat.tmp Op.stat.tmp2; chmod 644 Op.stat.tmp`;
23
24($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
25 $blksize,$blocks) = stat('Op.stat.tmp');
26
27if ($nlink == 2) {print "ok 3\n";} else {print "not ok 3\n";}
6eb13c3b 28if (($mtime && $mtime != $ctime) || $cwd =~ m#/afs/#) {
29 print "ok 4\n";
30}
31else {
32 print "not ok 4\n";
33}
8d063cd8 34print "#4 :$mtime: != :$ctime:\n";
35
378cc40b 36`cp /dev/null Op.stat.tmp`;
37
38if (-z 'Op.stat.tmp') {print "ok 5\n";} else {print "not ok 5\n";}
39if (! -s 'Op.stat.tmp') {print "ok 6\n";} else {print "not ok 6\n";}
40
41`echo hi >Op.stat.tmp`;
42if (! -z 'Op.stat.tmp') {print "ok 7\n";} else {print "not ok 7\n";}
43if (-s 'Op.stat.tmp') {print "ok 8\n";} else {print "not ok 8\n";}
44
45chmod 0,'Op.stat.tmp';
46$olduid = $>; # can't test -r if uid == 0
47eval '$> = 1;'; # so switch uid (may not be implemented)
48if (!$> || ! -r 'Op.stat.tmp') {print "ok 9\n";} else {print "not ok 9\n";}
49if (!$> || ! -w 'Op.stat.tmp') {print "ok 10\n";} else {print "not ok 10\n";}
50eval '$> = $olduid;'; # switch uid back (may not be implemented)
51if (! -x 'Op.stat.tmp') {print "ok 11\n";} else {print "not ok 11\n";}
52
53foreach ((12,13,14,15,16,17)) {
54 print "ok $_\n"; #deleted tests
55}
56
57chmod 0700,'Op.stat.tmp';
58if (-r 'Op.stat.tmp') {print "ok 18\n";} else {print "not ok 18\n";}
59if (-w 'Op.stat.tmp') {print "ok 19\n";} else {print "not ok 19\n";}
60if (-x 'Op.stat.tmp') {print "ok 20\n";} else {print "not ok 20\n";}
61
62if (-f 'Op.stat.tmp') {print "ok 21\n";} else {print "not ok 21\n";}
63if (! -d 'Op.stat.tmp') {print "ok 22\n";} else {print "not ok 22\n";}
64
65if (-d '.') {print "ok 23\n";} else {print "not ok 23\n";}
66if (! -f '.') {print "ok 24\n";} else {print "not ok 24\n";}
67
68if (`ls -l perl` =~ /^l.*->/) {
69 if (-l 'perl') {print "ok 25\n";} else {print "not ok 25\n";}
70}
71else {
72 print "ok 25\n";
73}
74
75if (-o 'Op.stat.tmp') {print "ok 26\n";} else {print "not ok 26\n";}
76
77if (-e 'Op.stat.tmp') {print "ok 27\n";} else {print "not ok 27\n";}
8d063cd8 78`rm -f Op.stat.tmp Op.stat.tmp2`;
378cc40b 79if (! -e 'Op.stat.tmp') {print "ok 28\n";} else {print "not ok 28\n";}
80
81if (-c '/dev/tty') {print "ok 29\n";} else {print "not ok 29\n";}
82if (! -c '.') {print "ok 30\n";} else {print "not ok 30\n";}
83
bf38876a 84if (! -e '/dev/printer' || -c '/dev/printer' || -S '/dev/printer')
378cc40b 85 {print "ok 31\n";}
86else
87 {print "not ok 31\n";}
88if (! -S '.') {print "ok 32\n";} else {print "not ok 32\n";}
89
90if (! -e '/dev/mt0' || -b '/dev/mt0')
91 {print "ok 33\n";}
92else
93 {print "not ok 33\n";}
94if (! -b '.') {print "ok 34\n";} else {print "not ok 34\n";}
95
96$cnt = $uid = 0;
97
ac58e20f 98die "Can't run op.stat test 35 without pwd working" unless $cwd;
99chdir '/usr/bin' || die "Can't cd to /usr/bin";
d9d8d8de 100while (defined($_ = <*>)) {
378cc40b 101 $cnt++;
102 $uid++ if -u;
103 last if $uid && $uid < $cnt;
104}
ac58e20f 105chdir $cwd || die "Can't cd back to $cwd";
378cc40b 106
107# I suppose this is going to fail somewhere...
108if ($uid > 0 && $uid < $cnt) {print "ok 35\n";} else {print "not ok 35\n";}
109
110unless (open(tty,"/dev/tty")) {
a687059c 111 print STDERR "Can't open /dev/tty--run t/TEST outside of make.\n";
378cc40b 112}
113if (-t tty) {print "ok 36\n";} else {print "not ok 36\n";}
114if (-c tty) {print "ok 37\n";} else {print "not ok 37\n";}
115close(tty);
116if (! -t tty) {print "ok 38\n";} else {print "not ok 38\n";}
117open(null,"/dev/null");
a687059c 118if (! -t null || -e '/xenix') {print "ok 39\n";} else {print "not ok 39\n";}
378cc40b 119close(null);
120if (-t) {print "ok 40\n";} else {print "not ok 40\n";}
121
122# These aren't strictly "stat" calls, but so what?
123
124if (-T 'op.stat') {print "ok 41\n";} else {print "not ok 41\n";}
125if (! -B 'op.stat') {print "ok 42\n";} else {print "not ok 42\n";}
126
127if (-B './perl') {print "ok 43\n";} else {print "not ok 43\n";}
128if (! -T './perl') {print "ok 44\n";} else {print "not ok 44\n";}
129
130open(foo,'op.stat');
131if (-T foo) {print "ok 45\n";} else {print "not ok 45\n";}
132if (! -B foo) {print "ok 46\n";} else {print "not ok 46\n";}
133$_ = <foo>;
134if (/perl/) {print "ok 47\n";} else {print "not ok 47\n";}
135if (-T foo) {print "ok 48\n";} else {print "not ok 48\n";}
136if (! -B foo) {print "ok 49\n";} else {print "not ok 49\n";}
137close(foo);
138
139open(foo,'op.stat');
140$_ = <foo>;
141if (/perl/) {print "ok 50\n";} else {print "not ok 50\n";}
142if (-T foo) {print "ok 51\n";} else {print "not ok 51\n";}
143if (! -B foo) {print "ok 52\n";} else {print "not ok 52\n";}
144seek(foo,0,0);
145if (-T foo) {print "ok 53\n";} else {print "not ok 53\n";}
146if (! -B foo) {print "ok 54\n";} else {print "not ok 54\n";}
147close(foo);
148
149if (-T '/dev/null') {print "ok 55\n";} else {print "not ok 55\n";}
150if (-B '/dev/null') {print "ok 56\n";} else {print "not ok 56\n";}