13 my $tests_needing_perlio = 17;
14 plan(12 + $tests_needing_perlio);
17 open(DUPOUT,">&STDOUT");
18 open(DUPERR,">&STDERR");
20 my $tempfile = tempfile();
22 open(STDOUT,">$tempfile") || die "Can't open stdout";
23 open(STDERR,">&STDOUT") || die "Can't open stderr";
25 select(STDERR); $| = 1;
26 select(STDOUT); $| = 1;
28 print STDOUT "ok 2\n";
29 print STDERR "ok 3\n";
31 # Since some systems don't have echo, we use Perl.
32 $echo = qq{$^X -le "print q(ok %d)"};
34 $cmd = sprintf $echo, 4;
37 $cmd = sprintf "$echo 1>&2", 5;
40 system sprintf $echo, 6;
41 system sprintf "$echo 1>&2", 7;
43 close(STDOUT) or die "Could not close: $!";
44 close(STDERR) or die "Could not close: $!";
46 open(STDOUT,">&DUPOUT") or die "Could not open: $!";
47 open(STDERR,">&DUPERR") or die "Could not open: $!";
49 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { print `type $tempfile` }
50 elsif ($^O eq 'VMS') { system "type $tempfile.;" } # TYPE defaults to .LIS when there is no extension
51 else { system "cat $tempfile" }
53 print STDOUT "ok 8\n";
55 open(F,">&",1) or die "Cannot dup to numeric 1: $!";
59 open(F,">&",'1') or die "Cannot dup to string '1': $!";
63 open(F,">&=",1) or die "Cannot dup to numeric 1: $!";
67 if ($Config{useperlio}) {
68 open(F,">&=",'1') or die "Cannot dup to string '1': $!";
72 open(F, ">&DUPOUT") or die "Cannot dup stdout back: $!";
78 open(F, ">&DUPOUT") or die "Cannot dup stdout back: $!";
83 skip("need perlio", $tests_needing_perlio) unless $Config{useperlio};
85 ok(open(F, ">&", STDOUT));
86 isnt(fileno(F), fileno(STDOUT));
89 ok(open(F, "<&=STDIN")) or _diag $!;
90 is(fileno(F), fileno(STDIN));
93 ok(open(F, ">&=STDOUT"));
94 is(fileno(F), fileno(STDOUT));
97 ok(open(F, ">&=STDERR"));
98 is(fileno(F), fileno(STDERR));
101 open(G, ">$tempfile") or die;
104 ok(open(F, ">&=$g"));
114 close G; # flush first
115 close F; # flush second
117 open(G, "<$tempfile") or die;
120 $line = <G>; chomp $line; is($line, "ggg");
121 $line = <G>; chomp $line; is($line, "fff");
125 open UTFOUT, '>:utf8', $tempfile or die $!;
126 open UTFDUP, '>&UTFOUT' or die $!;
127 # some old greek saying.
128 my $message = "\x{03A0}\x{0391}\x{039D}\x{03A4}\x{0391} \x{03A1}\x{0395}\x{0399}\n";
129 print UTFOUT $message;
130 print UTFDUP $message;
131 binmode UTFDUP, ':utf8';
132 print UTFDUP $message;
135 open(UTFIN, "<:utf8", $tempfile) or die $!;
138 $line = <UTFIN>; is($line, $message);
139 $line = <UTFIN>; is($line, $message);
140 $line = <UTFIN>; is($line, $message);