This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix core dump on IO::Seekable::setpos($fh, undef)
[perl5.git] / t / lib / open2.t
CommitLineData
7e1af8bc 1#!./perl -w
7e1af8bc 2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
774d564b 6 require Config; import Config;
7 unless ($Config{'d_fork'}) {
8 print "1..0\n";
9 exit 0;
10 }
7e1af8bc 11 # make warnings fatal
12 $SIG{__WARN__} = sub { die @_ };
13}
14
71be2cbc 15use strict;
7e1af8bc 16use IO::Handle;
17use IPC::Open2;
18#require 'open2.pl'; use subs 'open2';
19
774d564b 20my $perl = './perl';
21
7e1af8bc 22sub ok {
23 my ($n, $result, $info) = @_;
24 if ($result) {
25 print "ok $n\n";
26 }
27 else {
28 print "not ok $n\n";
29 print "# $info\n" if $info;
30 }
31}
32
33my ($pid, $reaped_pid);
34STDOUT->autoflush;
35STDERR->autoflush;
36
37print "1..7\n";
38
774d564b 39ok 1, $pid = open2 'READ', 'WRITE', $perl, '-e', 'print scalar <STDIN>';
7e1af8bc 40ok 2, print WRITE "hi kid\n";
41ok 3, <READ> eq "hi kid\n";
42ok 4, close(WRITE), $!;
43ok 5, close(READ), $!;
44$reaped_pid = waitpid $pid, 0;
45ok 6, $reaped_pid == $pid, $reaped_pid;
46ok 7, $? == 0, $?;