False alarm: no cyclic dependency.
[p5sagit/p5-mst-13.2.git] / t / io / layers.t
index 1596d72..8b84cf5 100644 (file)
@@ -4,27 +4,37 @@ BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';
     require './test.pl';
+    unless (find PerlIO::Layer 'perlio') {
+       print "1..0 # Skip: not perlio\n";
+       exit 0;
+    }
 }
 
 plan tests => 43;
 
 use Config;
 
-{
-    skip("This perl does not have perlio and Encode", 43)
-       unless $Config{useperlio} && " $Config{extensions} " =~ / Encode /;
+SKIP: {
+    skip("This perl does not have Encode", 43)
+       unless " $Config{extensions} " =~ / Encode /;
 
     sub check {
        my ($result, $expected, $id) = @_;
        my $n = scalar @$expected;
-       is($n, scalar @$expected, "$id layers = $n");
+       is($n, scalar @$expected, "$id - layers = $n");
+       if ($ENV{PERLIO}) {
+           # Get rid of "unix" and similar OS-specific low lever layer.
+           shift(@$result);
+           # Change expectations.
+           $expected->[0] = "perlio" if $expected->[0] eq "stdio";
+       }
        for (my $i = 0; $i < $n; $i++) {
            my $j = $expected->[$i];
            if (ref $j eq 'CODE') {
-               ok($j->($result->[$i]), "$id $i is ok");
+               ok($j->($result->[$i]), "$id - $i is ok");
            } else {
                is($result->[$i], $j,
-                  sprintf("$id $i is %s", defined $j ? $j : "undef"));
+                  sprintf("$id - $i is %s", defined $j ? $j : "undef"));
            }
        }
     }
@@ -83,10 +93,17 @@ use Config;
 
     binmode(F, ":raw :encoding(latin1)"); # "latin1" will be canonized
 
-    check([ PerlIO::get_layers(F, details => 1) ],
-         [ "stdio",    undef,        sub { $_[0] > 0 },
-           "encoding", "iso-8859-1", sub { $_[0] & PerlIO::F_UTF8() } ],
-         ":raw:encoding(latin1)");
+    {
+       my @results = PerlIO::get_layers(F, details => 1);
+
+       # Get rid of "unix" and undef.
+       splice(@results, 0, 2) if $ENV{PERLIO};
+
+       check([ @results ],
+             [ "stdio",    undef,        sub { $_[0] > 0 },
+               "encoding", "iso-8859-1", sub { $_[0] & PerlIO::F_UTF8() } ],
+             ":raw:encoding(latin1)");
+    }
 
     binmode(F);
 
@@ -98,6 +115,7 @@ use Config;
 
     {
        use open(IN => ":crlf", OUT => ":encoding(cp1252)");
+
        open F, "<afile";
        open G, ">afile";