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;
34 # FIXME. I think that we'll be needing ${^UTF8_LOCALE}
35 # This is a hack that assumes that no-one will use -C or -C65 (etc)
36 # without also having a UTF8 locale. Hopefully the smoke tests will pass.
37 my $UNICODE_STDIN = ${^UNICODE} & 1;
38 my $NTEST = 43 - (($DOSISH || !$FASTSTDIO) ? 7 : 0) - ($DOSISH ? 5 : 0)
41 sub PerlIO::F_UTF8 () { 0x00008000 } # from perliol.h
48 # NONSTDIO = $NONSTDIO
49 # FASTSTDIO = $FASTSTDIO
50 # UNICODE = ${^UNICODE}
51 # UNICODE_STDIN = $UNICODE_STDIN
55 # FIXME - more of these could be tested without Encode or full perl
56 skip("This perl does not have Encode", $NTEST)
57 unless " $Config{extensions} " =~ / Encode /;
58 skip("miniperl does not have Encode", $NTEST) if $ENV{PERL_CORE_MINITEST};
61 my ($result, $expected, $id) = @_;
62 # An interesting dance follows where we try to make the following
63 # IO layer stack setups to compare equal:
65 # PERLIO UNIX-like DOS-like
67 # unset / "" unix perlio / stdio [1] unix crlf
68 # stdio unix perlio / stdio [1] stdio
69 # perlio unix perlio unix perlio
70 # mmap unix mmap unix mmap
72 # [1] "stdio" if Configure found out how to do "fast stdio" (depends
73 # on the stdio implementation) and in Perl 5.8, otherwise "unix perlio"
77 shift @$result if $result->[0] eq "unix";
78 # Change expectations.
80 $expected->[0] = $ENV{PERLIO};
82 $expected->[0] = $ENV{PERLIO} if $expected->[0] eq "stdio";
84 } elsif (!$FASTSTDIO && !$DOSISH) {
85 splice(@$result, 0, 2, "stdio")
87 $result->[0] eq "unix" &&
88 $result->[1] eq "perlio";
90 splice(@$result, 0, 2, "stdio")
92 $result->[0] eq "unix" &&
93 $result->[1] eq "crlf";
95 if ($DOSISH && grep { $_ eq 'crlf' } @$expected) {
96 # 5 tests potentially skipped because
97 # DOSISH systems already have a CRLF layer
98 # which will make new ones not stick.
99 @$expected = grep { $_ ne 'crlf' } @$expected;
101 my $n = scalar @$expected;
102 is(scalar @$result, $n, "$id - layers == $n");
103 for (my $i = 0; $i < $n; $i++) {
104 my $j = $expected->[$i];
105 if (ref $j eq 'CODE') {
106 ok($j->($result->[$i]), "$id - $i is ok");
108 is($result->[$i], $j,
109 sprintf("$id - $i is %s",
110 defined $j ? $j : "undef"));
115 check([ PerlIO::get_layers(STDIN) ],
116 $UNICODE_STDIN ? [ "stdio", "utf8" ] : [ "stdio" ],
119 open(F, ">:crlf", "afile");
121 check([ PerlIO::get_layers(F) ],
125 binmode(F, ":encoding(sjis)"); # "sjis" will be canonized to "shiftjis"
127 check([ PerlIO::get_layers(F) ],
128 [ qw[stdio crlf encoding(shiftjis) utf8] ],
133 check([ PerlIO::get_layers(F) ],
139 check([ PerlIO::get_layers(F) ],
145 check([ PerlIO::get_layers(F) ],
149 binmode(F, ":bytes");
151 check([ PerlIO::get_layers(F) ],
155 binmode(F, ":encoding(utf8)");
157 check([ PerlIO::get_layers(F) ],
158 [ qw[stdio encoding(utf8) utf8] ],
161 binmode(F, ":raw :crlf");
163 check([ PerlIO::get_layers(F) ],
167 binmode(F, ":raw :encoding(latin1)"); # "latin1" will be canonized
169 # 7 tests potentially skipped.
170 unless ($DOSISH || !$FASTSTDIO) {
171 my @results = PerlIO::get_layers(F, details => 1);
173 # Get rid of the args and the flags.
174 splice(@results, 1, 2) if $NONSTDIO;
177 [ "stdio", undef, sub { $_[0] > 0 },
178 "encoding", "iso-8859-1", sub { $_[0] & PerlIO::F_UTF8() } ],
179 ":raw:encoding(latin1)");
184 check([ PerlIO::get_layers(F) ],
191 use open(IN => ":crlf", OUT => ":encoding(cp1252)");
196 check([ PerlIO::get_layers(F, input => 1) ],
200 check([ PerlIO::get_layers(G, output => 1) ],
201 [ qw[stdio encoding(cp1252) utf8] ],
208 1 while unlink "afile";