File: process-relative.t

package info (click to toggle)
libtemplate-perl 3.102-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,680 kB
  • sloc: perl: 14,945; makefile: 11; sh: 5
file content (77 lines) | stat: -rw-r--r-- 2,103 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#============================================================= -*-perl-*-
#
# t/process-relative.t
#
# Test template process with . in INCLUDE_PATH
#
# Written by Nicolas R. <atoomic@cpan.org>
#
# Copyright (C) 2018 cPanel Inc.  All Rights Reserved.
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# $Id$
#
#========================================================================

use strict;
use lib qw( ./lib ../lib );
use Template;

#use Template::Test;

use Test::More tests => 8;

#$Template::Test::DEBUG = 0;
#$Template::Context::DEBUG = 1;

my $template_file = q[t/test/dir/file1];

plan( skip_all => "File $template_file missing" ) unless -e $template_file;

foreach my $f ( $template_file, "./$template_file" ) {
    note "processing $f with INCLUDE_PATH='.' ; RELATIVE => 1";
    my $out;
    Template->new( { INCLUDE_PATH => ".", RELATIVE => 1 } )->process( $f, undef, \$out );
    is $out => q[This is file 1], "process file $f";
}

foreach my $f ( $template_file, "./$template_file" ) {
    note "processing $f with RELATIVE => 1";
    my $out;
    Template->new( { RELATIVE => 1 } )->process( $f, undef, \$out );
    is $out => q[This is file 1], "process file $f";
}

{
    my $f = $template_file;
    note "processing $f with INCLUDE_PATH='.'";
    my $out;
    Template->new( { INCLUDE_PATH => "." } )->process( $f, undef, \$out );
    is $out => q[This is file 1], "process file $f";
}

{
    my $f = "./$template_file";
    note "processing $f with INCLUDE_PATH='.'";
    my $out;
    Template->new( { INCLUDE_PATH => "." } )->process( $f, undef, \$out );
    is $out => undef, "process file $f fails without setting RELATIVE";
}

{
    my $out;
    my $f = $template_file;
    note "processing $f without INCLUDE_PATH set";
    Template->new()->process( $f, undef, \$out );
    is $out => q[This is file 1], "process file $f";
}

{
    my $out;
    my $f = "./$template_file";
    note "processing $f without INCLUDE_PATH set";
    Template->new()->process( $f, undef, \$out );
    is $out => undef, "process file $f";
}