[inseparable changes from patch from perl5.003_10 to perl5.003_11]
[p5sagit/p5-mst-13.2.git] / t / lib / filehand.t
CommitLineData
c07a80fd 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require Config; import Config;
36477c24 7 if ($Config{'extensions'} !~ /\bIO\b/ && $^O ne 'VMS') {
c07a80fd 8 print "1..0\n";
9 exit 0;
10 }
11}
12
13use FileHandle;
14use strict subs;
15
36477c24 16autoflush STDOUT 1;
17
c07a80fd 18$mystdout = new_from_fd FileHandle 1,"w";
5ef887f5 19$| = 1;
c07a80fd 20autoflush $mystdout;
36477c24 21print "1..11\n";
c07a80fd 22
23print $mystdout "ok ",fileno($mystdout),"\n";
24
25$fh = new FileHandle "TEST", O_RDONLY and print "ok 2\n";
36477c24 26
27
c07a80fd 28$buffer = <$fh>;
29print $buffer eq "#!./perl\n" ? "ok 3\n" : "not ok 3\n";
30
36477c24 31
5ef887f5 32ungetc $fh 65;
33CORE::read($fh, $buf,1);
c07a80fd 34print $buf eq 'A' ? "ok 4\n" : "not ok 4\n";
36477c24 35
36close $fh;
37
38$fh = new FileHandle;
39
40print "not " unless ($fh->open("< TEST") && <$fh> eq $buffer);
41print "ok 5\n";
42
43$fh->seek(0,0);
44print "not " unless (<$fh> eq $buffer);
45print "ok 6\n";
46
47$fh->seek(0,2);
48$line = <$fh>;
49print "not " if (defined($line) || !$fh->eof);
50print "ok 7\n";
51
52print "not " unless ($fh->open("TEST","r") && !$fh->tell && $fh->close);
53print "ok 8\n";
54
55autoflush STDOUT 0;
56
57print "not " if ($|);
58print "ok 9\n";
59
60autoflush STDOUT 1;
61
62print "not " unless ($|);
63print "ok 10\n";
64
65($rd,$wr) = FileHandle::pipe;
66
67if (fork) {
68 $wr->close;
69 print $rd->getline;
70}
71else {
72 $rd->close;
73 $wr->printf("ok %d\n",11);
74 exit(0);
75}