warnings.t 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!perl
  2. use strict;
  3. use warnings;
  4. use Text::Template;
  5. # Minimum Test::More version; 0.94+ is required for `done_testing`
  6. BEGIN {
  7. unless (eval { require Test::More; "$Test::More::VERSION" >= 0.94; }) {
  8. Test::More::plan(skip_all => '[ Test::More v0.94+ ] is required for testing');
  9. }
  10. Test::More->import;
  11. # Non-CORE module(s)
  12. unless (eval { require Test::Warnings; 1; }) {
  13. plan(skip_all => '[ Test::Warnings ] is required for testing');
  14. }
  15. Test::Warnings->import;
  16. }
  17. my $template = <<'EOT';
  18. {{
  19. if ($good =~ /good/) {
  20. 'This template should not produce warnings.'.$bad;
  21. }
  22. }}
  23. EOT
  24. $template = Text::Template->new(type => 'STRING', source => $template);
  25. isa_ok $template, 'Text::Template';
  26. my $result = $template->fill_in(HASH => { good => 'good' });
  27. $result =~ s/(?:^\s+)|(?:\s+$)//gs;
  28. is $result, 'This template should not produce warnings.';
  29. # see https://github.com/mschout/perl-text-template/issues/10
  30. $template = Text::Template->new(type => 'STRING', package => 'MY', source => '');
  31. $template->fill_in(package => 'MY', hash => { include => sub { 'XX' } });
  32. $template = Text::Template->new(type => 'STRING', package => 'MY', source => '');
  33. $template->fill_in(package => 'MY', hash => { include => sub { 'XX' } });
  34. done_testing;