gpt4 book ai didi

perl - Test::BDD::Cucumber::Harness::Html 中断 UTF-8 字符

转载 作者:行者123 更新时间:2023-12-04 03:24:08 25 4
gpt4 key购买 nike

当我尝试使用 Test::BDD::Cucumber::Harness::Html 在测试名称中打印 JSON 时,我得到了损坏的字符和以下错误消息:

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
  • 我运行的命令如下:
pherkin -oHtml mockserver > mockTest.html
  • 执行的代码如下:
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';
};

  • JSON 正文是:
{
"address5": "DUMLUPINAR MAHALLESİ",
}

结果是这样的:

ok 1 - {
# "address5": "DUMLUPINAR MAHALLESÄ°",
# }
#

最佳答案

小 cucumber 输出 utf 8 编码。用反引号捕获它并对其进行解码并将其写入文件。

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);

关于perl - Test::BDD::Cucumber::Harness::Html 中断 UTF-8 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67971552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com