Commit | Line | Data |
c07a80fd |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
20822f61 |
5 | @INC = '../lib'; |
c07a80fd |
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 | } |
b62e3068 |
11 | if ($^O eq 'mpeix') { |
12 | print "1..0 # Skip: broken on MPE/iX\n"; |
13 | exit 0; |
14 | } |
c07a80fd |
15 | } |
16 | |
17 | use FileHandle; |
18 | use strict subs; |
19 | |
36477c24 |
20 | autoflush STDOUT 1; |
21 | |
c07a80fd |
22 | $mystdout = new_from_fd FileHandle 1,"w"; |
5ef887f5 |
23 | $| = 1; |
c07a80fd |
24 | autoflush $mystdout; |
f21dc558 |
25 | print "1..12\n"; |
c07a80fd |
26 | |
22458fee |
27 | print $mystdout "ok ".fileno($mystdout)."\n"; |
c07a80fd |
28 | |
f86702cc |
29 | $fh = (new FileHandle "./TEST", O_RDONLY |
30 | or new FileHandle "TEST", O_RDONLY) |
31 | and print "ok 2\n"; |
36477c24 |
32 | |
33 | |
c07a80fd |
34 | $buffer = <$fh>; |
35 | print $buffer eq "#!./perl\n" ? "ok 3\n" : "not ok 3\n"; |
36 | |
36477c24 |
37 | |
9d116dd7 |
38 | ungetc $fh ord 'A'; |
5ef887f5 |
39 | CORE::read($fh, $buf,1); |
c07a80fd |
40 | print $buf eq 'A' ? "ok 4\n" : "not ok 4\n"; |
36477c24 |
41 | |
42 | close $fh; |
43 | |
44 | $fh = new FileHandle; |
45 | |
46 | print "not " unless ($fh->open("< TEST") && <$fh> eq $buffer); |
47 | print "ok 5\n"; |
48 | |
49 | $fh->seek(0,0); |
84902520 |
50 | print "#possible mixed CRLF/LF in t/TEST\nnot " unless (<$fh> eq $buffer); |
36477c24 |
51 | print "ok 6\n"; |
52 | |
53 | $fh->seek(0,2); |
54 | $line = <$fh>; |
55 | print "not " if (defined($line) || !$fh->eof); |
56 | print "ok 7\n"; |
57 | |
58 | print "not " unless ($fh->open("TEST","r") && !$fh->tell && $fh->close); |
59 | print "ok 8\n"; |
60 | |
61 | autoflush STDOUT 0; |
62 | |
63 | print "not " if ($|); |
64 | print "ok 9\n"; |
65 | |
66 | autoflush STDOUT 1; |
67 | |
68 | print "not " unless ($|); |
69 | print "ok 10\n"; |
70 | |
39e571d4 |
71 | if ($^O eq 'dos') |
72 | { |
73 | printf("ok %d\n",11); |
74 | exit(0); |
75 | } |
76 | |
36477c24 |
77 | ($rd,$wr) = FileHandle::pipe; |
78 | |
2986a63f |
79 | if ($^O eq 'VMS' || $^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'MSWin32' || $^O eq 'NetWare' || |
e5e1b98b |
80 | $Config{d_fork} ne 'define') { |
5f05dabc |
81 | $wr->autoflush; |
82 | $wr->printf("ok %d\n",11); |
83 | print $rd->getline; |
36477c24 |
84 | } |
85 | else { |
5f05dabc |
86 | if (fork) { |
87 | $wr->close; |
88 | print $rd->getline; |
89 | } |
90 | else { |
91 | $rd->close; |
92 | $wr->printf("ok %d\n",11); |
93 | exit(0); |
94 | } |
36477c24 |
95 | } |
f21dc558 |
96 | |
97 | print FileHandle->new('','r') ? "not ok 12\n" : "ok 12\n"; |