This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Switch most open() calls to three-argument form.
[perl5.git] / ext / IPC-Open3 / t / fd.t
1 #!./perl -- # Perl Rules
2
3 BEGIN {
4     if ($^O eq 'VMS') {
5         print "1..0 # Skip: needs porting, perhaps imitating Win32 mechanisms\n";
6         exit 0;
7     }
8     require "../../t/test.pl";
9 }
10 use strict;
11 use warnings;
12
13 plan 3;
14
15   my $file = 't/fd.t';
16
17 # [perl #76474]
18 {
19   my $stderr = runperl(
20      switches => ['-MIPC::Open3', '-w'],
21      prog => "open STDIN, q _${file}_ or die \$!; open3(q _<&0_, my \$out, undef, \$ENV{PERLEXE}, q _-e0_)",
22      stderr => 1,
23   );
24
25   is $stderr, '',
26    "dup STDOUT in a child process by using its file descriptor";
27 }
28
29 {
30   my $want = qr{\A#!\./perl -- # Perl Rules\r?\z};
31   open my $fh, '<', $file or die "Can't open $file: $!";
32   my $have = <$fh>;
33   chomp $have;
34   like($have, $want, 'We can find our test string');
35   close $fh;
36
37   fresh_perl_like(<<"EOP",
38 use IPC::Open3;
39 open FOO, '<', '$file' or die \$!;
40 open3('<&' . fileno FOO, my \$out, undef, \$ENV{PERLEXE}, '-eprint scalar <STDIN>');
41 print <\$out>;
42 EOP
43                   $want,
44                   undef,
45                   'Numeric file handles are duplicated correctly'
46       );
47 }