line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Lazy::Template; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use base qw/Class::Accessor::Fast/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
124
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/tester template/); |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use Test::Lazy::Tester; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
11
|
1
|
|
|
1
|
|
26
|
use Test::Builder(); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
12
|
1
|
|
|
1
|
|
5
|
use Scalar::Util qw/blessed/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
70
|
|
13
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
827
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Test::Lazy::Template |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Build a template for running a similar set of tests repeatedly. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
The purpose of this module is to provide a convenient way of |
24
|
|
|
|
|
|
|
testing a set of initial conditions in different ways. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
The best way to show this is in an example: |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Template up the intial condition template. |
29
|
|
|
|
|
|
|
my $template = new Test::Lazy::Template([ |
30
|
|
|
|
|
|
|
[ "qw/1/" ], |
31
|
|
|
|
|
|
|
[ "qw/a/" ], |
32
|
|
|
|
|
|
|
[ "qw/apple/" ], |
33
|
|
|
|
|
|
|
[ "qw/2/" ], |
34
|
|
|
|
|
|
|
[ "qw/0/" ], |
35
|
|
|
|
|
|
|
[ "qw/-1/" ], |
36
|
|
|
|
|
|
|
[ "map { \$_ => \$_ * 2 } qw/0 1 2 3 4/" ], |
37
|
|
|
|
|
|
|
]); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Run some different tests. |
40
|
|
|
|
|
|
|
# NOTE: Don't have to use '%?' if the statement will run without modification. |
41
|
|
|
|
|
|
|
$template->test("defined(%?)" => ok => undef); |
42
|
|
|
|
|
|
|
$template->test("length(%?) >= 1" => ok => undef); |
43
|
|
|
|
|
|
|
$template->test("length(%?)" => '>=' => 1); |
44
|
|
|
|
|
|
|
$template->test("length(%?)" => '<' => 10); |
45
|
|
|
|
|
|
|
$template->test([ |
46
|
|
|
|
|
|
|
[ '%?' => is => 1 ], |
47
|
|
|
|
|
|
|
[ is => 'a' ], |
48
|
|
|
|
|
|
|
[ is => 'apple' ], |
49
|
|
|
|
|
|
|
[ is => 2 ], |
50
|
|
|
|
|
|
|
[ is => 0 ], |
51
|
|
|
|
|
|
|
[ is => is => -1 ], |
52
|
|
|
|
|
|
|
[ is => { 0 => 0, 1 => 2, 2 => 4, 3 => 6, 4 => 8 } ], |
53
|
|
|
|
|
|
|
]); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 METHODS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 Test::Lazy::Template->new( ) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 Test::Lazy::Template->new( , , ..., ) |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Create a new C object using the giving test specification. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
If is a SCALAR reference, then new will split on each newline, |
64
|
|
|
|
|
|
|
ignoring empty lines and lines beginning with a pound (#). |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# You could do something like this: |
67
|
|
|
|
|
|
|
my $template = template(\<<_END_); |
68
|
|
|
|
|
|
|
qw/1/ |
69
|
|
|
|
|
|
|
qw/a/ |
70
|
|
|
|
|
|
|
qw/apple/ |
71
|
|
|
|
|
|
|
qw/2/ |
72
|
|
|
|
|
|
|
qw/0/ |
73
|
|
|
|
|
|
|
qw/-1/ |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Let's test this one too. |
76
|
|
|
|
|
|
|
map { \$_ => \$_ * 2 } qw/0 1 2 3 4/ |
77
|
|
|
|
|
|
|
_END_ |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Returns the new C object |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub new { |
85
|
2
|
|
|
2
|
1
|
21734
|
my $self = bless {}, shift; |
86
|
2
|
100
|
66
|
|
|
28
|
my $tester = blessed $_[0] && $_[0]->isa("Test::Lazy::Tester") ? shift : Test::Lazy::Tester->new; |
87
|
2
|
|
|
|
|
15
|
my $template = $_[0]; |
88
|
2
|
100
|
|
|
|
11
|
if (ref $template eq 'SCALAR') { |
|
|
50
|
|
|
|
|
|
89
|
1
|
100
|
|
|
|
7
|
my @template = map { [ $_ ] } grep { length $_ && $_ !~ m/^\s*#/ } split m/\n/, $$template; |
|
7
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
44
|
|
90
|
1
|
|
|
|
|
3
|
$template = \@template; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
elsif (ref $template eq 'ARRAY') { |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else { |
95
|
0
|
|
|
|
|
0
|
$template = [ @_ ]; |
96
|
|
|
|
|
|
|
} |
97
|
2
|
|
|
|
|
10
|
$self->tester($tester); |
98
|
2
|
|
|
|
|
23
|
$self->template($template); |
99
|
2
|
|
|
|
|
14
|
return $self; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 $template->test( ) |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
For each test in $template, modify and run each the test according to the corresponding entry in . |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 $template->test( ) |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Modify and then run each test in $template by using to complete each test's specification. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub test { |
113
|
10
|
|
|
10
|
1
|
5641
|
my $self = shift; |
114
|
|
|
|
|
|
|
|
115
|
10
|
|
|
|
|
30
|
my $template = $self->template; |
116
|
10
|
|
|
|
|
45
|
my $size = @$template; |
117
|
10
|
|
|
|
|
12
|
my $mdf_template; |
118
|
|
|
|
|
|
|
my $base_stmt; |
119
|
10
|
100
|
|
|
|
74
|
if (ref $_[0] eq 'ARRAY') { |
|
|
50
|
|
|
|
|
|
120
|
2
|
|
|
|
|
5
|
$mdf_template = shift; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
elsif (ref $_[1] eq 'ARRAY') { |
123
|
0
|
|
|
|
|
0
|
$base_stmt = shift; |
124
|
0
|
|
|
|
|
0
|
$mdf_template = shift; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
else { |
127
|
8
|
|
|
|
|
11
|
my ($mdf_stmt, $mdf_cmpr, $mdf_rslt); |
128
|
8
|
50
|
|
|
|
15
|
if (2 == @_) { |
129
|
0
|
|
|
|
|
0
|
($mdf_stmt, $mdf_cmpr, $mdf_rslt) = (undef, @_); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
else { |
132
|
8
|
|
|
|
|
17
|
($mdf_stmt, $mdf_cmpr, $mdf_rslt) = @_; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
8
|
|
|
|
|
26
|
$mdf_template = [ map { [ $mdf_stmt, $mdf_cmpr, $mdf_rslt ] } (0 .. $size - 1) ]; |
|
56
|
|
|
|
|
567
|
|
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
10
|
|
|
|
|
35
|
for (my $index = 0; $index < $size; ++$index) { |
139
|
70
|
|
|
|
|
29280
|
my $line = $template->[$index]; |
140
|
70
|
|
|
|
|
95
|
my $mdf_line = $mdf_template->[$index]; |
141
|
|
|
|
|
|
|
|
142
|
70
|
|
|
|
|
71
|
my ($mdf_stmt, $mdf_cmpr, $mdf_rslt); |
143
|
70
|
100
|
|
|
|
153
|
if (2 == @$mdf_line) { |
144
|
14
|
|
|
|
|
33
|
($mdf_stmt, $mdf_cmpr, $mdf_rslt) = ($base_stmt, @$mdf_line); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
else { |
147
|
56
|
|
|
|
|
129
|
($mdf_stmt, $mdf_cmpr, $mdf_rslt) = @$mdf_line; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
70
|
100
|
|
|
|
119
|
if (defined $mdf_stmt) { |
151
|
56
|
|
|
|
|
277
|
$mdf_stmt =~ s/%\?/$line->[0]/; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
else { |
154
|
14
|
|
|
|
|
24
|
$mdf_stmt = $line->[0]; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
70
|
|
|
|
|
102
|
my $stmt = $mdf_stmt; |
158
|
70
|
|
|
|
|
116
|
my ($cmpr) = grep { defined } ($mdf_cmpr, $line->[1]); |
|
140
|
|
|
|
|
292
|
|
159
|
70
|
|
|
|
|
100
|
my ($rslt) = grep { defined } ($mdf_rslt, $line->[2]); |
|
140
|
|
|
|
|
218
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
{ |
162
|
70
|
|
|
|
|
65
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
|
70
|
|
|
|
|
93
|
|
163
|
|
|
|
|
|
|
|
164
|
70
|
|
|
|
|
193
|
$self->tester->try($stmt, $cmpr, $rslt, "$index: %"); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |