1#============================================================= -*-perl-*-
2#
3# t/stop.t
4#
5# Test the [% STOP %] directive.
6#
7# Written by Andy Wardley <abw@kfs.org>
8#
9# Copyright (C) 1996-2000 Andy Wardley.  All Rights Reserved.
10# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
11#
12# This is free software; you can redistribute it and/or modify it
13# under the same terms as Perl itself.
14#
15# $Id$
16#
17#========================================================================
18
19use strict;
20use lib qw( ./lib ../lib ../blib/lib ../blib/arch ./blib/lib ./blib/arch );
21use vars qw( $DEBUG );
22use Template::Test;
23use Template::Parser;
24use Template::Exception;
25
26#$Template::Parser::DEBUG = 1;
27$DEBUG = 1;
28
29my $ttblocks = {
30    header => sub { "This is the header\n" },
31    footer => sub { "This is the footer\n" },
32    halt1  => sub { die Template::Exception->new('stop', 'big error') },
33};
34my $ttvars = {
35    halt   => sub { die Template::Exception->new('stop', 'big error') },
36};
37    
38my $ttbare = Template->new(BLOCKS => $ttblocks);
39my $ttwrap = Template->new({
40    PRE_PROCESS  => 'header',
41    POST_PROCESS => 'footer',
42    BLOCKS       => $ttblocks,
43});
44    
45
46test_expect(\*DATA, [ bare => $ttbare, wrapped => $ttwrap ], $ttvars);
47
48__END__
49
50-- test --
51This is some text
52[% STOP %]
53More text
54-- expect --
55This is some text
56
57-- test --
58This is some text
59[% halt %]
60More text
61-- expect --
62This is some text
63
64-- test --
65This is some text
66[% INCLUDE halt1 %]
67More text
68-- expect --
69This is some text
70
71-- test --
72This is some text
73[% INCLUDE myblock1 %]
74More text
75[% BLOCK myblock1 -%]
76This is myblock1
77[% STOP %]
78more of myblock1
79[% END %]
80-- expect --
81This is some text
82This is myblock1
83
84-- test --
85This is some text
86[% INCLUDE myblock2 %]
87More text
88[% BLOCK myblock2 -%]
89This is myblock2
90[% halt %]
91more of myblock2
92[% END %]
93-- expect --
94This is some text
95This is myblock2
96
97
98#------------------------------------------------------------------------
99# ensure 'stop' exceptions get ignored by TRY...END blocks
100#------------------------------------------------------------------------
101-- test --
102before
103[% TRY -%]
104trying
105[% STOP -%]
106tried
107[% CATCH -%]
108caught [[% error.type %]] - [% error.info %]
109[% END %]
110after
111
112-- expect --
113before
114trying
115
116
117#------------------------------------------------------------------------
118# ensure PRE_PROCESS and POST_PROCESS templates get added with STOP
119#------------------------------------------------------------------------
120
121-- test --
122-- use wrapped --
123This is some text
124[% STOP %]
125More text
126-- expect --
127This is the header
128This is some text
129This is the footer
130
131