Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 102 lines (88 sloc) 1.98 kb
9a56a1a @abw added t/throw.t
authored
1 #============================================================= -*-perl-*-
2 #
3 # t/throw.t
4 #
5 # Test the THROW directive.
6 #
7 # Written by Andy Wardley <abw@kfs.org>
8 #
9 # Copyright (C) 2000 Andy Wardley. All Rights Reserved.
10 #
11 # This is free software; you can redistribute it and/or modify it
12 # under the same terms as Perl itself.
13 #
14 # $Id$
15 #
16 #========================================================================
17
18 use strict;
19 use lib qw( ./lib ../lib );
20 use Template;
21 use Template::Test;
22 $^W = 1;
23
24 $Template::Test::DEBUG = 0;
25 #$Template::Parser::DEBUG = 1;
26 #$Template::Directive::PRETTY = 1;
27
28 test_expect(\*DATA);
29
30
31 __DATA__
32 -- test --
33 [% me = 'I' -%]
34 [% TRY -%]
35 [%- THROW chicken "Failed failed failed" 'boo' name='Fred' -%]
36 [% CATCH -%]
37 ERROR: [% error.type %] - [% error.info.0 %]/[% error.info.1 %]/[% error.info.name %]
38 [% END %]
39 -- expect --
40 ERROR: chicken - Failed failed failed/boo/Fred
41
42 -- test --
43 [% TRY -%]
44 [% THROW food 'eggs' -%]
45 [% CATCH -%]
46 ERROR: [% error.type %] / [% error.info %]
47 [% END %]
48
49 -- expect --
50 ERROR: food / eggs
51
52 # test throwing multiple params
53 -- test --
54 [% pi = 3.14
55 e = 2.718 -%]
56 [% TRY -%]
57 [% THROW foo pi e msg="fell over" reason="brain exploded" -%]
58 [% CATCH -%]
59 [% error.type %]: pi=[% error.info.0 %] e=[% error.info.1 %]
60 I [% error.info.msg %] because my [% error.info.reason %]!
61 [% END %]
62 -- expect --
63 foo: pi=3.14 e=2.718
64 I fell over because my brain exploded!
65
66 -- test --
67 [% TRY -%]
68 [% THROW foo 'one' 2 three=3.14 -%]
69 [% CATCH -%]
70 [% error.type %]
71 [% error.info.0 %]
72 [% error.info.1 %]
73 [% error.info.three %]
74 [%- FOREACH e = error.info.args %]
75 * [% e %]
76 [%- END %]
77 [% END %]
78 -- expect --
79 foo
80 one
81 2
82 3.14
83 * one
84 * 2
85
86 -- test --
87 [% TRY -%]
88 [% THROW food 'eggs' 'flour' msg="Missing Ingredients" -%]
89 [% CATCH food -%]
90 [% error.info.msg %]
91 [% FOREACH item = error.info.args -%]
92 * [% item %]
93 [% END -%]
94 [% END %]
95 -- expect --
96 Missing Ingredients
97 * eggs
98 * flour
99
100
101
Something went wrong with that request. Please try again.