This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[inseparable changes from patch from perl5.003_12 to perl5.003_13]
[perl5.git] / t / lib / open2.t
1 #!./perl -w
2 use strict;
3
4 BEGIN {
5     chdir 't' if -d 't';
6     @INC = '../lib';
7     # make warnings fatal
8     $SIG{__WARN__} = sub { die @_ };
9 }
10
11 use IO::Handle;
12 use IPC::Open2;
13 #require 'open2.pl'; use subs 'open2';
14
15 sub ok {
16     my ($n, $result, $info) = @_;
17     if ($result) {
18         print "ok $n\n";
19     }
20     else {
21         print "not ok $n\n";
22         print "# $info\n" if $info;
23     }
24 }
25
26 my ($pid, $reaped_pid);
27 STDOUT->autoflush;
28 STDERR->autoflush;
29
30 print "1..7\n";
31
32 ok 1, $pid = open2 'READ', 'WRITE', $^X, '-e', 'print scalar <STDIN>';
33 ok 2, print WRITE "hi kid\n";
34 ok 3, <READ> eq "hi kid\n";
35 ok 4, close(WRITE), $!;
36 ok 5, close(READ), $!;
37 $reaped_pid = waitpid $pid, 0;
38 ok 6, $reaped_pid == $pid, $reaped_pid;
39 ok 7, $? == 0, $?;