As requested by pudge.
[p5sagit/p5-mst-13.2.git] / t / io / dup.t
CommitLineData
378cc40b 1#!./perl
2
ba553610 3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
378cc40b 7
ba553610 8my $test = 1;
e4a4387c 9print "1..8\n";
378cc40b 10print "ok 1\n";
11
ba553610 12open(DUPOUT,">&STDOUT");
13open(DUPERR,">&STDERR");
378cc40b 14
ba553610 15open(STDOUT,">Io.dup") || die "Can't open stdout";
a687059c 16open(STDERR,">&STDOUT") || die "Can't open stderr";
378cc40b 17
a687059c 18select(STDERR); $| = 1;
19select(STDOUT); $| = 1;
378cc40b 20
a687059c 21print STDOUT "ok 2\n";
22print STDERR "ok 3\n";
ba553610 23
24# Since some systems don't have echo, we use Perl.
25$echo = qq{$^X -le "print q{ok %d}"};
26
27$cmd = sprintf $echo, 4;
28print `$cmd`;
29
30$cmd = sprintf "$echo 1>&2", 5;
31print `$cmd`;
32
33# KNOWN BUG system() does not honor STDOUT redirections on VMS.
34if( $^O eq 'VMS' ) {
35 print "not ok $_ # TODO system() not honoring STDOUT redirect on VMS\n"
36 for 6..7;
37}
38else {
39 system sprintf $echo, 6;
40 system sprintf "$echo 1>&2", 7;
41}
378cc40b 42
d1e4d418 43close(STDOUT) or die "Could not close: $!";
44close(STDERR) or die "Could not close: $!";
378cc40b 45
d1e4d418 46open(STDOUT,">&DUPOUT") or die "Could not open: $!";
47open(STDERR,">&DUPERR") or die "Could not open: $!";
378cc40b 48
cda41bc1 49if (($^O eq 'MSWin32') || ($^O eq 'NetWare') || ($^O eq 'VMS')) { print `type Io.dup` }
68dc0745 50else { system 'cat Io.dup' }
378cc40b 51unlink 'Io.dup';
52
e4a4387c 53print STDOUT "ok 8\n";
9394203c 54