14-broken.t 2.3 KB

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