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