This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [ PATCH ] module test fest
[perl5.git] / ext / IO / lib / IO / t / 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 {
d846159b
MS
13 if($ENV{PERL_CORE}) {
14 if ($Config{'extensions'} !~ /\bIO\b/) {
15 print "1..0 # Skip: IO extension not compiled\n";
7a4c00b4 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";
ba553610
MS
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;
47print `$cmd`;
48
49$cmd = sprintf "$echo 1>&2", 5;
50print `$cmd`;
61f2b451 51
52$stderr->close;
53$stdout->close;
54
55$stdout->fdopen($dupout,"w");
56$stderr->fdopen($duperr,"w");
57
cda41bc1 58if ($^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'VMS') { print `type Io.dup` }
68dc0745 59else { system 'cat Io.dup' }
61f2b451 60unlink 'Io.dup';
61
62print STDOUT "ok 6\n";