9 unless (find PerlIO::Layer 'perlio') {
10 print "1..0 # Skip: not perlio\n";
14 if ($@ =~ /dynamic loading not available/) {
15 print "1..0 # miniperl cannot load Encode\n";
18 # Makes testing easier.
19 $ENV{PERLIO} = 'stdio' if exists $ENV{PERLIO} && $ENV{PERLIO} eq '';
20 if (exists $ENV{PERLIO} && $ENV{PERLIO} !~ /^(stdio|perlio|mmap)$/) {
21 # We are not prepared for anything else.
22 print "1..0 # PERLIO='$ENV{PERLIO}' unknown\n";
25 $PERLIO = exists $ENV{PERLIO} ? $ENV{PERLIO} : "(undef)";
32 my $DOSISH = $^O =~ /^(?:MSWin32|os2|dos|NetWare|mint)$/ ? 1 : 0;
33 $DOSISH = 1 if !$DOSISH and $^O =~ /^uwin/;
34 my $NONSTDIO = exists $ENV{PERLIO} && $ENV{PERLIO} ne 'stdio' ? 1 : 0;
35 my $FASTSTDIO = $Config{d_faststdio} && $Config{usefaststdio} ? 1 : 0;
40 # NONSTDIO = $NONSTDIO
41 # FASTSTDIO = $FASTSTDIO
45 skip("This perl does not have Encode", 43)
46 unless " $Config{extensions} " =~ / Encode /;
49 my ($result, $expected, $id) = @_;
50 # An interesting dance follows where we try to make the following
51 # IO layer stack setups to compare equal:
53 # PERLIO UNIX-like DOS-like
55 # unset / "" unix perlio / stdio [1] unix crlf
56 # stdio unix perlio / stdio [1] stdio
57 # perlio unix perlio unix perlio
58 # mmap unix mmap unix mmap
60 # [1] "stdio" if Configure found out how to do "fast stdio" (depends
61 # on the stdio implementation) and in Perl 5.8, otherwise "unix perlio"
65 shift @$result if $result->[0] eq "unix";
66 # Change expectations.
68 $expected->[0] = $ENV{PERLIO};
70 $expected->[0] = $ENV{PERLIO} if $expected->[0] eq "stdio";
72 } elsif (!$FASTSTDIO && !$DOSISH) {
73 splice(@$result, 0, 2, "stdio")
75 $result->[0] eq "unix" &&
76 $result->[1] eq "perlio";
78 splice(@$result, 0, 2, "stdio")
80 $result->[0] eq "unix" &&
81 $result->[1] eq "crlf";
83 my $n = scalar @$expected;
84 is($n, scalar @$expected, "$id - layers = $n");
85 for (my $i = 0; $i < $n; $i++) {
86 my $j = $expected->[$i];
87 if (ref $j eq 'CODE') {
88 ok($j->($result->[$i]), "$id - $i is ok");
91 sprintf("$id - $i is %s",
92 defined $j ? $j : "undef"));
97 check([ PerlIO::get_layers(STDIN) ],
101 open(F, ">:crlf", "afile");
103 check([ PerlIO::get_layers(F) ],
107 binmode(F, ":encoding(sjis)"); # "sjis" will be canonized to "shiftjis"
109 check([ PerlIO::get_layers(F) ],
110 [ qw[stdio crlf encoding(shiftjis) utf8] ],
115 check([ PerlIO::get_layers(F) ],
121 check([ PerlIO::get_layers(F) ],
125 binmode(F, ":pop") if $DOSISH; # Drop one extra :crlf.
128 check([ PerlIO::get_layers(F) ],
132 binmode(F, ":bytes");
134 check([ PerlIO::get_layers(F) ],
138 binmode(F, ":encoding(utf8)");
140 check([ PerlIO::get_layers(F) ],
141 [ qw[stdio encoding(utf8) utf8] ],
144 binmode(F, ":raw :crlf");
146 check([ PerlIO::get_layers(F) ],
150 binmode(F, ":raw :encoding(latin1)"); # "latin1" will be canonized
153 skip("too complex layer coreography", 7) if $DOSISH || !$FASTSTDIO;
155 my @results = PerlIO::get_layers(F, details => 1);
157 # Get rid of the args and the flags.
158 splice(@results, 1, 2) if $NONSTDIO;
161 [ "stdio", undef, sub { $_[0] > 0 },
162 "encoding", "iso-8859-1", sub { $_[0] & PerlIO::F_UTF8() } ],
163 ":raw:encoding(latin1)");
168 check([ PerlIO::get_layers(F) ],
175 use open(IN => ":crlf", OUT => ":encoding(cp1252)");
180 check([ PerlIO::get_layers(F, input => 1) ],
184 check([ PerlIO::get_layers(G, output => 1) ],
185 [ qw[stdio encoding(cp1252) utf8] ],
192 1 while unlink "afile";