9 unless (find PerlIO::Layer 'perlio') {
10 print "1..0 # Skip: not perlio\n";
13 # Makes testing easier.
14 $ENV{PERLIO} = 'stdio' if exists $ENV{PERLIO} && $ENV{PERLIO} eq '';
15 if (exists $ENV{PERLIO} && $ENV{PERLIO} !~ /^(stdio|perlio|mmap)$/) {
16 # We are not prepared for anything else.
17 print "1..0 # PERLIO='$ENV{PERLIO}' unknown\n";
20 $PERLIO = exists $ENV{PERLIO} ? $ENV{PERLIO} : "(undef)";
27 my $DOSISH = $^O =~ /^(?:MSWin32|cygwin|os2|dos|NetWare|mint)$/ ? 1 : 0;
28 my $NONSTDIO = exists $ENV{PERLIO} && $ENV{PERLIO} ne 'stdio' ? 1 : 0;
29 my $FASTSTDIO = $Config{d_faststdio} && $Config{usefaststdio} ? 1 : 0;
34 # NONSTDIO = $NONSTDIO
35 # FASTSTDIO = $FASTSTDIO
39 skip("This perl does not have Encode", 43)
40 unless " $Config{extensions} " =~ / Encode /;
43 my ($result, $expected, $id) = @_;
44 # An interesting dance follows where we try to make the following
45 # IO layer stack setups to compare equal:
47 # PERLIO UNIX-like DOS-like
49 # unset / "" unix perlio / stdio [1] unix crlf
50 # stdio unix perlio / stdio [1] stdio
51 # perlio unix perlio unix perlio
52 # mmap unix mmap unix mmap
54 # [1] "stdio" if Configure found out how to do "fast stdio" (depends
55 # on the stdio implementation) and in Perl 5.8, otherwise "unix perlio"
59 shift @$result if $result->[0] eq "unix";
60 # Change expectations.
62 $expected->[0] = $ENV{PERLIO};
64 $expected->[0] = $ENV{PERLIO} if $expected->[0] eq "stdio";
66 } elsif (!$FASTSTDIO && !$DOSISH) {
67 splice(@$result, 0, 2, "stdio")
69 $result->[0] eq "unix" &&
70 $result->[1] eq "perlio";
72 splice(@$result, 0, 2, "stdio")
74 $result->[0] eq "unix" &&
75 $result->[1] eq "crlf";
77 my $n = scalar @$expected;
78 is($n, scalar @$expected, "$id - layers = $n");
79 for (my $i = 0; $i < $n; $i++) {
80 my $j = $expected->[$i];
81 if (ref $j eq 'CODE') {
82 ok($j->($result->[$i]), "$id - $i is ok");
85 sprintf("$id - $i is %s",
86 defined $j ? $j : "undef"));
91 check([ PerlIO::get_layers(STDIN) ],
95 open(F, ">:crlf", "afile");
97 check([ PerlIO::get_layers(F) ],
101 binmode(F, ":encoding(sjis)"); # "sjis" will be canonized to "shiftjis"
103 check([ PerlIO::get_layers(F) ],
104 [ qw[stdio crlf encoding(shiftjis) utf8] ],
109 check([ PerlIO::get_layers(F) ],
115 check([ PerlIO::get_layers(F) ],
119 binmode(F, ":pop") if $DOSISH; # Drop one extra :crlf.
122 check([ PerlIO::get_layers(F) ],
126 binmode(F, ":bytes");
128 check([ PerlIO::get_layers(F) ],
132 binmode(F, ":encoding(utf8)");
134 check([ PerlIO::get_layers(F) ],
135 [ qw[stdio encoding(utf8) utf8] ],
138 binmode(F, ":raw :crlf");
140 check([ PerlIO::get_layers(F) ],
144 binmode(F, ":raw :encoding(latin1)"); # "latin1" will be canonized
147 skip("too complex layer coreography", 7) if $DOSISH || !$FASTSTDIO;
149 my @results = PerlIO::get_layers(F, details => 1);
151 # Get rid of the args and the flags.
152 splice(@results, 1, 2) if $NONSTDIO;
155 [ "stdio", undef, sub { $_[0] > 0 },
156 "encoding", "iso-8859-1", sub { $_[0] & PerlIO::F_UTF8() } ],
157 ":raw:encoding(latin1)");
162 check([ PerlIO::get_layers(F) ],
169 use open(IN => ":crlf", OUT => ":encoding(cp1252)");
174 check([ PerlIO::get_layers(F, input => 1) ],
178 check([ PerlIO::get_layers(G, output => 1) ],
179 [ qw[stdio encoding(cp1252) utf8] ],
186 1 while unlink "afile";