This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix bad test output of IPC::Open2 in ext
[perl5.git] / ext / IPC-Open2 / t / IPC-Open2.t
1 #!./perl -w
2
3 use Config;
4 BEGIN {
5     require Test::More;
6     if (!$Config{'d_fork'}
7        # open2/3 supported on win32 (but not Borland due to CRT bugs)
8        && (($^O ne 'MSWin32' && $^O ne 'NetWare') || $Config{'cc'} =~ /^bcc/i))
9     {
10         Test::More->import(skip_all => 'open2/3 not available with MSWin32+Netware+cc=bcc');
11         exit 0;
12     }
13     # make warnings fatal
14     $SIG{__WARN__} = sub { die @_ };
15 }
16
17 use strict;
18 use IO::Handle;
19 use IPC::Open2;
20 use Test::More tests => 7;
21
22 my $perl = $^X;
23
24 sub cmd_line {
25         if ($^O eq 'MSWin32' || $^O eq 'NetWare') {
26                 return qq/"$_[0]"/;
27         }
28         else {
29                 return $_[0];
30         }
31 }
32
33 my ($pid, $reaped_pid);
34 STDOUT->autoflush;
35 STDERR->autoflush;
36
37 ok($pid = open2 'READ', 'WRITE', $perl, '-e',
38         cmd_line('print scalar <STDIN>'));
39 ok(print WRITE "hi kid\n");
40 ok(<READ> =~ /^hi kid\r?\n$/);
41 ok(close(WRITE), "closing WRITE: $!");
42 ok(close(READ), "closing READ: $!");
43 $reaped_pid = waitpid $pid, 0;
44 ok($reaped_pid == $pid, "Reaped PID: $reaped_pid");
45 ok($? == 0, "\$? should be zero ($?)");