3 # test apparatus for Text::Template module
16 die "This is the test program for Text::Template version 1.46.
17 You are using version $Text::Template::VERSION instead.
18 That does not make sense.\n
20 unless $Text::Template::VERSION == 1.46;
29 $FAILURE = q{Program fragment at line 1 delivered error ``kill trapped by operation mask''};
37 $goodtemplate = q{This should succeed: { $v }};
38 $goodoutput = q{This should succeed: 119};
40 $template1 = new Text::Template ('type' => 'STRING', 'source' => $goodtemplate)
42 $template2 = new Text::Template ('type' => 'STRING', 'source' => $goodtemplate)
45 $text1 = $template1->fill_in();
46 $text2 = $template1->fill_in(SAFE => $c);
48 $text3 = $template2->fill_in(SAFE => $c);
51 # (1)(2)(3) None of these should have failed.
52 print +(defined $text1 ? '' : 'not '), "ok $n\n";
54 print +(defined $text2 ? '' : 'not '), "ok $n\n";
56 print +(defined $text3 ? '' : 'not '), "ok $n\n";
59 # (4) Safe and non-safe fills of different template objects with the
60 # same template text should yield the same result.
61 # print +($text1 eq $text3 ? '' : 'not '), "ok $n\n";
62 # (4) voided this test: it's not true, because the unsafe fill
63 # uses package main, while the safe fill uses the secret safe package.
64 # We could alias the secret safe package to be identical to main,
65 # but that wouldn't be safe. If you want the aliasing, you have to
66 # request it explicitly with `PACKAGE'.
70 # (5) Safe and non-safe fills of the same template object
71 # should yield the same result.
72 # (5) voided this test for the same reason as #4.
73 # print +($text1 eq $text2 ? '' : 'not '), "ok $n\n";
77 # (6) Make sure the output was actually correct
78 print +($text1 eq $goodoutput ? '' : 'not '), "ok $n\n";
82 $badtemplate = qq{This should fail: { $BADOP; 'NOFAIL' }};
83 $badnosafeoutput = q{This should fail: NOFAIL};
84 $badsafeoutput = q{This should fail: Program fragment delivered error ``kill trapped by operation mask at template line 1.''};
86 $template1 = new Text::Template ('type' => 'STRING', 'source' => $badtemplate)
88 $template2 = new Text::Template ('type' => 'STRING', 'source' => $badtemplate)
91 $text1 = $template1->fill_in();
92 $text2 = $template1->fill_in(SAFE => $c);
94 $text3 = $template2->fill_in(SAFE => $c);
96 $text4 = $template1->fill_in();
98 # (7)(8)(9)(10) None of these should have failed.
99 print +(defined $text1 ? '' : 'not '), "ok $n\n";
101 print +(defined $text2 ? '' : 'not '), "ok $n\n";
103 print +(defined $text3 ? '' : 'not '), "ok $n\n";
105 print +(defined $text4 ? '' : 'not '), "ok $n\n";
108 # (11) text1 and text4 should be the same (using safe in between
109 # didn't change anything.)
110 print +($text1 eq $text4 ? '' : 'not '), "ok $n\n";
113 # (12) text2 and text3 should be the same (same template text in different
115 print +($text2 eq $text3 ? '' : 'not '), "ok $n\n";
118 # (13) text1 should yield badnosafeoutput
119 print +($text1 eq $badnosafeoutput ? '' : 'not '), "ok $n\n";
122 # (14) text2 should yield badsafeoutput
123 $text2 =~ s/'kill'/kill/; # 5.8.1 added quote marks around the op name
124 print "# expected: <$badsafeoutput>\n# got : <$text2>\n";
125 print +($text2 eq $badsafeoutput ? '' : 'not '), "ok $n\n";
129 $template = q{{$x=1}{$x+1}};
131 $template1 = new Text::Template ('type' => 'STRING', 'source' => $template)
133 $template2 = new Text::Template ('type' => 'STRING', 'source' => $template)
136 $text1 = $template1->fill_in();
137 $text2 = $template1->fill_in(SAFE => new Safe);
139 # (15) Do effects persist in safe compartments?
140 print +($text1 eq $text2 ? '' : 'not '), "ok $n\n";
143 # (16) Try the BROKEN routine in safe compartments
145 my %a = @_; $a{error} =~ s/ at.*//s;
146 "OK! text:$a{text} error:$a{error} lineno:$a{lineno} arg:$a{arg}" ;
148 $templateB = new Text::Template (TYPE => 'STRING', SOURCE => '{die}')
150 $text1 = $templateB->fill_in(BROKEN => \&my_broken,
151 BROKEN_ARG => 'barg',
154 $result1 = qq{OK! text:die error:Died lineno:1 arg:barg};
155 print +($text1 eq $result1 ? '' : 'not '), "ok $n\n";