1*0Sstevel@tonic-gate#!./perl -w 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateBEGIN { 4*0Sstevel@tonic-gate chdir 't' if -d 't'; 5*0Sstevel@tonic-gate @INC = '../lib'; 6*0Sstevel@tonic-gate require Config; import Config; 7*0Sstevel@tonic-gate if (!$Config{'d_fork'} 8*0Sstevel@tonic-gate # open2/3 supported on win32 (but not Borland due to CRT bugs) 9*0Sstevel@tonic-gate && (($^O ne 'MSWin32' && $^O ne 'NetWare') || $Config{'cc'} =~ /^bcc/i)) 10*0Sstevel@tonic-gate { 11*0Sstevel@tonic-gate print "1..0\n"; 12*0Sstevel@tonic-gate exit 0; 13*0Sstevel@tonic-gate } 14*0Sstevel@tonic-gate # make warnings fatal 15*0Sstevel@tonic-gate $SIG{__WARN__} = sub { die @_ }; 16*0Sstevel@tonic-gate} 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gateuse strict; 19*0Sstevel@tonic-gateuse IO::Handle; 20*0Sstevel@tonic-gateuse IPC::Open2; 21*0Sstevel@tonic-gate#require 'open2.pl'; use subs 'open2'; 22*0Sstevel@tonic-gate 23*0Sstevel@tonic-gatemy $perl = './perl'; 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gatesub ok { 26*0Sstevel@tonic-gate my ($n, $result, $info) = @_; 27*0Sstevel@tonic-gate if ($result) { 28*0Sstevel@tonic-gate print "ok $n\n"; 29*0Sstevel@tonic-gate } 30*0Sstevel@tonic-gate else { 31*0Sstevel@tonic-gate print "not ok $n\n"; 32*0Sstevel@tonic-gate print "# $info\n" if $info; 33*0Sstevel@tonic-gate } 34*0Sstevel@tonic-gate} 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gatesub cmd_line { 37*0Sstevel@tonic-gate if ($^O eq 'MSWin32' || $^O eq 'NetWare') { 38*0Sstevel@tonic-gate return qq/"$_[0]"/; 39*0Sstevel@tonic-gate } 40*0Sstevel@tonic-gate else { 41*0Sstevel@tonic-gate return $_[0]; 42*0Sstevel@tonic-gate } 43*0Sstevel@tonic-gate} 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gatemy ($pid, $reaped_pid); 46*0Sstevel@tonic-gateSTDOUT->autoflush; 47*0Sstevel@tonic-gateSTDERR->autoflush; 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gateprint "1..7\n"; 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gateok 1, $pid = open2 'READ', 'WRITE', $perl, '-e', 52*0Sstevel@tonic-gate cmd_line('print scalar <STDIN>'); 53*0Sstevel@tonic-gateok 2, print WRITE "hi kid\n"; 54*0Sstevel@tonic-gateok 3, <READ> =~ /^hi kid\r?\n$/; 55*0Sstevel@tonic-gateok 4, close(WRITE), $!; 56*0Sstevel@tonic-gateok 5, close(READ), $!; 57*0Sstevel@tonic-gate$reaped_pid = waitpid $pid, 0; 58*0Sstevel@tonic-gateok 6, $reaped_pid == $pid, $reaped_pid; 59*0Sstevel@tonic-gateok 7, $? == 0, $?; 60