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; |
ff8b5bfb |
12 | print "1..25\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 | |
ff8b5bfb |
87 | curr_test(13); |
88 | |
89 | SKIP: { |
90 | skip("need perlio", 13) unless $Config{useperlio}; |
91 | |
92 | ok(open(F, ">&", STDOUT)); |
93 | isnt(fileno(F), fileno(STDOUT)); |
94 | close F; |
95 | |
96 | ok(open(F, "<&=STDIN")); |
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 | |
108 | open(G, ">dup$$") or die; |
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 | |
124 | open(G, "<dup$$") or die; |
125 | { local $/; is(<G>, "ggg\nfff\n") } |
126 | close G; |
127 | |
128 | END { 1 while unlink "dup$$" } |
129 | } |