vendredi 15 avril 2016

Trying to create a string with template values and unit test that the template is processing correctly

I am trying to create a test file that inputs template values into a string using the template toolkit but I don't know what check/tests to include to make sure the template toolkit is processing 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));

The diag function returns a value of 1, which from the documentation means that the string has been processed sucessfully, but I have been trying check what the stdout is so I can see the output string but I can get it to print. I have tried writing the stdout to a file from the terminal command but nothing appears in the file. I can write the stderr to a file though. I have also been trying different configuration for the template as seen in the code below. Is it not working because I am not running any tests, or am I using the Template Toolkit in the wrong way?

If there is any other required information to needed to answer this question just comment below.

Aucun commentaire:

Enregistrer un commentaire