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)";
30 my $DOSISH = $^O =~ /^(?:MSWin32|os2|dos|NetWare|mint)$/ ? 1 : 0;
31 $DOSISH = 1 if !$DOSISH and $^O =~ /^uwin/;
32 my $NONSTDIO = exists $ENV{PERLIO} && $ENV{PERLIO} ne 'stdio' ? 1 : 0;
33 my $FASTSTDIO = $Config{d_faststdio} && $Config{usefaststdio} ? 1 : 0;
35 my $NTEST = 43 - (($DOSISH || !$FASTSTDIO) ? 7 : 0) - ($DOSISH ? 5 : 0);
37 sub PerlIO::F_UTF8 () { 0x00008000 } # from perliol.h
44 # NONSTDIO = $NONSTDIO
45 # FASTSTDIO = $FASTSTDIO
49 # FIXME - more of these could be tested without Encode or full perl
50 skip("This perl does not have Encode", $NTEST)
51 unless " $Config{extensions} " =~ / Encode /;
52 skip("miniperl does not have Encode", $NTEST) if $ENV{PERL_CORE_MINITEST};
55 my ($result, $expected, $id) = @_;
56 # An interesting dance follows where we try to make the following
57 # IO layer stack setups to compare equal:
59 # PERLIO UNIX-like DOS-like
61 # unset / "" unix perlio / stdio [1] unix crlf
62 # stdio unix perlio / stdio [1] stdio
63 # perlio unix perlio unix perlio
64 # mmap unix mmap unix mmap
66 # [1] "stdio" if Configure found out how to do "fast stdio" (depends
67 # on the stdio implementation) and in Perl 5.8, otherwise "unix perlio"
71 shift @$result if $result->[0] eq "unix";
72 # Change expectations.
74 $expected->[0] = $ENV{PERLIO};
76 $expected->[0] = $ENV{PERLIO} if $expected->[0] eq "stdio";
78 } elsif (!$FASTSTDIO && !$DOSISH) {
79 splice(@$result, 0, 2, "stdio")
81 $result->[0] eq "unix" &&
82 $result->[1] eq "perlio";
84 splice(@$result, 0, 2, "stdio")
86 $result->[0] eq "unix" &&
87 $result->[1] eq "crlf";
89 if ($DOSISH && grep { $_ eq 'crlf' } @$expected) {
90 # 5 tests potentially skipped because
91 # DOSISH systems already have a CRLF layer
92 # which will make new ones not stick.
93 @$expected = grep { $_ ne 'crlf' } @$expected;
95 my $n = scalar @$expected;
96 is(scalar @$result, $n, "$id - layers == $n");
97 for (my $i = 0; $i < $n; $i++) {
98 my $j = $expected->[$i];
99 if (ref $j eq 'CODE') {
100 ok($j->($result->[$i]), "$id - $i is ok");
102 is($result->[$i], $j,
103 sprintf("$id - $i is %s",
104 defined $j ? $j : "undef"));
109 check([ PerlIO::get_layers(STDIN) ],
113 open(F, ">:crlf", "afile");
115 check([ PerlIO::get_layers(F) ],
119 binmode(F, ":encoding(sjis)"); # "sjis" will be canonized to "shiftjis"
121 check([ PerlIO::get_layers(F) ],
122 [ qw[stdio crlf encoding(shiftjis) utf8] ],
127 check([ PerlIO::get_layers(F) ],
133 check([ PerlIO::get_layers(F) ],
139 check([ PerlIO::get_layers(F) ],
143 binmode(F, ":bytes");
145 check([ PerlIO::get_layers(F) ],
149 binmode(F, ":encoding(utf8)");
151 check([ PerlIO::get_layers(F) ],
152 [ qw[stdio encoding(utf8) utf8] ],
155 binmode(F, ":raw :crlf");
157 check([ PerlIO::get_layers(F) ],
161 binmode(F, ":raw :encoding(latin1)"); # "latin1" will be canonized
163 # 7 tests potentially skipped.
164 unless ($DOSISH || !$FASTSTDIO) {
165 my @results = PerlIO::get_layers(F, details => 1);
167 # Get rid of the args and the flags.
168 splice(@results, 1, 2) if $NONSTDIO;
171 [ "stdio", undef, sub { $_[0] > 0 },
172 "encoding", "iso-8859-1", sub { $_[0] & PerlIO::F_UTF8() } ],
173 ":raw:encoding(latin1)");
178 check([ PerlIO::get_layers(F) ],
185 use open(IN => ":crlf", OUT => ":encoding(cp1252)");
190 check([ PerlIO::get_layers(F, input => 1) ],
194 check([ PerlIO::get_layers(G, output => 1) ],
195 [ qw[stdio encoding(cp1252) utf8] ],
202 1 while unlink "afile";