7 unless (find PerlIO::Layer 'perlio') {
8 print "1..0 # Skip: not perlio\n";
11 if (exists $ENV{PERLIO} && $ENV{PERLIO} !~ /^(stdio|perlio|mmap)$/) {
12 print "1..0 # PERLIO='$ENV{PERLIO}' unknown\n";
21 my $DOSISH = $^O =~ /^(?:MSWin32|cygwin|os2|dos|NetWare|mint)$/;
22 my $NONSTDIO = exists $ENV{PERLIO} && $ENV{PERLIO} ne 'stdio';
25 skip("This perl does not have Encode", 43)
26 unless " $Config{extensions} " =~ / Encode /;
29 my ($result, $expected, $id) = @_;
32 shift @$result if $result->[0] eq "unix";
33 # Change expectations.
34 $expected->[0] = $ENV{PERLIO} if $expected->[0] eq "stdio";
36 splice(@$result, 0, 2, "stdio")
37 if $result->[0] eq "unix" &&
38 $result->[1] eq "crlf";
40 my $n = scalar @$expected;
41 is($n, scalar @$expected, "$id - layers = $n");
42 for (my $i = 0; $i < $n; $i++) {
43 my $j = $expected->[$i];
44 if (ref $j eq 'CODE') {
45 ok($j->($result->[$i]), "$id - $i is ok");
48 sprintf("$id - $i is %s",
49 defined $j ? $j : "undef"));
54 check([ PerlIO::get_layers(STDIN) ],
58 open(F, ">:crlf", "afile");
60 check([ PerlIO::get_layers(F) ],
64 binmode(F, ":encoding(sjis)"); # "sjis" will be canonized to "shiftjis"
66 check([ PerlIO::get_layers(F) ],
67 [ qw[stdio crlf encoding(shiftjis) utf8] ],
72 check([ PerlIO::get_layers(F) ],
78 check([ PerlIO::get_layers(F) ],
82 binmode(F, ":pop") if $DOSISH; # Drop one extra :crlf.
85 check([ PerlIO::get_layers(F) ],
91 check([ PerlIO::get_layers(F) ],
95 binmode(F, ":encoding(utf8)");
97 check([ PerlIO::get_layers(F) ],
98 [ qw[stdio encoding(utf8) utf8] ],
101 binmode(F, ":raw :crlf");
103 check([ PerlIO::get_layers(F) ],
107 binmode(F, ":raw :encoding(latin1)"); # "latin1" will be canonized
110 skip("too complex layer coreography", 7) if $DOSISH;
112 my @results = PerlIO::get_layers(F, details => 1);
114 # Get rid of the args and the flags.
115 splice(@results, 1, 2) if $NONSTDIO;
118 [ "stdio", undef, sub { $_[0] > 0 },
119 "encoding", "iso-8859-1", sub { $_[0] & PerlIO::F_UTF8() } ],
120 ":raw:encoding(latin1)");
125 check([ PerlIO::get_layers(F) ],
132 use open(IN => ":crlf", OUT => ":encoding(cp1252)");
137 check([ PerlIO::get_layers(F, input => 1) ],
141 check([ PerlIO::get_layers(G, output => 1) ],
142 [ qw[stdio encoding(cp1252) utf8] ],
149 1 while unlink "afile";