This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.003_01: [patch re-organisation and patch series introduction]
[perl5.git] / t / lib / io_pipe.t
1 #!./perl
2
3 BEGIN {
4     @INC = '../lib';
5     require Config; import Config;
6     if ($Config{'extensions'} !~ /\bIO\b/ && $^O ne 'VMS') {
7         print "1..0\n";
8         exit 0;
9     }
10 }
11
12 use IO::Pipe;
13
14 $| = 1;
15 print "1..6\n";
16
17 $pipe = new IO::Pipe;
18
19 $pid = fork();
20
21 if($pid)
22  {
23   $pipe->writer;
24   print $pipe "Xk 1\n";
25   print $pipe "oY 2\n";
26   $pipe->close;
27   wait;
28  }
29 elsif(defined $pid)
30  {
31   $pipe->reader;
32   $stdin = bless \*STDIN, "IO::Handle";
33   $stdin->fdopen($pipe,"r");
34   exec 'tr', 'YX', 'ko';
35  }
36 else
37  {
38   die;
39  }
40
41 $pipe = new IO::Pipe;
42 $pid = fork();
43
44 if($pid)
45  {
46   $pipe->reader;
47   while(<$pipe>) {
48       s/^not //;
49       print;
50   }
51   $pipe->close;
52   wait;
53  }
54 elsif(defined $pid)
55  {
56   $pipe->writer;
57
58   $stdout = bless \*STDOUT, "IO::Handle";
59   $stdout->fdopen($pipe,"w");
60   print STDOUT "not ok 3\n";
61   exec 'echo', 'not ok 4';
62  }
63 else
64  {
65   die;
66  }
67
68 $pipe = new IO::Pipe;
69 $pipe->writer;
70
71 $SIG{'PIPE'} = 'broken_pipe';
72
73 sub broken_pipe {
74     print "ok 5\n";
75 }
76
77 print $pipe "not ok 5\n";
78 $pipe->close;
79
80
81 print "ok 6\n";
82