2016-04-15 3 views
0

私が比較している出力文字列が重複しているため、テストが失敗しましたが、理由はわかりません。ここでperl unit testでこの出力が重複しているのはなぜですか?

は私のテストファイルです:

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 

私はバグを見つけるか、なぜこれが起こっている把握することができないよう。

答えて

2

$template->process(\$text, $vars, \$output)への呼び出しが2回あります。

私はあなたが

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"); 
をしたいと思います
関連する問題