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