Skip Menu |

This queue is for tickets about the Test-Trap CPAN distribution.

Report information
The Basics
Id: 91686
Status: resolved
Priority: 0/
Queue: Test-Trap

People
Owner: ebhanssen [...] allverden.no
Requestors: zurom [...] mail.ru
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in:
  • v0.2.5.0_1
  • v0.2.5.0_2
  • v0.3.0



Subject: No UTF support
No UTF support To get it work properly one shoud do smth like this my $got = $trap->stdout; utf8::decode( $got );
On 2013-12-27 13:03:01, http://zurom.id.mail.ru/ wrote: Show quoted text
> No UTF support > > To get it work properly one shoud do smth like this > my $got = $trap->stdout; > utf8::decode( $got );
It was not actually UTF support that was missing, but rather support for PerlIO layers. In other stuff, like return values, exceptions, and warnings, there has never been a problem with UTF. But in output capturing, everything was "output" on a handle with default layers. Which are raw (various unix/stdio/perlio-combos) on Unix and raw:crlf on Windows. No support for encodings. You get a warning, and the bytes of the internal representation are printed – and trapped. Now, in v0.2.5.0_1 (0.3.0 candidate?) I've added support for encodings. In the simplest form, you can ask for the trap to preserve the original handle's layers (replicating them to the handles for writing to and reading from the tempfile), and make sure the interesting handles specify the encoding: use Test::Trap qw/ :output(tempfile-preserve) /; # or qw/ :output(systemsafe-preserve) / binmode STDOUT, 'utf8'; binmode STDERR, 'utf8'; trap { ... }; my $got = $trap->stdout; # UTF handled, as STDOUT already had :utf8 ... or you could declare your own strategy: use Test::Trap::Builder::TempFile # or ::SystemSafe 'my-strategy', { io_layers => 'utf8' }; use Test::Trap qw / :output(my-strategy) /; trap { ... }; my $got = $trap->stdout; # UTF handled, not matter what layers STDOUT already had I've added no such support to Test::Trap::Builder::PerlIO, since it doesn't seem as if a utf8 layer on a PerlIO::scalar does anything more than silence the warning. :-\ (I'm not sure it's worth complicating Test::Trap::Builder::PerlIO for that. It's supposed to be light. Anyone who needs something more complicated could just write a strategy themselves. But I'll ponder it.) -- Eirik Berg Hanssen, ebhanssen@cpan.org Just this .sig then nothing more