为什么这个输出在perl单元测试中重复?
我正在比较的输出字符串被复制,导致测试失败,但我不知道为什么 这是我的测试文件:为什么这个输出在perl单元测试中重复?,perl,unit-testing,output,Perl,Unit Testing,Output,我正在比较的输出字符串被复制,导致测试失败,但我不知道为什么 这是我的测试文件: use lib ('./t/lib/'); use strict; use warnings; use Template; use Test::More tests => 1; # options/configuration for template #my $config = { #PRE_PROCESS => 1, # means the templates processed c
use lib ('./t/lib/');
use strict;
use warnings;
use Template;
use Test::More tests => 1;
# options/configuration for template
#my $config = {
#PRE_PROCESS => 1, # means the templates processed can use the same global vars defined earlier
#INTERPOLATE => 1,
#EVAL_PERL => 1,
# RELATIVE => 1,
# OUTPUT_PATH => './out',
# };
my $template = Template->new();
# input string
my $text = "This is string number [% num %] .";
# template placeholder variables
my $vars = {
num => "one",
};
my $output = shift;
my $expected_output = "This is string number one .";
# processes input string and inserts placeholder values
$template->process(\$text, $vars, \$output)
|| die "Template process failed: ", $template->error(), "\n";
# If process method is executed successfully it should have a return value of 1
diag($template->process(\$text, $vars, \$output));
# compares actual output with the expected output
is($output, $expected_output);
下面是我失败测试的输出:
t/68_template_test.t
t/68_template_test.t .. # 1
t/68_template_test.t .. 1/1
# Failed test at t/68_template_test.t line 45.
# got: 'This is string number one .This is string number one .'
# expected: 'This is string number one .'
# Looks like you failed 1 test of 1.
t/68_template_test.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/1 subtests
我似乎无法发现这个bug,也无法找出发生这种情况的原因。有两个调用
$template->process(\$text,\$vars,\$output)
我想你想要
my $rv = $template->process(\$text, $vars, \my $output);
ok($rv, "\$template->process ran successfully")
and note($rv)
or diag($template->error());
is($output, $expected_output, "\$template->process produced correct output");
有两个对
$template->process(\$text,\$vars,\$output)
的调用
我想你想要
my $rv = $template->process(\$text, $vars, \my $output);
ok($rv, "\$template->process ran successfully")
and note($rv)
or diag($template->error());
is($output, $expected_output, "\$template->process produced correct output");