Template/Test.pm

filter: Statementstmt 95.9% 47 / 49 Branchbran 60.0% 6 / 10 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 92.2% 71 / 77 CC 9 SCAR 13.1
CC
9
Cov
90%
ejs_test
7.1
ejs_test_parse
3.1
BEGIN
1.0
CRAP 3.7
« Template/Parser/Context.pm ↑ Summary Template.pm »
1 6 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 EJS::Template::Test - Testing utility for EJS::Template
8  
9 =cut
10  
11 package EJS::Template::Test;
12 6 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use EJS::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 6 our @EXPORT = qw(ejs_test ejs_test_parse);
20  
21 =head1 Methods
22  
23 =head2 ejs_test
24  
25 =cut
26  
27 50 ▶sub ejs_test {
Subroutine ejs_test: called CC=7 SCAR=19.6
Pod documented
28 50 my ($source, $expected, $variables, $config) = @_;
29 50 local $Test::Builder::Level = $Test::Builder::Level + 1;
30
31 50 ▶ my $ejs = EJS::Template->new(%{$config || {}});
Condition100%2/2
$config || {}
l!l
3218
MC/DC100%1/1
$config || {}
$config
Truth table100%2/2
A
A= $config
Aresult
11
00
32 50 my $prefix = '';
33
34 50 for my $name (qw(engine escape)) {
35 100 ▶ if ($ejs->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ejs->{$name}) 32 68 100
36 32 $prefix .= $ejs->{$name}.': ';
37 }
38 }
39
40 50 ▶ $prefix ||= 'source: ';
Condition100%2/2
$prefix ||= "source: "
l!l
3218
MC/DC100%1/1
$prefix ||= "source: "
$prefix
Truth table100%2/2
A
A= $prefix
Aresult
11
00
41
42 50 my $output;
43
44 50 eval {
45 50 ▶ $ejs->process(\$source, $variables, \$output) or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
$ejs->process(\$source, $variables, \$output) or croak($@) 50 0 50
46 };
47
48 50 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 50 50
49 0 fail $prefix."[$source]: $@";
50 } else {
51 50 is($output, $expected, $prefix."[$source]");
52 }
53 }
54  
55 =head2 ejs_test_parse
56  
57 =cut
58  
59 20 ▶sub ejs_test_parse {
Subroutine ejs_test_parse: called CC=3 SCAR=11.3
Pod documented
60 20 my ($source, $expected) = @_;
61 20 local $Test::Builder::Level = $Test::Builder::Level + 1;
62
63 20 my $prefix = 'source: ';
64 20 my $output;
65
66 20 eval {
67 20 ▶ EJS::Template->parse(\$source, \$output) or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
"EJS::Template"->parse(\$source, \$output) or croak($@) 20 0 20
68 };
69
70 20 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 20 20
71 0 fail $prefix."[$source]: $@";
72 } else {
73 20 is($output, $expected, $prefix."[$source]");
74 }
75 }
76  
77 =head1 SEE ALSO
78  
79 =over 4
80  
81 =item * L<EJS::Template>
82  
83 =back
84  
85 =cut
86  
87 6 1;
« Template/Parser/Context.pm ↑ Summary Template.pm »