Discussion:
Fatal "wide character" warnings in tests
Ovid
2012-01-29 21:55:46 UTC
Permalink
How do I make "Wide character in print" warnings fatal in tests?

This test passes;

    use Test::More;                                                                                                                                          
    use strict;
    use warnings;
    use warnings FATAL => 'utf8';
    use utf8::all;
    my $string = '日本国';
    my $length = length($string);
    is $length, 3, "$string should have $length characters";
    diag $string;
    done_testing;

That's passing because the warnings pragma is lexically scoped and the actual warnings are emitted in Test::Builder guts (utf8::all will let the test pass because that package's code is now marked as utf8, but it doesn't fix Test::Builder's filehandles). I can make the warnings go away with this:

    my $output = Test::Builder->new->todo_output;
    binmode $output, ':encoding(UTF-8)';
    $output = Test::Builder->new->failure_output;
    binmode $output, ':encoding(UTF-8)'; 

But I'd really like a clean way of just saying "kill my code if I ever see 'Wide character in print'" regardless of which package the error is emitted from.

Cheers,
Ovid
--
Live and work overseas - http://overseas-exile.blogspot.com/
Buy the book           - http://www.oreilly.com/catalog/perlhks/
Tech blog              - http://blogs.perl.org/users/ovid/
Twitter                - http://twitter.com/OvidPerl/ 
David Golden
2012-01-30 00:19:59 UTC
Permalink
Hook %SIG?

David
Post by Ovid
How do I make "Wide character in print" warnings fatal in tests?
This test passes;
use Test::More;
use strict;
use warnings;
use warnings FATAL => 'utf8';
use utf8::all;
my $string = '日本囜';
my $length = length($string);
is $length, 3, "$string should have $length characters";
diag $string;
done_testing;
That's passing because the warnings pragma is lexically scoped and the
actual warnings are emitted in Test::Builder guts (utf8::all will let the
test pass because that package's code is now marked as utf8, but it doesn't
my $output = Test::Builder->new->todo_output;
binmode $output, ':encoding(UTF-8)';
$output = Test::Builder->new->failure_output;
binmode $output, ':encoding(UTF-8)';
But I'd really like a clean way of just saying "kill my code if I ever see
'Wide character in print'" regardless of which package the error is emitted
from.
Cheers,
Ovid
--
Live and work overseas - http://overseas-exile.blogspot.com/
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog - http://blogs.perl.org/users/ovid/
Twitter - http://twitter.com/OvidPerl/
Gabor Szabo
2012-01-30 06:04:53 UTC
Permalink
Post by Ovid
How do I make "Wide character in print" warnings fatal in tests?
Test::NoWarnings catches all forms of warnings in your test, not only
the specific one you mentioned.
Maybe that could be used/changed.

Gabor
--
Gabor Szabo
http://szabgab.com/
Ovid
2012-01-30 08:30:50 UTC
Permalink
I wound up stopping use of that module many years ago, but maybe I should look at creating an alternative to Test::NoWarnings. It's caused me so much grief over the years due to how it diddle's Test::More's plan that maybe it's time to scratch this itch and my Wide Character issue at the same time.

Cheers,
Ovid 
-- 
Live and work overseas - http://overseas-exile.blogspot.com/ 
Buy the book - http://www.oreilly.com/catalog/perlhks/ 
Tech blog - http://blogs.perl.org/users/ovid/ 
Twitter - http://twitter.com/OvidPerl/


----- Original Message -----
Sent: Monday, 30 January 2012, 7:04
Subject: Re: Fatal "wide character" warnings in tests
Post by Ovid
How do I make "Wide character in print" warnings fatal in tests?
Test::NoWarnings catches all forms of warnings in your test, not only
the specific one you mentioned.
Maybe that could be used/changed.
Gabor
--
Gabor Szabo
http://szabgab.com/
Buddy Burden
2012-02-02 03:33:17 UTC
Permalink
Ovid,

Perhaps I'm misunderstanding, but couldn't you just wrap the guts of
it (or the whole thing) inside a

warning_is { ... } undef, "No warnings from UTF8 stuff";

type construct? That gives you a failing test, which, in conjunction
with your very excellent Test::Most and judiciious use of
$BAIL_ON_FAIL should handle the killing part ...


            -- Buddy
Christian Walde
2012-02-09 16:26:55 UTC
Permalink
Post by Ovid
I wound up stopping use of that module many years ago, but maybe I should look at creating an alternative to Test::NoWarnings. It's caused me so much grief over the years due to how it diddle's Test::More's plan that maybe it's time to scratch this itch and my Wide Character issue at the same time.
You could just start using https://metacpan.org/module/strictures in the code where you want those warnings to die. :)
--
With regards,
Christian Walde
Loading...