Trying to create a string with the values ​​of the template and unit test so that the template processes correctly

I am trying to create a test file that injects the values ​​of a template into a string using the template toolkit, but I do not know what checks / checks to include to make sure that the template toolbox handles the string correctly. Here is my code:

#!/usr/bin/env perl

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($config);

# input string
my $text = "This is string number [%num%] ."; 

# template placeholder variables
my $vars = {
     num => "one",
 };


# processes imput string and inserts placeholder values 
my $create_temp = $template->process(\$text, $vars)
    || die "Template process failed: ", $template->error(), "\n";


#is(($template->process(\$text, $vars)), '1' , 'The template is processing correctly');

# If process method is executed successfully it should have a return value of 1
diag($template->process(\$text, $vars));

diag 1, , , , stdout, , . stdout , . stderr . , . , , Template Toolkit ?

- , , .

+4
2

, $template->process , unit test, , , , .

Test::Output, STDOUT.

use Test::Output;

stdout_is { $template->process( \$text, $vars ) } q{This is string number one .},
    q{Template generates the correct output};

Capture::Tiny .

use Capture::Tiny 'capture_stdout';

my $output = capture_stdout {
    ok $template->process( \$text, $vars ), q{Template processes successfully};
};
is $output, q{This is string number one .}, q{... and the output is correct};

, , ( TAP, Test:: Harness STDOUT).

+4

, process() STDOUT, . , anythere.

process() , . , , , .

$template->process(\$text, $vars, \$output);
is($output, $expected_output);

, TT Template::Test, , , .

+4

All Articles