09-error.t 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!perl
  2. #
  3. # test apparatus for Text::Template module
  4. # still incomplete.
  5. use Text::Template;
  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. print "1..5\n";
  12. $n = 1;
  13. # (1-2) Missing source
  14. eval {
  15. Text::Template->new();
  16. };
  17. unless ($@ =~ /^\QUsage: Text::Template::new(TYPE => ..., SOURCE => ...)/) {
  18. print STDERR $@;
  19. print "not ";
  20. }
  21. print "ok $n\n";
  22. $n++;
  23. eval {
  24. Text::Template->new(TYPE => 'FILE');
  25. };
  26. if ($@ =~ /^\QUsage: Text::Template::new(TYPE => ..., SOURCE => ...)/) {
  27. print "ok $n\n";
  28. } else {
  29. print STDERR $@;
  30. print "not ok $n\n";
  31. }
  32. $n++;
  33. # (3) Invalid type
  34. eval {
  35. Text::Template->new(TYPE => 'wlunch', SOURCE => 'fish food');
  36. };
  37. if ($@ =~ /^\QIllegal value `WLUNCH' for TYPE parameter/) {
  38. print "ok $n\n";
  39. } else {
  40. print STDERR $@;
  41. print "not ok $n\n";
  42. }
  43. $n++;
  44. # (4-5) File does not exist
  45. my $o = Text::Template->new(TYPE => 'file',
  46. SOURCE => 'this file does not exist');
  47. print $o ? "not ok $n\n" : "ok $n\n";
  48. $n++;
  49. print defined($Text::Template::ERROR)
  50. && $Text::Template::ERROR =~ /^Couldn't open file/
  51. ? "ok $n\n" : "not ok $n\n";
  52. $n++;
  53. exit;