I ran into the exact same problem while testing Perl6::Str, and I worked around it with the following sub, through which I piped all my output to diag(). It doesn't display the non-ASCII-Characters, but it does enable very detailed analysis even on non-utf-8 terminals:
use charnames ();
sub escape_str {
my $str = shift;
$str =~ s{([^\0-\177])}{_N_escape($1)}eg;
return $str;
}
sub _N_escape {
return '\N{' . charnames::viacode(ord($_[0])) . '}';
}
However your post encouraged me to dig into Test::More source code, and in Test::Builder I found this code:
sub _print_diag {
my $self = shift;
local($\, $", $,) = (undef, ' ', '');
my $fh = $self->todo ? $self->todo_output : $self->failure_output;
print $fh @_;
}
So it seems you have to get hold of a test builder object, and then binmode todo_output or failure_output (or both):
$ perl -MTest::More -wle 'binmode Test::More->builder->failure_output,
+ ":utf8"; diag chr(228)'
# ä
Not pretty, but it works. |