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;
30 $Config{d_stdstdio} &&
31 $Config{d_stdio_ptr_lval} &&
32 ($Config{d_stdio_cnt_lval} ||
33 $Config{d_stdio_ptr_lval_sets_cnt}) ? 1 : 0;
38 # NONSTDIO = $NONSTDIO
39 # FASTSTDIO = $FASTSTDIO
43 skip("This perl does not have Encode", 43)
44 unless " $Config{extensions} " =~ / Encode /;
47 my ($result, $expected, $id) = @_;
48 # An interesting dance follows where we try to make the following
49 # IO layer stack setups to compare equal:
51 # PERLIO UNIX-like DOS-like
53 # none or "" stdio [1] unix crlf
54 # stdio stdio [1] stdio
55 # perlio unix perlio unix perlio
56 # mmap unix mmap unix mmap
58 # [1] If Configure found how to do "fast stdio",
59 # otherwise it will be "unix perlio".
63 shift @$result if $result->[0] eq "unix";
64 # Change expectations.
66 $expected->[0] = $ENV{PERLIO};
68 $expected->[0] = $ENV{PERLIO} if $expected->[0] eq "stdio";
70 } elsif (!$FASTSTDIO) {
71 splice(@$result, 0, 2, "stdio")
73 $result->[0] eq "unix" &&
74 $result->[1] eq "perlio";
76 splice(@$result, 0, 2, "stdio")
78 $result->[0] eq "unix" &&
79 $result->[1] eq "crlf";
81 my $n = scalar @$expected;
82 is($n, scalar @$expected, "$id - layers = $n");
83 for (my $i = 0; $i < $n; $i++) {
84 my $j = $expected->[$i];
85 if (ref $j eq 'CODE') {
86 ok($j->($result->[$i]), "$id - $i is ok");
89 sprintf("$id - $i is %s",
90 defined $j ? $j : "undef"));
95 check([ PerlIO::get_layers(STDIN) ],
99 open(F, ">:crlf", "afile");
101 check([ PerlIO::get_layers(F) ],
105 binmode(F, ":encoding(sjis)"); # "sjis" will be canonized to "shiftjis"
107 check([ PerlIO::get_layers(F) ],
108 [ qw[stdio crlf encoding(shiftjis) utf8] ],
113 check([ PerlIO::get_layers(F) ],
119 check([ PerlIO::get_layers(F) ],
123 binmode(F, ":pop") if $DOSISH; # Drop one extra :crlf.
126 check([ PerlIO::get_layers(F) ],
130 binmode(F, ":bytes");
132 check([ PerlIO::get_layers(F) ],
136 binmode(F, ":encoding(utf8)");
138 check([ PerlIO::get_layers(F) ],
139 [ qw[stdio encoding(utf8) utf8] ],
142 binmode(F, ":raw :crlf");
144 check([ PerlIO::get_layers(F) ],
148 binmode(F, ":raw :encoding(latin1)"); # "latin1" will be canonized
151 skip("too complex layer coreography", 7) if $DOSISH || !$FASTSTDIO;
153 my @results = PerlIO::get_layers(F, details => 1);
155 # Get rid of the args and the flags.
156 splice(@results, 1, 2) if $NONSTDIO;
159 [ "stdio", undef, sub { $_[0] > 0 },
160 "encoding", "iso-8859-1", sub { $_[0] & PerlIO::F_UTF8() } ],
161 ":raw:encoding(latin1)");
166 check([ PerlIO::get_layers(F) ],
173 use open(IN => ":crlf", OUT => ":encoding(cp1252)");
178 check([ PerlIO::get_layers(F, input => 1) ],
182 check([ PerlIO::get_layers(G, output => 1) ],
183 [ qw[stdio encoding(cp1252) utf8] ],
190 1 while unlink "afile";