Commit | Line | Data |
378cc40b |
1 | #!./perl |
2 | |
ba553610 |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
ff8b5bfb |
5 | @INC = qw(. ../lib); |
6 | require "./test.pl"; |
ba553610 |
7 | } |
378cc40b |
8 | |
1bb0a50f |
9 | use Config; |
10 | |
ba553610 |
11 | my $test = 1; |
ad1c9500 |
12 | print "1..26\n"; |
378cc40b |
13 | print "ok 1\n"; |
14 | |
ba553610 |
15 | open(DUPOUT,">&STDOUT"); |
16 | open(DUPERR,">&STDERR"); |
378cc40b |
17 | |
ba553610 |
18 | open(STDOUT,">Io.dup") || die "Can't open stdout"; |
a687059c |
19 | open(STDERR,">&STDOUT") || die "Can't open stderr"; |
378cc40b |
20 | |
a687059c |
21 | select(STDERR); $| = 1; |
22 | select(STDOUT); $| = 1; |
378cc40b |
23 | |
a687059c |
24 | print STDOUT "ok 2\n"; |
25 | print STDERR "ok 3\n"; |
ba553610 |
26 | |
27 | # Since some systems don't have echo, we use Perl. |
dc459aad |
28 | $echo = qq{$^X -le "print q(ok %d)"}; |
ba553610 |
29 | |
dc459aad |
30 | $cmd = sprintf $echo, 4; |
ba553610 |
31 | print `$cmd`; |
32 | |
dc459aad |
33 | $cmd = sprintf "$echo 1>&2", 5; |
34 | $cmd = sprintf $echo, 5 if $^O eq 'MacOS'; # don't know if we can do this ... |
ba553610 |
35 | print `$cmd`; |
36 | |
37 | # KNOWN BUG system() does not honor STDOUT redirections on VMS. |
38 | if( $^O eq 'VMS' ) { |
31775886 |
39 | print "not ok $_ # TODO system() not honoring STDOUT redirect on VMS\n" |
ba553610 |
40 | for 6..7; |
41 | } |
42 | else { |
43 | system sprintf $echo, 6; |
dc459aad |
44 | if ($^O eq 'MacOS') { |
45 | system sprintf $echo, 7; |
46 | } |
47 | else { |
48 | system sprintf "$echo 1>&2", 7; |
49 | } |
ba553610 |
50 | } |
378cc40b |
51 | |
d1e4d418 |
52 | close(STDOUT) or die "Could not close: $!"; |
53 | close(STDERR) or die "Could not close: $!"; |
378cc40b |
54 | |
d1e4d418 |
55 | open(STDOUT,">&DUPOUT") or die "Could not open: $!"; |
56 | open(STDERR,">&DUPERR") or die "Could not open: $!"; |
378cc40b |
57 | |
cda41bc1 |
58 | if (($^O eq 'MSWin32') || ($^O eq 'NetWare') || ($^O eq 'VMS')) { print `type Io.dup` } |
dc459aad |
59 | elsif ($^O eq 'MacOS') { system 'catenate Io.dup' } |
60 | else { system 'cat Io.dup' } |
378cc40b |
61 | unlink 'Io.dup'; |
62 | |
e4a4387c |
63 | print STDOUT "ok 8\n"; |
9394203c |
64 | |
1bb0a50f |
65 | open(F,">&",1) or die "Cannot dup to numeric 1: $!"; |
31775886 |
66 | print F "ok 9\n"; |
67 | close(F); |
68 | |
1bb0a50f |
69 | open(F,">&",'1') or die "Cannot dup to string '1': $!"; |
31775886 |
70 | print F "ok 10\n"; |
71 | close(F); |
72 | |
1bb0a50f |
73 | open(F,">&=",1) or die "Cannot dup to numeric 1: $!"; |
31775886 |
74 | print F "ok 11\n"; |
75 | close(F); |
76 | |
1bb0a50f |
77 | if ($Config{useperlio}) { |
78 | open(F,">&=",'1') or die "Cannot dup to string '1': $!"; |
79 | print F "ok 12\n"; |
80 | close(F); |
81 | } else { |
82 | open(F, ">&DUPOUT") or die "Cannot dup stdout back: $!"; |
83 | print F "ok 12\n"; |
84 | close(F); |
85 | } |
31775886 |
86 | |
939b405b |
87 | # To get STDOUT back. |
88 | open(F, ">&DUPOUT") or die "Cannot dup stdout back: $!"; |
89 | |
ff8b5bfb |
90 | curr_test(13); |
91 | |
92 | SKIP: { |
ad1c9500 |
93 | skip("need perlio", 14) unless $Config{useperlio}; |
ff8b5bfb |
94 | |
95 | ok(open(F, ">&", STDOUT)); |
96 | isnt(fileno(F), fileno(STDOUT)); |
97 | close F; |
98 | |
99 | ok(open(F, "<&=STDIN")); |
100 | is(fileno(F), fileno(STDIN)); |
101 | close F; |
102 | |
103 | ok(open(F, ">&=STDOUT")); |
104 | is(fileno(F), fileno(STDOUT)); |
105 | close F; |
106 | |
107 | ok(open(F, ">&=STDERR")); |
108 | is(fileno(F), fileno(STDERR)); |
109 | close F; |
110 | |
111 | open(G, ">dup$$") or die; |
112 | my $g = fileno(G); |
113 | |
114 | ok(open(F, ">&=$g")); |
115 | is(fileno(F), $g); |
116 | close F; |
117 | |
118 | ok(open(F, ">&=G")); |
119 | is(fileno(F), $g); |
120 | |
121 | print G "ggg\n"; |
122 | print F "fff\n"; |
123 | |
124 | close G; # flush first |
125 | close F; # flush second |
126 | |
127 | open(G, "<dup$$") or die; |
ad1c9500 |
128 | { |
129 | my $line; |
130 | $line = <G>; chomp $line; is($line, "ggg"); |
131 | $line = <G>; chomp $line; is($line, "fff"); |
132 | } |
ff8b5bfb |
133 | close G; |
134 | |
135 | END { 1 while unlink "dup$$" } |
136 | } |