[inseparable changes from patch from perl5.003_15 to perl5.003_16]
[p5sagit/p5-mst-13.2.git] / t / lib / io_pipe.t
CommitLineData
61f2b451 1#!./perl
2
7a4c00b4 3
61f2b451 4BEGIN {
7a4c00b4 5 unless(grep /blib/, @INC) {
6 chdir 't' if -d 't';
7 @INC = '../lib' if -d '../lib';
8 }
9}
10
11use Config;
12
13BEGIN {
14 if(-d "lib" && -f "TEST") {
15 if ($Config{'extensions'} !~ /\bIO\b/ && $^O ne 'VMS') {
16 print "1..0\n";
17 exit 0;
18 }
61f2b451 19 }
20}
21
22use IO::Pipe;
23
24$| = 1;
25print "1..6\n";
26
27$pipe = new IO::Pipe;
28
29$pid = fork();
30
31if($pid)
32 {
33 $pipe->writer;
34 print $pipe "Xk 1\n";
35 print $pipe "oY 2\n";
36 $pipe->close;
37 wait;
38 }
39elsif(defined $pid)
40 {
41 $pipe->reader;
42 $stdin = bless \*STDIN, "IO::Handle";
43 $stdin->fdopen($pipe,"r");
44 exec 'tr', 'YX', 'ko';
45 }
46else
47 {
7a4c00b4 48 die;
61f2b451 49 }
50
51$pipe = new IO::Pipe;
52$pid = fork();
53
54if($pid)
55 {
56 $pipe->reader;
57 while(<$pipe>) {
58 s/^not //;
59 print;
60 }
61 $pipe->close;
62 wait;
63 }
64elsif(defined $pid)
65 {
66 $pipe->writer;
67
68 $stdout = bless \*STDOUT, "IO::Handle";
69 $stdout->fdopen($pipe,"w");
70 print STDOUT "not ok 3\n";
71 exec 'echo', 'not ok 4';
72 }
73else
74 {
75 die;
76 }
77
78$pipe = new IO::Pipe;
79$pipe->writer;
80
81$SIG{'PIPE'} = 'broken_pipe';
82
83sub broken_pipe {
84 print "ok 5\n";
85}
86
87print $pipe "not ok 5\n";
88$pipe->close;
89
90
91print "ok 6\n";
92