On Feb 24, 2008, at 12:02, Michael G Schwern wrote:
Test::Builder dups STDERR and STDOUT, this is so you can mess with
them to your heart's content and still get testing done. File I/O
disciplines don't appear to be copied across dups. That's what
everyone was complaining about, that they had to manually apply
layers to Test::Builder's own handles.
Why not add an interface to Test::Builder so that users can specify
encoding layers for its dup'd file handles?
use Test::More tests => 2, layer => ':utf8';
I'd probably make :utf8 the default, and apply it to STDOUT and STDERR
if running on Perl 5.6 or later. That way, any time something is
emitted via diag() that is in Perl's internal encoding, it will work
(provided, of course, that the user's terminal supports UTF-8, which
is not your problem). This would also allow someone to set the
encoding to something else if necessary:
use Test::More tests => 2, layer => ':encoding(shift-jis)';
The implementation would look something like this pseudo-code:
sub layers {
my ($self, $layer) = @_;
return unless PERL58;
bindmode *{ $duped_stdout }, $layer;
bindmode *{ $duped_stderr }, $layer;
}
I'v been wrestling with this stuff myself with SVN::Notify, which is
why I have an opinion. ;-)
HTH,
David