error.t 808 B

12345678910111213141516171819202122232425262728293031323334
  1. #!perl
  2. #
  3. # test apparatus for Text::Template module
  4. # still incomplete.
  5. use strict;
  6. use warnings;
  7. use Test::More tests => 6;
  8. use_ok 'Text::Template' or exit 1;
  9. # (1-2) Missing source
  10. eval {
  11. Text::Template->new();
  12. pass;
  13. };
  14. like $@, qr/^\QUsage: Text::Template::new(TYPE => ..., SOURCE => ...)/;
  15. eval { Text::Template->new(TYPE => 'FILE'); };
  16. like $@, qr/^\QUsage: Text::Template::new(TYPE => ..., SOURCE => ...)/;
  17. # (3) Invalid type
  18. eval { Text::Template->new(TYPE => 'wlunch', SOURCE => 'fish food'); };
  19. like $@, qr/^\QIllegal value `WLUNCH' for TYPE parameter/;
  20. # (4-5) File does not exist
  21. my $o = Text::Template->new(
  22. TYPE => 'file',
  23. SOURCE => 'this file does not exist');
  24. ok !defined $o;
  25. ok defined($Text::Template::ERROR)
  26. && $Text::Template::ERROR =~ /^Couldn't open file/;