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|cygwin|os2|dos|NetWare|mint)$/ ? 1 : 0;
33 my $NONSTDIO = exists $ENV{PERLIO} && $ENV{PERLIO} ne 'stdio' ? 1 : 0;
34 my $FASTSTDIO = $Config{d_faststdio} && $Config{usefaststdio} ? 1 : 0;
39 # NONSTDIO = $NONSTDIO
40 # FASTSTDIO = $FASTSTDIO
44 skip("This perl does not have Encode", 43)
45 unless " $Config{extensions} " =~ / Encode /;
48 my ($result, $expected, $id) = @_;
49 # An interesting dance follows where we try to make the following
50 # IO layer stack setups to compare equal:
52 # PERLIO UNIX-like DOS-like
54 # unset / "" unix perlio / stdio [1] unix crlf
55 # stdio unix perlio / stdio [1] stdio
56 # perlio unix perlio unix perlio
57 # mmap unix mmap unix mmap
59 # [1] "stdio" if Configure found out how to do "fast stdio" (depends
60 # on the stdio implementation) and in Perl 5.8, otherwise "unix perlio"
64 shift @$result if $result->[0] eq "unix";
65 # Change expectations.
67 $expected->[0] = $ENV{PERLIO};
69 $expected->[0] = $ENV{PERLIO} if $expected->[0] eq "stdio";
71 } elsif (!$FASTSTDIO && !$DOSISH) {
72 splice(@$result, 0, 2, "stdio")
74 $result->[0] eq "unix" &&
75 $result->[1] eq "perlio";
77 splice(@$result, 0, 2, "stdio")
79 $result->[0] eq "unix" &&
80 $result->[1] eq "crlf";
82 my $n = scalar @$expected;
83 is($n, scalar @$expected, "$id - layers = $n");
84 for (my $i = 0; $i < $n; $i++) {
85 my $j = $expected->[$i];
86 if (ref $j eq 'CODE') {
87 ok($j->($result->[$i]), "$id - $i is ok");
90 sprintf("$id - $i is %s",
91 defined $j ? $j : "undef"));
96 check([ PerlIO::get_layers(STDIN) ],
100 open(F, ">:crlf", "afile");
102 check([ PerlIO::get_layers(F) ],
106 binmode(F, ":encoding(sjis)"); # "sjis" will be canonized to "shiftjis"
108 check([ PerlIO::get_layers(F) ],
109 [ qw[stdio crlf encoding(shiftjis) utf8] ],
114 check([ PerlIO::get_layers(F) ],
120 check([ PerlIO::get_layers(F) ],
124 binmode(F, ":pop") if $DOSISH; # Drop one extra :crlf.
127 check([ PerlIO::get_layers(F) ],
131 binmode(F, ":bytes");
133 check([ PerlIO::get_layers(F) ],
137 binmode(F, ":encoding(utf8)");
139 check([ PerlIO::get_layers(F) ],
140 [ qw[stdio encoding(utf8) utf8] ],
143 binmode(F, ":raw :crlf");
145 check([ PerlIO::get_layers(F) ],
149 binmode(F, ":raw :encoding(latin1)"); # "latin1" will be canonized
152 skip("too complex layer coreography", 7) if $DOSISH || !$FASTSTDIO;
154 my @results = PerlIO::get_layers(F, details => 1);
156 # Get rid of the args and the flags.
157 splice(@results, 1, 2) if $NONSTDIO;
160 [ "stdio", undef, sub { $_[0] > 0 },
161 "encoding", "iso-8859-1", sub { $_[0] & PerlIO::F_UTF8() } ],
162 ":raw:encoding(latin1)");
167 check([ PerlIO::get_layers(F) ],
174 use open(IN => ":crlf", OUT => ":encoding(cp1252)");
179 check([ PerlIO::get_layers(F, input => 1) ],
183 check([ PerlIO::get_layers(G, output => 1) ],
184 [ qw[stdio encoding(cp1252) utf8] ],
191 1 while unlink "afile";