s/Nick Clark/Nicholas Clark/
[p5sagit/p5-mst-13.2.git] / t / io / layers.t
index 904ef93..62f77e8 100644 (file)
@@ -31,21 +31,40 @@ my $DOSISH    = $^O =~ /^(?:MSWin32|os2|dos|NetWare|mint)$/ ? 1 : 0;
    $DOSISH    = 1 if !$DOSISH and $^O =~ /^uwin/;
 my $NONSTDIO  = exists $ENV{PERLIO} && $ENV{PERLIO} ne 'stdio'     ? 1 : 0;
 my $FASTSTDIO = $Config{d_faststdio} && $Config{usefaststdio}      ? 1 : 0;
+my $UNICODE_STDIN;
+if (${^UNICODE} & 1) {
+    if (${^UNICODE} & 64) {
+       # Conditional on the locale
+       $UNICODE_STDIN = ${^UTF8LOCALE};
+    } else {
+       # Unconditional
+       $UNICODE_STDIN = 1;
+    }
+} else {
+    $UNICODE_STDIN = 0;
+}
+my $NTEST = 44 - (($DOSISH || !$FASTSTDIO) ? 7 : 0) - ($DOSISH ? 5 : 0)
+    + $UNICODE_STDIN;
 
-my $NTEST = 43 - (($DOSISH || !$FASTSTDIO) ? 7 : 0) - ($DOSISH ? 5 : 0);
+sub PerlIO::F_UTF8 () { 0x00008000 } # from perliol.h
 
 plan tests => $NTEST;
 
 print <<__EOH__;
-# PERLIO    = $PERLIO
-# DOSISH    = $DOSISH
-# NONSTDIO  = $NONSTDIO
-# FASTSTDIO = $FASTSTDIO
+# PERLIO        = $PERLIO
+# DOSISH        = $DOSISH
+# NONSTDIO      = $NONSTDIO
+# FASTSTDIO     = $FASTSTDIO
+# UNICODE       = ${^UNICODE}
+# UTF8LOCALE    = ${^UTF8LOCALE}
+# UNICODE_STDIN = $UNICODE_STDIN
 __EOH__
 
 SKIP: {
+    # FIXME - more of these could be tested without Encode or full perl
     skip("This perl does not have Encode", $NTEST)
        unless " $Config{extensions} " =~ / Encode /;
+    skip("miniperl does not have Encode", $NTEST) if $ENV{PERL_CORE_MINITEST};
 
     sub check {
        my ($result, $expected, $id) = @_;
@@ -89,7 +108,7 @@ SKIP: {
            @$expected = grep { $_ ne 'crlf' } @$expected;
        }
        my $n = scalar @$expected;
-       is($n, scalar @$expected, "$id - layers == $n");
+       is(scalar @$result, $n, "$id - layers == $n");
        for (my $i = 0; $i < $n; $i++) {
            my $j = $expected->[$i];
            if (ref $j eq 'CODE') {
@@ -103,7 +122,7 @@ SKIP: {
     }
 
     check([ PerlIO::get_layers(STDIN) ],
-         [ "stdio" ],
+         $UNICODE_STDIN ? [ "stdio", "utf8" ] : [ "stdio" ],
          "STDIN");
 
     open(F, ">:crlf", "afile");
@@ -195,5 +214,12 @@ SKIP: {
        close G;
     }
 
+    # Check that PL_sigwarn's reference count is correct, and that 
+    # &PerlIO::Layer::NoWarnings isn't prematurely freed.
+    fresh_perl_like (<<'EOT', qr/^CODE/);
+open(UTF, "<:raw:encoding(utf8)", "afile") or die $!;
+print ref *PerlIO::Layer::NoWarnings{CODE};
+EOT
+
     1 while unlink "afile";
 }