Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yath extra-UTF8-encodes #187

Open
FGasper opened this issue Jun 22, 2020 · 0 comments
Open

yath extra-UTF8-encodes #187

FGasper opened this issue Jun 22, 2020 · 0 comments

Comments

@FGasper
Copy link

FGasper commented Jun 22, 2020

#!/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant