Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 96 lines (85 sloc) 2.433 kB
7dc261c @abw *** empty log message ***
authored
1 #============================================================= -*-perl-*-
2 #
3 # t/compile4.t
4 #
5 # Test the facility for the Template::Provider to maintain a persistance
6 # cache of compiled templates by writing generated Perl code to files.
7 # This is similar to compile1.t but defines COMPILE_DIR as well as
8 # COMPILE_EXT.
9 #
10 # Written by Andy Wardley <abw@kfs.org>
11 #
12 # Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved.
13 # Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
14 #
15 # This is free software; you can redistribute it and/or modify it
16 # under the same terms as Perl itself.
17 #
18 # $Id$
19 #
20 #========================================================================
21
22 use strict;
23 use lib qw( ./lib ../lib );
24 use Template::Test;
25 use Cwd qw( abs_path );
26 use File::Path;
27 $^W = 1;
28
29 # declare extra tests to follow test_expect();
30 #$Template::Test::EXTRA = 2;
31
32 # script may be being run in distribution root or 't' directory
d884f67 @abw Updated t/compile* tests to handle the stupidity that is windows\path…
authored
33 my @dir = -d 't' ? qw(t test) : qw(test);
34 my $dir = abs_path( File::Spec->catfile(@dir) );
35 my $tdir = abs_path( File::Spec->catfile(@dir, 'tmp'));
36 my $cdir = File::Spec->catfile($tdir, 'cache');
37 my $zero = File::Spec->catfile($dir, qw(src divisionbyzero));
7dc261c @abw *** empty log message ***
authored
38 my $ttcfg = {
39 POST_CHOMP => 1,
40 INCLUDE_PATH => "$dir/src",
41 COMPILE_DIR => $cdir,
42 COMPILE_EXT => '.ttc',
a4123f8 @abw 2.04b
authored
43 ABSOLUTE => 1,
2cb5f1c @abw Applied a patch from Norbert Buchmüller to prevent the #line markers
authored
44 CONSTANTS => {
d884f67 @abw Updated t/compile* tests to handle the stupidity that is windows\path…
authored
45 dir => $dir,
46 zero => $zero,
2cb5f1c @abw Applied a patch from Norbert Buchmüller to prevent the #line markers
authored
47 },
7dc261c @abw *** empty log message ***
authored
48 };
49
50 # delete any existing cache files
51 rmtree($cdir) if -d $cdir;
52 mkpath($cdir);
53
a4123f8 @abw 2.04b
authored
54 test_expect(\*DATA, $ttcfg, { root => abs_path($dir) } );
7dc261c @abw *** empty log message ***
authored
55
56
57 __DATA__
58 -- test --
59 [% TRY %]
60 [% INCLUDE foo %]
61 [% CATCH file %]
62 Error: [% error.type %] - [% error.info %]
63 [% END %]
64 -- expect --
65 This is the foo file, a is
66
67 -- test --
68 [% META author => 'abw' version => 3.14 %]
69 [% INCLUDE complex %]
70 -- expect --
71 This is the header, title: Yet Another Template Test
72 This is a more complex file which includes some BLOCK definitions
73 This is the footer, author: abw, version: 3.14
5068caf @abw *** empty log message ***
authored
74 - 3 - 2 - 1
0b63aae @abw *** empty log message ***
authored
75
76 -- test --
77 [% TRY %]
78 [% INCLUDE bar/baz word = 'wibble' %]
79 [% CATCH file %]
80 Error: [% error.type %] - [% error.info %]
81 [% END %]
82 -- expect --
83 This is file baz
84 The word is 'wibble'
85
a4123f8 @abw 2.04b
authored
86 -- test --
87 [% INCLUDE "$root/src/blam" %]
88 -- expect --
89 This is the blam file
2cb5f1c @abw Applied a patch from Norbert Buchmüller to prevent the #line markers
authored
90 -- test --
91 [%- # first pass, writes the compiled code to cache -%]
92 [% INCLUDE divisionbyzero -%]
93 -- expect --
94 -- process --
d884f67 @abw Updated t/compile* tests to handle the stupidity that is windows\path…
authored
95 undef error - Illegal division by zero at [% constants.zero %] line 1.
Something went wrong with that request. Please try again.