This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Retract #20260.
[perl5.git] / ext / IO / lib / IO / t / io_dup.t
1 #!./perl
2
3 BEGIN {
4     unless(grep /blib/, @INC) {
5         chdir 't' if -d 't';
6         @INC = '../lib';
7     }
8 }
9
10 use Config;
11
12 BEGIN {
13     if($ENV{PERL_CORE}) {
14         if ($Config{'extensions'} !~ /\bIO\b/) {
15             print "1..0 # Skip: IO extension not compiled\n";
16             exit 0;
17         }
18     }
19 }
20
21 use IO::Handle;
22 use IO::File;
23
24 select(STDERR); $| = 1;
25 select(STDOUT); $| = 1;
26
27 print "1..6\n";
28
29 print "ok 1\n";
30
31 $dupout = IO::Handle->new->fdopen( \*STDOUT ,"w");
32 $duperr = IO::Handle->new->fdopen( \*STDERR ,"w");
33
34 $stdout = \*STDOUT; bless $stdout, "IO::File"; # "IO::Handle";
35 $stderr = \*STDERR; bless $stderr, "IO::Handle";
36
37 $stdout->open( "Io.dup","w") || die "Can't open stdout";
38 $stderr->fdopen($stdout,"w");
39
40 print $stdout "ok 2\n";
41 print $stderr "ok 3\n";
42
43 # Since some systems don't have echo, we use Perl.
44 $echo = qq{$^X -le "print q(ok %d)"};
45
46 $cmd = sprintf $echo, 4;
47 print `$cmd`;
48
49 $cmd = sprintf "$echo 1>&2", 5;
50 $cmd = sprintf $echo, 5 if $^O eq 'MacOS';
51 print `$cmd`;
52
53 $stderr->close;
54 $stdout->close;
55
56 $stdout->fdopen($dupout,"w");
57 $stderr->fdopen($duperr,"w");
58
59 if ($^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'VMS') { print `type Io.dup` }
60 elsif ($^O eq 'MacOS') { system 'Catenate Io.dup' }
61 else                   { system 'cat Io.dup' }
62 unlink 'Io.dup';
63
64 print STDOUT "ok 6\n";