On 2013-09-10T23:46:43-04:00, DAGOLDEN wrote:
Show quoted text> Sorry. I just re-read what I wrote and realized it was still probably
> unclear.
I just ran across this as well. The attached test file may help make the problem explicit, and shows a very odd wrinkle as well -- namely, that it is the additional stack frame from Encode::decode is causing the lexical warnings to not be observed.
- Alex
#!/usr/bin/env perl
use strict;
use warnings;
use Encode;
use Test::More;
my $valid = "\x61\x00\x00\x00";
my $invalid = "\x78\x56\x34\x12";
my @warnings;
$SIG{__WARN__} = sub {push @warnings, "@_"};
my $enc = find_encoding("UTF32-LE");
diag "This is perl $^V, Encode $Encode::VERSION";
{
@warnings = ();
my $ret = Encode::Unicode::decode( $enc, $valid );
is("@warnings", "", "Calling decode in Encode::Unicode on valid string produces no warnings");
}
{
@warnings = ();
my $ret = Encode::Unicode::decode( $enc, $invalid );
like("@warnings", qr/is not Unicode/, "Calling decode in Encode::Unicode on invalid string warns");
}
{
no warnings 'utf8';
@warnings = ();
my $ret = Encode::Unicode::decode( $enc, $invalid );
is("@warnings", "", "Warning from decode in Encode::Unicode can be silenced via no warnings 'utf8'");
}
{
no warnings;
@warnings = ();
my $ret = Encode::Unicode::decode( $enc, $invalid );
is("@warnings", "", "Warning from decode in Encode::Unicode can be silenced via no warnings");
}
{
@warnings = ();
my $ret = Encode::decode( $enc, $invalid );
like("@warnings", qr/is not Unicode/, "Calling decode in Encode on invalid string warns");
}
{
no warnings 'utf8';
@warnings = ();
my $ret = Encode::decode( $enc, $invalid );
is("@warnings", "", "Warning from decode in Encode can be silenced via no warnings 'utf8'");
};
{
no warnings;
@warnings = ();
my $ret = Encode::decode( $enc, $invalid );
is("@warnings", "", "Warning from decode in Encode can be silenced via no warnings 'utf8'");
};
done_testing;
__END__
# This is perl v5.20.0, Encode 2.63
ok 1 - Method call on valid string produces no warnings
ok 2 - Method call on invalid string warns
ok 3 - Warning from method call can be silenced via no warnings 'utf8'
ok 4 - Warning from method call can be silenced via no warnings
ok 5 - Function call on invalid string warns
not ok 6 - Warning from function call can be silenced via no warnings 'utf8'
# Failed test 'Warning from function call can be silenced via no warnings 'utf8''
# at wat.pl line 55.
# got: 'Code point 0x12345678 is not Unicode, may not be portable at /home/chmrr/prog/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/x86_64-linux/Encode.pm line 175.
# '
# expected: ''
not ok 7 - Warning from function call can be silenced via no warnings 'utf8'
# Failed test 'Warning from function call can be silenced via no warnings 'utf8''
# at wat.pl line 62.
# got: 'Code point 0x12345678 is not Unicode, may not be portable at /home/chmrr/prog/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/x86_64-linux/Encode.pm line 175.
# '
# expected: ''
1..7
# Looks like you failed 2 tests of 7.