Commit | Line | Data |
61f2b451 |
1 | #!./perl |
2 | |
3 | BEGIN { |
7a4c00b4 |
4 | unless(grep /blib/, @INC) { |
5 | chdir 't' if -d 't'; |
6 | @INC = '../lib' if -d '../lib'; |
7 | } |
8 | } |
9 | |
10 | use Config; |
11 | |
12 | BEGIN { |
13 | if(-d "lib" && -f "TEST") { |
774d564b |
14 | if (! $Config{'d_fork'} || |
15 | ($Config{'extensions'} !~ /\bIO\b/ && $^O ne 'VMS')) |
16 | { |
7a4c00b4 |
17 | print "1..0\n"; |
18 | exit 0; |
19 | } |
61f2b451 |
20 | } |
21 | } |
22 | |
23 | use IO::Pipe; |
24 | |
774d564b |
25 | my $perl = './perl'; |
26 | |
61f2b451 |
27 | $| = 1; |
774d564b |
28 | print "1..10\n"; |
29 | |
30 | $pipe = new IO::Pipe->reader($perl, '-e', 'print "not ok 1\n"'); |
31 | while (<$pipe>) { |
32 | s/^not //; |
33 | print; |
34 | } |
35 | $pipe->close or print "# \$!=$!\nnot "; |
36 | print "ok 2\n"; |
37 | |
38 | $cmd = 'BEGIN{$SIG{ALRM} = sub {print "not ok 4\n"; exit}; alarm 10} s/not //'; |
39 | $pipe = new IO::Pipe->writer($perl, '-pe', $cmd); |
40 | print $pipe "not ok 3\n" ; |
41 | $pipe->close or print "# \$!=$!\nnot "; |
42 | print "ok 4\n"; |
61f2b451 |
43 | |
44 | $pipe = new IO::Pipe; |
45 | |
46 | $pid = fork(); |
47 | |
48 | if($pid) |
49 | { |
50 | $pipe->writer; |
774d564b |
51 | print $pipe "Xk 5\n"; |
52 | print $pipe "oY 6\n"; |
61f2b451 |
53 | $pipe->close; |
54 | wait; |
55 | } |
56 | elsif(defined $pid) |
57 | { |
58 | $pipe->reader; |
59 | $stdin = bless \*STDIN, "IO::Handle"; |
60 | $stdin->fdopen($pipe,"r"); |
61 | exec 'tr', 'YX', 'ko'; |
62 | } |
63 | else |
64 | { |
774d564b |
65 | die "# error = $!"; |
61f2b451 |
66 | } |
67 | |
68 | $pipe = new IO::Pipe; |
69 | $pid = fork(); |
70 | |
71 | if($pid) |
72 | { |
73 | $pipe->reader; |
74 | while(<$pipe>) { |
75 | s/^not //; |
76 | print; |
77 | } |
78 | $pipe->close; |
79 | wait; |
80 | } |
81 | elsif(defined $pid) |
82 | { |
83 | $pipe->writer; |
84 | |
85 | $stdout = bless \*STDOUT, "IO::Handle"; |
86 | $stdout->fdopen($pipe,"w"); |
774d564b |
87 | print STDOUT "not ok 7\n"; |
88 | exec 'echo', 'not ok 8'; |
61f2b451 |
89 | } |
90 | else |
91 | { |
92 | die; |
93 | } |
94 | |
95 | $pipe = new IO::Pipe; |
96 | $pipe->writer; |
97 | |
98 | $SIG{'PIPE'} = 'broken_pipe'; |
99 | |
100 | sub broken_pipe { |
774d564b |
101 | print "ok 9\n"; |
61f2b451 |
102 | } |
103 | |
774d564b |
104 | print $pipe "not ok 9\n"; |
61f2b451 |
105 | $pipe->close; |
106 | |
3d57aefb |
107 | sleep 1; |
61f2b451 |
108 | |
774d564b |
109 | print "ok 10\n"; |
61f2b451 |
110 | |