You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/env perl
use Test::More;
use File::Temp;
my $tfh = File::Temp::tempfile();
my $str = "¡Hola!\n";
{
my $redir = Redirect->new( \*STDOUT => $tfh );
print $str;
}
my $out = do {
sysseek $tfh, 0, 0;
local $/;
readline $tfh;
};
is( $out, $str, 'expect' );
done_testing();
#----------------------------------------------------------------------
package Redirect;
sub new {
my ($class) = @_;
open( my $orig_from, '>&', $_[1] ) or die "$class: failed to save “from”: $!";
open( $_[1], '>&', $_[2] ) or die "$class: failed to redirect: $!";
return bless [ $_[1], $orig_from ], $class;
}
sub DESTROY {
my ($self) = @_;
open $self->[0], '>&', $self->[1] or die "$self: failed to restore original “from”: $!";
return;
}
prove handles this fine, but yath messes it up:
> yath test_redir.pl
** Defaulting to the 'test' command **
[ FAIL ] job 1 + expect
( DIAG ) job 1 Failed test 'expect'
( DIAG ) job 1 at test_redir.pl line 23.
( DIAG ) job 1 got: '¡Hola!
( DIAG ) job 1 '
( DIAG ) job 1 expected: '�Hola!
( DIAG ) job 1 '
( DIAG ) job 1 Looks like you failed 1 test of 1.
( FAILED ) job 1 test_redir.pl
< REASON > job 1 Test script returned error (Err: 1)
< REASON > job 1 ----- START -----
Assertion failures were encountered (Count: 1)
< REASON > job 1 ------ END ------
An strace shows that the write to STDOUT is being UTF-8-encoded; since the string is already encoded, then, it’s garbling.
The text was updated successfully, but these errors were encountered:
prove
handles this fine, butyath
messes it up:An strace shows that the write to STDOUT is being UTF-8-encoded; since the string is already encoded, then, it’s garbling.
The text was updated successfully, but these errors were encountered: