1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t'
# $Id: 09_wrong.t 511 2006-08-07 01:41:42Z tinita $
use lib 'blib/lib';
use Test::More tests => 9;
BEGIN { use_ok('HTML::Template::Compiled') };
eval {
my $htc = HTML::Template::Compiled->new(
scalarref => \<<'EOM',
<tmpl_if foo>bar</tmpl_if>
<%if foo %>bar<%/if%>
<%if foo %>bar
EOM
debug => $ENV{HARNESS_ACTIVE} ? 0 : 1,
line_numbers => 1,
);
};
print "err: $@\n" unless $ENV{HARNESS_ACTIVE};
ok($@ =~ m/Missing closing tag for 'IF'/, "premature end of template");
# test wrong balanced tag
my $wrong;
eval {
$wrong = HTML::Template::Compiled->new(
path => 't/templates',
line_numbers => 1,
filename => 'wrong.html',
debug => $ENV{HARNESS_ACTIVE} ? 0 : 1,
);
};
print "err: $@\n" unless $ENV{HARNESS_ACTIVE};
ok($@ =~ m/does not match opening tag/ , "wrong template");
eval {
my $htc = HTML::Template::Compiled->new(
path => 't/templates',
filename => 'notexist.htc',
debug => $ENV{HARNESS_ACTIVE} ? 0 : 1,
);
};
print "err: $@\n" unless $ENV{HARNESS_ACTIVE};
ok($@ =~ m/not found/ , "template not found");
eval {
my $str = <<'EOM';
<tmpl_include name="notexist.htc">
EOM
my $htc = HTML::Template::Compiled->new(
path => 't/templates',
scalarref => \$str,
debug => $ENV{HARNESS_ACTIVE} ? 0 : 1,
);
};
print "err: $@\n" unless $ENV{HARNESS_ACTIVE};
ok($@ =~ m/not found/ , "template from include not found");
{
my @wrong = (
"<TMPL_VA foo>",
"<TMPL_VAR foo oops>",
"<TMPL_IF blah escape=html>",
"foo<TMPL_IF >",
);
for my $wrong (@wrong) {
eval {
my $htc = HTML::Template::Compiled->new(
scalarref => \$wrong,
debug => 0,
);
};
print STDERR "Error? $@\n" unless $ENV{HARNESS_ACTIVE};;
cmp_ok($@, "=~", qr{\Q: Syntax error in <TMPL_*> tag at }, "die when syntax is wrong");
}
}
|