Move the ext/IO tests to a more standard location so that
[p5sagit/p5-mst-13.2.git] / ext / 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 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 42
43# Since some systems don't have echo, we use Perl.
e69a2255 44$echo = qq{$^X -le "print q(ok %d)"};
ba553610 45
46$cmd = sprintf $echo, 4;
47print `$cmd`;
48
e69a2255 49$cmd = sprintf "$echo 1>&2", 5;
50$cmd = sprintf $echo, 5 if $^O eq 'MacOS';
ba553610 51print `$cmd`;
61f2b451 52
53$stderr->close;
54$stdout->close;
55
56$stdout->fdopen($dupout,"w");
57$stderr->fdopen($duperr,"w");
58
cda41bc1 59if ($^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'VMS') { print `type Io.dup` }
e69a2255 60elsif ($^O eq 'MacOS') { system 'Catenate Io.dup' }
61else { system 'cat Io.dup' }
61f2b451 62unlink 'Io.dup';
63
64print STDOUT "ok 6\n";