line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mason::Test::Class; |
2
|
|
|
|
|
|
|
$Mason::Test::Class::VERSION = '2.24'; |
3
|
20
|
|
|
20
|
|
996722
|
use Carp; |
|
20
|
|
|
|
|
36
|
|
|
20
|
|
|
|
|
1155
|
|
4
|
20
|
|
|
20
|
|
91
|
use File::Basename; |
|
20
|
|
|
|
|
25
|
|
|
20
|
|
|
|
|
1292
|
|
5
|
20
|
|
|
20
|
|
86
|
use File::Path; |
|
20
|
|
|
|
|
25
|
|
|
20
|
|
|
|
|
928
|
|
6
|
20
|
|
|
20
|
|
14548
|
use File::Temp qw(tempdir); |
|
20
|
|
|
|
|
332896
|
|
|
20
|
|
|
|
|
1328
|
|
7
|
20
|
|
|
20
|
|
6562
|
use Mason; |
|
20
|
|
|
|
|
59
|
|
|
20
|
|
|
|
|
787
|
|
8
|
20
|
|
|
20
|
|
104
|
use Mason::Util qw(trim write_file); |
|
20
|
|
|
|
|
29
|
|
|
20
|
|
|
|
|
931
|
|
9
|
20
|
|
|
20
|
|
91
|
use Method::Signatures::Simple; |
|
20
|
|
|
|
|
35
|
|
|
20
|
|
|
|
|
97
|
|
10
|
20
|
|
|
20
|
|
7437
|
use Test::Class::Most; |
|
20
|
|
|
|
|
12496
|
|
|
20
|
|
|
|
|
287
|
|
11
|
20
|
|
|
20
|
|
72595
|
use Test::LongString; |
|
20
|
|
|
|
|
36232
|
|
|
20
|
|
|
|
|
109
|
|
12
|
20
|
|
|
20
|
|
1448
|
use Class::Load; |
|
20
|
|
|
|
|
33
|
|
|
20
|
|
|
|
|
665
|
|
13
|
20
|
|
|
20
|
|
75
|
use strict; |
|
20
|
|
|
|
|
42
|
|
|
20
|
|
|
|
|
522
|
|
14
|
20
|
|
|
20
|
|
69
|
use warnings; |
|
20
|
|
|
|
|
30
|
|
|
20
|
|
|
|
|
4860
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->SKIP_CLASS("abstract base class"); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# RO accessors |
19
|
420
|
|
|
420
|
0
|
1973
|
sub comp_root { $_[0]->{comp_root} } |
20
|
200
|
|
|
200
|
0
|
43405
|
sub data_dir { $_[0]->{data_dir} } |
21
|
215
|
|
|
215
|
0
|
2113
|
sub interp { $_[0]->{interp} } |
22
|
8
|
|
|
8
|
0
|
54
|
sub temp_dir { $_[0]->{temp_dir} } |
23
|
0
|
|
|
0
|
0
|
0
|
sub temp_root { $_[0]->{temp_root} } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# RW class accessors |
26
|
|
|
|
|
|
|
my $default_plugins = []; |
27
|
1
|
50
|
|
1
|
0
|
8
|
sub default_plugins { $default_plugins = $_[1] if defined( $_[1] ); $default_plugins; } |
|
1
|
|
|
|
|
2
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $gen_path_count = 0; |
30
|
|
|
|
|
|
|
my $parse_count = 0; |
31
|
|
|
|
|
|
|
my $temp_dir_count = 0; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our $current_test_object; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _startup : Test(startup) { |
36
|
20
|
|
|
20
|
|
12797
|
my $self = shift; |
37
|
20
|
|
|
|
|
60
|
my $verbose = $ENV{TEST_VERBOSE}; |
38
|
20
|
50
|
|
|
|
162
|
$self->{temp_root} = tempdir( 'mason-test-XXXX', TMPDIR => 1, CLEANUP => $verbose ? 0 : 1 ); |
39
|
20
|
50
|
|
|
|
11514
|
printf STDERR ( "\n*** temp_root = %s, no cleanup\n", $self->{temp_root} ) if $verbose; |
40
|
20
|
|
|
|
|
183
|
$self->setup_dirs; |
41
|
20
|
|
|
20
|
|
104
|
} |
|
20
|
|
|
|
|
35
|
|
|
20
|
|
|
|
|
169
|
|
42
|
|
|
|
|
|
|
|
43
|
20
|
|
|
20
|
|
11232
|
method setup_dirs () { |
|
79
|
|
|
79
|
|
201
|
|
|
79
|
|
|
|
|
184
|
|
44
|
79
|
|
|
|
|
560
|
$self->{temp_dir} = join( "/", $self->{temp_root}, $temp_dir_count++ ); |
45
|
79
|
|
|
|
|
330
|
$self->{comp_root} = $self->{temp_dir} . "/comps"; |
46
|
79
|
|
|
|
|
300
|
$self->{data_dir} = $self->{temp_dir} . "/data"; |
47
|
79
|
|
|
|
|
37950
|
mkpath( [ $self->{comp_root}, $self->{data_dir} ], 0, 0775 ); |
48
|
79
|
|
|
|
|
759
|
$self->setup_interp(@_); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
20
|
|
|
20
|
|
7448
|
method setup_interp () { |
|
91
|
|
|
91
|
|
207
|
|
|
91
|
|
|
|
|
167
|
|
52
|
91
|
|
|
|
|
550
|
$self->{interp} = $self->create_interp(@_); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
20
|
|
|
20
|
|
6274
|
method create_interp () { |
|
100
|
|
|
100
|
|
224
|
|
|
100
|
|
|
|
|
216
|
|
56
|
100
|
|
|
|
|
358
|
my (%params) = @_; |
57
|
100
|
100
|
|
|
|
509
|
$params{plugins} = $default_plugins if @$default_plugins; |
58
|
100
|
|
100
|
|
|
771
|
my $mason_root_class = delete( $params{mason_root_class} ) || 'Mason'; |
59
|
100
|
|
|
|
|
636
|
Class::Load::load_class($mason_root_class); |
60
|
100
|
|
|
|
|
4620
|
rmtree( $self->data_dir ); |
61
|
100
|
|
|
|
|
796
|
return $mason_root_class->new( |
62
|
|
|
|
|
|
|
comp_root => $self->comp_root, |
63
|
|
|
|
|
|
|
data_dir => $self->data_dir, |
64
|
|
|
|
|
|
|
%params, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
20
|
|
|
20
|
|
7591
|
method add_comp (%params) { |
|
303
|
|
|
303
|
|
673
|
|
|
303
|
|
|
|
|
1070
|
|
|
303
|
|
|
|
|
393
|
|
69
|
303
|
|
|
|
|
1246
|
$self->_validate_keys( \%params, qw(path src v verbose) ); |
70
|
303
|
|
50
|
|
|
930
|
my $path = $params{path} || die "must pass path"; |
71
|
303
|
|
50
|
|
|
819
|
my $source = $params{src} || " "; |
72
|
303
|
|
33
|
|
|
1353
|
my $verbose = $params{v} || $params{verbose}; |
73
|
303
|
50
|
|
|
|
1063
|
die "'$path' is not absolute" unless substr( $path, 0, 1 ) eq '/'; |
74
|
303
|
|
|
|
|
1073
|
my $source_file = $self->comp_root . $path; |
75
|
303
|
|
|
|
|
1212
|
$self->mkpath_and_write_file( $source_file, $source ); |
76
|
303
|
50
|
|
|
|
1902
|
if ($verbose) { |
77
|
0
|
|
|
|
|
0
|
print STDERR "*** $path ***\n"; |
78
|
0
|
|
|
|
|
0
|
my $output = $self->interp->_compile( $source_file, $path ); |
79
|
0
|
|
|
|
|
0
|
print STDERR "$output\n"; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
20
|
|
|
20
|
|
8559
|
method remove_comp (%params) { |
|
6
|
|
|
6
|
|
13
|
|
|
6
|
|
|
|
|
22
|
|
|
6
|
|
|
|
|
9
|
|
84
|
6
|
|
50
|
|
|
28
|
my $path = $params{path} || die "must pass path"; |
85
|
6
|
|
|
|
|
26
|
my $source_file = join( "/", $self->comp_root, $path ); |
86
|
6
|
|
|
|
|
36734
|
unlink($source_file); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
20
|
|
|
20
|
|
6472
|
method _gen_comp_path () { |
|
83
|
|
|
83
|
|
128
|
|
|
83
|
|
|
|
|
116
|
|
90
|
83
|
|
|
|
|
298
|
my $caller = ( caller(2) )[3]; |
91
|
83
|
|
|
|
|
2023
|
my ($caller_base) = ( $caller =~ /([^:]+)$/ ); |
92
|
83
|
|
|
|
|
283
|
my $path = "/$caller_base" . ( ++$gen_path_count ) . ".mc"; |
93
|
83
|
|
|
|
|
305
|
return $path; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
20
|
|
|
20
|
|
7302
|
method test_comp (%params) { |
|
101
|
|
|
101
|
|
199
|
|
|
101
|
|
|
|
|
354
|
|
|
101
|
|
|
|
|
135
|
|
97
|
101
|
|
66
|
|
|
720
|
my $path = $params{path} || $self->_gen_comp_path; |
98
|
101
|
|
50
|
|
|
424
|
my $source = $params{src} || " "; |
99
|
101
|
|
33
|
|
|
459
|
my $verbose = $params{v} || $params{verbose}; |
100
|
|
|
|
|
|
|
|
101
|
101
|
|
|
|
|
449
|
$self->add_comp( path => $path, src => $source, verbose => $verbose ); |
102
|
101
|
|
|
|
|
234
|
delete( $params{src} ); |
103
|
|
|
|
|
|
|
|
104
|
101
|
|
|
|
|
721
|
$self->test_existing_comp( %params, path => $path ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
20
|
|
|
20
|
|
7376
|
method test_existing_comp (%params) { |
|
107
|
|
|
107
|
|
227
|
|
|
107
|
|
|
|
|
328
|
|
|
107
|
|
|
|
|
122
|
|
108
|
107
|
|
|
|
|
564
|
$self->_validate_keys( \%params, qw(args desc expect expect_data expect_error path v verbose) ); |
109
|
107
|
50
|
|
|
|
394
|
my $path = $params{path} or die "must pass path"; |
110
|
107
|
|
|
|
|
402
|
my $caller = ( caller(1) )[3]; |
111
|
107
|
|
66
|
|
|
2340
|
my $desc = $params{desc} || $path; |
112
|
107
|
|
|
|
|
447
|
my $expect = trim( $params{expect} ); |
113
|
107
|
|
|
|
|
196
|
my $expect_error = $params{expect_error}; |
114
|
107
|
|
|
|
|
153
|
my $expect_data = $params{expect_data}; |
115
|
107
|
|
33
|
|
|
509
|
my $verbose = $params{v} || $params{verbose}; |
116
|
107
|
|
100
|
|
|
587
|
my $args = $params{args} || {}; |
117
|
107
|
|
|
|
|
563
|
( my $request_path = $path ) =~ s/\.m[cpi]$//; |
118
|
|
|
|
|
|
|
|
119
|
107
|
|
|
|
|
323
|
my @run_params = ( $request_path, %$args ); |
120
|
107
|
|
|
|
|
182
|
local $current_test_object = $self; |
121
|
|
|
|
|
|
|
|
122
|
107
|
100
|
|
|
|
300
|
if ( defined($expect_error) ) { |
123
|
36
|
|
33
|
|
|
75
|
$desc ||= $expect_error; |
124
|
36
|
|
|
36
|
|
281
|
throws_ok( sub { $self->interp->run(@run_params) }, $expect_error, $desc ); |
|
36
|
|
|
|
|
1066
|
|
125
|
|
|
|
|
|
|
} |
126
|
107
|
100
|
|
|
|
20539
|
if ( defined($expect) ) { |
127
|
70
|
|
33
|
|
|
182
|
$desc ||= $caller; |
128
|
70
|
|
|
|
|
375
|
my $output = trim( $self->interp->run(@run_params)->output ); |
129
|
70
|
100
|
|
|
|
2543
|
if ( ref($expect) eq 'Regexp' ) { |
130
|
2
|
|
|
|
|
13
|
like( $output, $expect, $desc ); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
else { |
133
|
68
|
|
|
|
|
376
|
is( $output, $expect, $desc ); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
107
|
100
|
|
|
|
42112
|
if ( defined($expect_data) ) { |
137
|
1
|
|
33
|
|
|
2
|
$desc ||= $caller; |
138
|
1
|
|
|
|
|
6
|
cmp_deeply( $self->interp->run(@run_params)->data, $expect_data, $desc ); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
20
|
|
|
20
|
|
11427
|
method run_test_in_comp (%params) { |
|
4
|
|
|
4
|
|
9
|
|
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
6
|
|
143
|
4
|
|
50
|
|
|
19
|
my $test = delete( $params{test} ) || die "must pass test"; |
144
|
4
|
|
100
|
|
|
20
|
my $args = delete( $params{args} ) || {}; |
145
|
4
|
|
66
|
|
|
26
|
$params{path} ||= $self->_gen_comp_path; |
146
|
4
|
|
|
|
|
21
|
$self->add_comp( %params, src => '% $.args->{_test}->($self);' ); |
147
|
4
|
|
|
|
|
31
|
( my $request_path = $params{path} ) =~ s/\.m[cpi]$//; |
148
|
4
|
|
|
|
|
17
|
my @run_params = ( $request_path, %$args ); |
149
|
4
|
|
|
|
|
31
|
$self->interp->run( @run_params, _test => $test ); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
20
|
|
|
20
|
|
8105
|
method test_parse (%params) { |
|
4
|
|
|
4
|
|
6
|
|
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
5
|
|
153
|
4
|
|
|
|
|
13
|
my $caller = ( caller(1) )[3]; |
154
|
4
|
|
|
|
|
87
|
my ($caller_base) = ( $caller =~ /([^:]+)$/ ); |
155
|
4
|
|
|
|
|
9
|
my $desc = $params{desc}; |
156
|
4
|
|
33
|
|
|
14
|
my $source = $params{src} || croak "must pass src"; |
157
|
4
|
|
|
|
|
6
|
my $expect_list = $params{expect}; |
158
|
4
|
|
|
|
|
6
|
my $expect_error = $params{expect_error}; |
159
|
4
|
50
|
33
|
|
|
20
|
croak "must pass either expect or expect_error" unless $expect_list || $expect_error; |
160
|
|
|
|
|
|
|
|
161
|
4
|
|
|
|
|
12
|
my $path = "/parse/comp" . $parse_count++; |
162
|
4
|
|
|
|
|
19
|
my $file = $self->temp_dir . $path; |
163
|
4
|
|
|
|
|
17
|
$self->mkpath_and_write_file( $file, $source ); |
164
|
|
|
|
|
|
|
|
165
|
4
|
50
|
|
|
|
13
|
if ($expect_error) { |
166
|
0
|
|
0
|
|
|
0
|
$desc ||= $expect_error; |
167
|
0
|
|
|
0
|
|
0
|
throws_ok( sub { $self->interp->_compile( $file, $path ) }, $expect_error, $desc ); |
|
0
|
|
|
|
|
0
|
|
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
else { |
170
|
4
|
|
33
|
|
|
19
|
$desc ||= $caller; |
171
|
4
|
|
|
|
|
33
|
my $output = $self->interp->_compile( $file, $path ); |
172
|
4
|
|
|
|
|
15
|
foreach my $expect (@$expect_list) { |
173
|
6
|
100
|
|
|
|
763
|
if ( ref($expect) eq 'Regexp' ) { |
174
|
3
|
|
|
|
|
16
|
like_string( $output, $expect, "$desc - $expect" ); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
else { |
177
|
3
|
|
|
|
|
15
|
contains_string( $output, $expect, "$desc - $expect" ); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
20
|
|
|
20
|
|
10774
|
method mkpath_and_write_file ($source_file, $source) { |
|
312
|
|
|
312
|
|
452
|
|
|
312
|
|
|
|
|
460
|
|
|
312
|
|
|
|
|
362
|
|
184
|
312
|
100
|
|
|
|
14085
|
unlink($source_file) if -e $source_file; |
185
|
312
|
|
|
|
|
39588
|
mkpath( dirname($source_file), 0, 0775 ); |
186
|
312
|
|
|
|
|
1358
|
write_file( $source_file, $source ); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
20
|
|
|
20
|
|
7021
|
method _validate_keys ($params, @allowed_keys) { |
|
410
|
|
|
410
|
|
557
|
|
|
410
|
|
|
|
|
975
|
|
|
410
|
|
|
|
|
412
|
|
190
|
410
|
|
|
|
|
951
|
my %is_allowed = map { ( $_, 1 ) } @allowed_keys; |
|
2068
|
|
|
|
|
3335
|
|
191
|
410
|
50
|
|
|
|
1130
|
if ( my @bad_keys = grep { !$is_allowed{$_} } keys(%$params) ) { |
|
955
|
|
|
|
|
2958
|
|
192
|
0
|
|
|
|
|
|
croak "bad parameters: " . join( ", ", @bad_keys ); |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
1; |