This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PerlIO-encoding/t/fallback.t: test for warning
authorDavid Mitchell <davem@iabyn.com>
Tue, 21 Jun 2016 12:28:19 +0000 (13:28 +0100)
committerDavid Mitchell <davem@iabyn.com>
Tue, 21 Jun 2016 12:28:19 +0000 (13:28 +0100)
The previous commit fixed a typo that had been present since this test
script was created: WARN_ON_ERR misspelt as WARN_ON_ERROR.  This means
that one of the tests is now (correctly) issuing a warning.  Rather than
that spilling out onto STDERR, capture it and test it instead.

ext/PerlIO-encoding/t/fallback.t

index d46e181..cf3fdc3 100644 (file)
@@ -16,7 +16,7 @@ BEGIN {
     import Encode qw(:fallback_all);
 }
 
-use Test::More tests => 9;
+use Test::More tests => 10;
 
 # $PerlIO::encoding = 0; # WARN_ON_ERR|PERLQQ;
 
@@ -64,13 +64,20 @@ printf "# %x\n",ord($line);
 is($line,"\\xA30.02\n","Escaped non-mapped char");
 close($fh);
 
-$PerlIO::encoding::fallback = Encode::WARN_ON_ERR;
+{
+    my $message = '';
+    local $SIG{__WARN__} = sub { $message = $_[0] };
 
-ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
-my $line = <$fh>;
-printf "# %x\n",ord($line);
-is($line,"\x{FFFD}0.02\n","Unicode replacement char");
-close($fh);
+    $PerlIO::encoding::fallback = Encode::WARN_ON_ERR;
+
+    ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
+    my $line = <$fh>;
+    printf "# %x\n",ord($line);
+    is($line,"\x{FFFD}0.02\n","Unicode replacement char");
+    close($fh);
+
+    like($message, qr/does not map to Unicode/o, "FB_WARN message");
+}
 
 END {
     1 while unlink($file);