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; |
1031ca5c |
10 | no warnings 'once'; |
1bb0a50f |
11 | |
ba553610 |
12 | my $test = 1; |
1d341aad |
13 | my $tests_needing_perlio = 17; |
14 | plan(12 + $tests_needing_perlio); |
378cc40b |
15 | print "ok 1\n"; |
16 | |
ba553610 |
17 | open(DUPOUT,">&STDOUT"); |
18 | open(DUPERR,">&STDERR"); |
378cc40b |
19 | |
62a28c97 |
20 | my $tempfile = tempfile(); |
21 | |
22 | open(STDOUT,">$tempfile") || die "Can't open stdout"; |
a687059c |
23 | open(STDERR,">&STDOUT") || die "Can't open stderr"; |
378cc40b |
24 | |
a687059c |
25 | select(STDERR); $| = 1; |
26 | select(STDOUT); $| = 1; |
378cc40b |
27 | |
a687059c |
28 | print STDOUT "ok 2\n"; |
29 | print STDERR "ok 3\n"; |
ba553610 |
30 | |
31 | # Since some systems don't have echo, we use Perl. |
dc459aad |
32 | $echo = qq{$^X -le "print q(ok %d)"}; |
ba553610 |
33 | |
dc459aad |
34 | $cmd = sprintf $echo, 4; |
ba553610 |
35 | print `$cmd`; |
36 | |
dc459aad |
37 | $cmd = sprintf "$echo 1>&2", 5; |
38 | $cmd = sprintf $echo, 5 if $^O eq 'MacOS'; # don't know if we can do this ... |
ba553610 |
39 | print `$cmd`; |
40 | |
7aa55bb4 |
41 | system sprintf $echo, 6; |
42 | if ($^O eq 'MacOS') { |
43 | system sprintf $echo, 7; |
ba553610 |
44 | } |
45 | else { |
7aa55bb4 |
46 | system sprintf "$echo 1>&2", 7; |
ba553610 |
47 | } |
378cc40b |
48 | |
d1e4d418 |
49 | close(STDOUT) or die "Could not close: $!"; |
50 | close(STDERR) or die "Could not close: $!"; |
378cc40b |
51 | |
d1e4d418 |
52 | open(STDOUT,">&DUPOUT") or die "Could not open: $!"; |
53 | open(STDERR,">&DUPERR") or die "Could not open: $!"; |
378cc40b |
54 | |
7aa55bb4 |
55 | if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { print `type $tempfile` } |
56 | elsif ($^O eq 'VMS') { system "type $tempfile.;" } # TYPE defaults to .LIS when there is no extension |
62a28c97 |
57 | elsif ($^O eq 'MacOS') { system "catenate $tempfile" } |
58 | else { system "cat $tempfile" } |
378cc40b |
59 | |
e4a4387c |
60 | print STDOUT "ok 8\n"; |
9394203c |
61 | |
1bb0a50f |
62 | open(F,">&",1) or die "Cannot dup to numeric 1: $!"; |
31775886 |
63 | print F "ok 9\n"; |
64 | close(F); |
65 | |
1bb0a50f |
66 | open(F,">&",'1') or die "Cannot dup to string '1': $!"; |
31775886 |
67 | print F "ok 10\n"; |
68 | close(F); |
69 | |
1bb0a50f |
70 | open(F,">&=",1) or die "Cannot dup to numeric 1: $!"; |
31775886 |
71 | print F "ok 11\n"; |
72 | close(F); |
73 | |
1bb0a50f |
74 | if ($Config{useperlio}) { |
75 | open(F,">&=",'1') or die "Cannot dup to string '1': $!"; |
76 | print F "ok 12\n"; |
77 | close(F); |
78 | } else { |
79 | open(F, ">&DUPOUT") or die "Cannot dup stdout back: $!"; |
80 | print F "ok 12\n"; |
81 | close(F); |
82 | } |
31775886 |
83 | |
939b405b |
84 | # To get STDOUT back. |
85 | open(F, ">&DUPOUT") or die "Cannot dup stdout back: $!"; |
86 | |
ff8b5bfb |
87 | curr_test(13); |
88 | |
89 | SKIP: { |
1d341aad |
90 | skip("need perlio", $tests_needing_perlio) unless $Config{useperlio}; |
ff8b5bfb |
91 | |
92 | ok(open(F, ">&", STDOUT)); |
93 | isnt(fileno(F), fileno(STDOUT)); |
94 | close F; |
95 | |
0685228b |
96 | ok(open(F, "<&=STDIN")) or _diag $!; |
ff8b5bfb |
97 | is(fileno(F), fileno(STDIN)); |
98 | close F; |
99 | |
100 | ok(open(F, ">&=STDOUT")); |
101 | is(fileno(F), fileno(STDOUT)); |
102 | close F; |
103 | |
104 | ok(open(F, ">&=STDERR")); |
105 | is(fileno(F), fileno(STDERR)); |
106 | close F; |
107 | |
62a28c97 |
108 | open(G, ">$tempfile") or die; |
ff8b5bfb |
109 | my $g = fileno(G); |
110 | |
111 | ok(open(F, ">&=$g")); |
112 | is(fileno(F), $g); |
113 | close F; |
114 | |
115 | ok(open(F, ">&=G")); |
116 | is(fileno(F), $g); |
117 | |
118 | print G "ggg\n"; |
119 | print F "fff\n"; |
120 | |
121 | close G; # flush first |
122 | close F; # flush second |
123 | |
62a28c97 |
124 | open(G, "<$tempfile") or die; |
ad1c9500 |
125 | { |
126 | my $line; |
127 | $line = <G>; chomp $line; is($line, "ggg"); |
128 | $line = <G>; chomp $line; is($line, "fff"); |
129 | } |
ff8b5bfb |
130 | close G; |
131 | |
62a28c97 |
132 | open UTFOUT, '>:utf8', $tempfile or die $!; |
f0720f70 |
133 | open UTFDUP, '>&UTFOUT' or die $!; |
40986f42 |
134 | # some old greek saying. |
135 | my $message = "\x{03A0}\x{0391}\x{039D}\x{03A4}\x{0391} \x{03A1}\x{0395}\x{0399}\n"; |
f0720f70 |
136 | print UTFOUT $message; |
137 | print UTFDUP $message; |
138 | binmode UTFDUP, ':utf8'; |
139 | print UTFDUP $message; |
140 | close UTFOUT; |
141 | close UTFDUP; |
62a28c97 |
142 | open(UTFIN, "<:utf8", $tempfile) or die $!; |
f0720f70 |
143 | { |
144 | my $line; |
145 | $line = <UTFIN>; is($line, $message); |
146 | $line = <UTFIN>; is($line, $message); |
147 | $line = <UTFIN>; is($line, $message); |
148 | } |
149 | close UTFIN; |
f0720f70 |
150 | |
ff8b5bfb |
151 | } |