This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Forgot from #12843.
[perl5.git] / lib / IPC / Open2.t
CommitLineData
7e1af8bc 1#!./perl -w
7e1af8bc 2
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
774d564b 6 require Config; import Config;
f55ee38a
GS
7 if (!$Config{'d_fork'}
8 # open2/3 supported on win32 (but not Borland due to CRT bugs)
2986a63f 9 && (($^O ne 'MSWin32' && $^O ne 'NetWare') || $Config{'cc'} =~ /^bcc/i))
f55ee38a 10 {
774d564b 11 print "1..0\n";
12 exit 0;
13 }
7e1af8bc 14 # make warnings fatal
15 $SIG{__WARN__} = sub { die @_ };
16}
17
71be2cbc 18use strict;
7e1af8bc 19use IO::Handle;
20use IPC::Open2;
21#require 'open2.pl'; use subs 'open2';
22
774d564b 23my $perl = './perl';
24
7e1af8bc 25sub ok {
26 my ($n, $result, $info) = @_;
27 if ($result) {
28 print "ok $n\n";
29 }
30 else {
f55ee38a 31 print "not ok $n\n";
7e1af8bc 32 print "# $info\n" if $info;
33 }
34}
35
f55ee38a 36sub cmd_line {
2986a63f 37 if ($^O eq 'MSWin32' || $^O eq 'NetWare') {
f55ee38a
GS
38 return qq/"$_[0]"/;
39 }
40 else {
41 return $_[0];
42 }
43}
44
7e1af8bc 45my ($pid, $reaped_pid);
46STDOUT->autoflush;
47STDERR->autoflush;
48
49print "1..7\n";
50
f55ee38a
GS
51ok 1, $pid = open2 'READ', 'WRITE', $perl, '-e',
52 cmd_line('print scalar <STDIN>');
7e1af8bc 53ok 2, print WRITE "hi kid\n";
f55ee38a 54ok 3, <READ> =~ /^hi kid\r?\n$/;
7e1af8bc 55ok 4, close(WRITE), $!;
56ok 5, close(READ), $!;
57$reaped_pid = waitpid $pid, 0;
58ok 6, $reaped_pid == $pid, $reaped_pid;
59ok 7, $? == 0, $?;