Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么这个输出在perl单元测试中重复?_Perl_Unit Testing_Output - Fatal编程技术网

为什么这个输出在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");