Test::BDD::Cucumber::Harness::Html breaks UTF-8 characters

Viewed 184

When I try to print a JSON in a test name using the Test::BDD::Cucumber::Harness::Html i get the the character broken and the following error message:

Wide character in print at /home/dragos/perl5/perlbrew/perls/perl-5.26.3/lib/site_perl/5.26.3/Test2/Formatter/TAP.pm line 125
  • The command I run is the following:
pherkin -oHtml mockserver > mockTest.html
  • The code that is executed is following:
use Test2::V0;

  Then
    qr/test utf8 string/,
    sub {
      my $data =  Mojo::File->new('test.json')->slurp();

      $data = Encode::decode('utf8', $data);
      is(1, 1, $data);
      is $server->get(S->{'url'}),
        'Hello stranger.', 'Welcome screen found';
    };

  • The JSON body is:
{
  "address5": "DUMLUPINAR MAHALLESİ",
}

The result looks like this:

ok 1 - {
    #        "address5": "DUMLUPINAR MAHALLESİ",
    #      }
    #      
1 Answers

The pherkin ouput utf8 encoded. Capture it with back ticks and decode it the write it to a file.

use Encode qw(decode encode encode_utf8);
use autodie;
 

    my $filename = 'test.html';
    # capture  STDOUT and decode the utf8 chars
    # App::pherkin::_pre_run
    # and Test::BDD::Cucumber::Executor::_test_output
    # both open STDOUT in utf8 mode 
    my $output = `pherkin -oHtml mockserver`;
    open( my $fh, '>', $filename );
    print $fh decode('utf8', $output);
Related