1#!perl 2# test apparatus for Text::Template module 3 4use Text::Template; 5 6print "1..5\n"; 7 8$n=1; 9 10die "This is the test program for Text::Template version 1.46. 11You are using version $Text::Template::VERSION instead. 12That does not make sense.\n 13Aborting" 14 unless $Text::Template::VERSION == 1.46; 15 16# (1) basic error delivery 17{ my $r = Text::Template->new(TYPE => 'string', 18 SOURCE => '{1/0}', 19 )->fill_in(); 20 if ($r eq q{Program fragment delivered error ``Illegal division by zero at template line 1.''}) { 21 print "ok $n\n"; 22 } else { 23 print "not ok $n\n# $r\n"; 24 } 25 $n++; 26} 27 28# (2) BROKEN sub called in ->new? 29{ my $r = Text::Template->new(TYPE => 'string', 30 SOURCE => '{1/0}', 31 BROKEN => sub {'---'}, 32 )->fill_in(); 33 if ($r eq q{---}) { 34 print "ok $n\n"; 35 } else { 36 print "not ok $n\n# $r\n"; 37 } 38 $n++; 39} 40 41# (3) BROKEN sub called in ->fill_in? 42{ my $r = Text::Template->new(TYPE => 'string', 43 SOURCE => '{1/0}', 44 )->fill_in(BROKEN => sub {'---'}); 45 if ($r eq q{---}) { 46 print "ok $n\n"; 47 } else { 48 print "not ok $n\n# $r\n"; 49 } 50 $n++; 51} 52 53# (4) BROKEN sub passed correct args when called in ->new? 54{ my $r = Text::Template->new(TYPE => 'string', 55 SOURCE => '{1/0}', 56 BROKEN => sub { my %a = @_; 57 qq{$a{lineno},$a{error},$a{text}} 58 }, 59 )->fill_in(); 60 if ($r eq qq{1,Illegal division by zero at template line 1.\n,1/0}) { 61 print "ok $n\n"; 62 } else { 63 print "not ok $n\n# $r\n"; 64 } 65 $n++; 66} 67 68# (5) BROKEN sub passed correct args when called in ->fill_in? 69{ my $r = Text::Template->new(TYPE => 'string', 70 SOURCE => '{1/0}', 71 )->fill_in(BROKEN => 72 sub { my %a = @_; 73 qq{$a{lineno},$a{error},$a{text}} 74 }); 75 if ($r eq qq{1,Illegal division by zero at template line 1.\n,1/0}) { 76 print "ok $n\n"; 77 } else { 78 print "not ok $n\n# $r\n"; 79 } 80 $n++; 81} 82 83