This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Sarathy's clear_pmop patch with Radu Greab's fix,
[perl5.git] / t / lib / io_dup.t
CommitLineData
61f2b451 1#!./perl
2
3BEGIN {
7a4c00b4 4 unless(grep /blib/, @INC) {
5 chdir 't' if -d 't';
20822f61 6 @INC = '../lib';
7a4c00b4 7 }
8}
9
10use Config;
11
12BEGIN {
13 if(-d "lib" && -f "TEST") {
14 if ($Config{'extensions'} !~ /\bIO\b/ && $^O ne 'VMS') {
15 print "1..0\n";
16 exit 0;
17 }
61f2b451 18 }
19}
20
21use IO::Handle;
22use IO::File;
23
24select(STDERR); $| = 1;
25select(STDOUT); $| = 1;
26
27print "1..6\n";
28
29print "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
40print $stdout "ok 2\n";
41print $stderr "ok 3\n";
68dc0745 42if ($^O eq 'MSWin32') {
43 print `echo ok 4`;
44 print `echo ok 5 1>&2`; # does this *really* work?
45}
46else {
47 system 'echo ok 4';
48 system 'echo ok 5 1>&2';
49}
61f2b451 50
51$stderr->close;
52$stdout->close;
53
54$stdout->fdopen($dupout,"w");
55$stderr->fdopen($duperr,"w");
56
68dc0745 57if ($^O eq 'MSWin32') { print `type Io.dup` }
58else { system 'cat Io.dup' }
61f2b451 59unlink 'Io.dup';
60
61print STDOUT "ok 6\n";