This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
New tests: op/method.t and op/locale.t
[perl5.git] / t / lib / io_pipe.t
1 #!./perl
2
3
4 BEGIN {
5     unless(grep /blib/, @INC) {
6         chdir 't' if -d 't';
7         @INC = '../lib' if -d '../lib';
8     }
9 }
10
11 use Config;
12
13 BEGIN {
14     if(-d "lib" && -f "TEST") {
15         if ($Config{'extensions'} !~ /\bIO\b/ && $^O ne 'VMS') {
16             print "1..0\n";
17             exit 0;
18         }
19     }
20 }
21
22 use IO::Pipe;
23
24 $| = 1;
25 print "1..6\n";
26
27 $pipe = new IO::Pipe;
28
29 $pid = fork();
30
31 if($pid)
32  {
33   $pipe->writer;
34   print $pipe "Xk 1\n";
35   print $pipe "oY 2\n";
36   $pipe->close;
37   wait;
38  }
39 elsif(defined $pid)
40  {
41   $pipe->reader;
42   $stdin = bless \*STDIN, "IO::Handle";
43   $stdin->fdopen($pipe,"r");
44   exec 'tr', 'YX', 'ko';
45  }
46 else
47  {
48   die;
49  }
50
51 $pipe = new IO::Pipe;
52 $pid = fork();
53
54 if($pid)
55  {
56   $pipe->reader;
57   while(<$pipe>) {
58       s/^not //;
59       print;
60   }
61   $pipe->close;
62   wait;
63  }
64 elsif(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  }
73 else
74  {
75   die;
76  }
77
78 $pipe = new IO::Pipe;
79 $pipe->writer;
80
81 $SIG{'PIPE'} = 'broken_pipe';
82
83 sub broken_pipe {
84     print "ok 5\n";
85 }
86
87 print $pipe "not ok 5\n";
88 $pipe->close;
89
90
91 print "ok 6\n";
92