line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mason::t::Interp; |
2
|
|
|
|
|
|
|
$Mason::t::Interp::VERSION = '2.23'; |
3
|
1
|
|
|
1
|
|
773
|
use Test::Class::Most parent => 'Mason::Test::Class'; |
|
1
|
|
|
|
|
26660
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
655
|
use Capture::Tiny qw(capture); |
|
1
|
|
|
|
|
3325
|
|
|
1
|
|
|
|
|
69
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7
|
{ package MyInterp; use Moose; extends 'Mason::Interp'; __PACKAGE__->meta->make_immutable() } |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
7
|
|
|
|
|
|
|
$MyInterp::VERSION = '2.23'; |
8
|
|
|
|
|
|
|
sub test_base_interp_class : Tests { |
9
|
1
|
|
|
1
|
0
|
2617
|
my $self = shift; |
10
|
1
|
|
|
|
|
9
|
my $interp = $self->create_interp( base_interp_class => 'MyInterp' ); |
11
|
1
|
|
|
|
|
7
|
is( ref($interp), 'MyInterp' ); |
12
|
1
|
|
|
1
|
|
5313
|
} |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub test_find_paths : Tests { |
15
|
1
|
|
|
1
|
0
|
249
|
my $self = shift; |
16
|
1
|
|
|
|
|
10
|
my $r1 = $self->temp_dir . "/r1"; |
17
|
1
|
|
|
|
|
2
|
my $r2 = $self->temp_dir . "/r2"; |
18
|
1
|
|
|
|
|
7
|
my $interp = $self->create_interp( comp_root => [ $r1, $r2 ] ); |
19
|
1
|
|
|
|
|
7
|
my @files = |
20
|
|
|
|
|
|
|
( "$r1/foo.mc", "$r1/foo/bar.mc", "$r2/foo/baz.mc", "$r1/foo/blarg.mc", "$r2/foo/blarg.mc" ); |
21
|
1
|
|
|
|
|
3
|
foreach my $file (@files) { |
22
|
5
|
|
|
|
|
21
|
$self->mkpath_and_write_file( $file, " " ); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
cmp_set( |
25
|
1
|
|
|
|
|
8
|
[ $interp->all_paths("/") ], |
26
|
|
|
|
|
|
|
[qw(/foo.mc /foo/bar.mc /foo/baz.mc /foo/blarg.mc)], |
27
|
|
|
|
|
|
|
"all_paths(/)" |
28
|
|
|
|
|
|
|
); |
29
|
1
|
|
|
|
|
5533
|
cmp_set( |
30
|
|
|
|
|
|
|
[ $interp->all_paths() ], |
31
|
|
|
|
|
|
|
[qw(/foo.mc /foo/bar.mc /foo/baz.mc /foo/blarg.mc)], |
32
|
|
|
|
|
|
|
"all_paths(/)" |
33
|
|
|
|
|
|
|
); |
34
|
1
|
|
|
|
|
1662
|
cmp_set( |
35
|
|
|
|
|
|
|
[ $interp->all_paths("/foo") ], |
36
|
|
|
|
|
|
|
[qw(/foo/bar.mc /foo/baz.mc /foo/blarg.mc)], |
37
|
|
|
|
|
|
|
"all_paths(/foo)" |
38
|
|
|
|
|
|
|
); |
39
|
1
|
|
|
|
|
1108
|
cmp_set( [ $interp->all_paths("/bar") ], [], "all_paths(/bar)" ); |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
515
|
cmp_set( |
42
|
|
|
|
|
|
|
[ $interp->glob_paths("/foo/ba*.mc") ], |
43
|
|
|
|
|
|
|
[qw(/foo/bar.mc /foo/baz.mc)], |
44
|
|
|
|
|
|
|
"glob_paths(/foo/ba*.mc)" |
45
|
|
|
|
|
|
|
); |
46
|
1
|
|
|
|
|
890
|
cmp_set( [ $interp->glob_paths("/foo/bl*.mc") ], |
47
|
|
|
|
|
|
|
[qw(/foo/blarg.mc)], "glob_paths(/foo/bl*.mc)" ); |
48
|
1
|
|
|
|
|
578
|
cmp_set( [ $interp->glob_paths("/foo/d*") ], [], "glob_paths(/foo/d*)" ); |
49
|
1
|
|
|
1
|
|
547
|
} |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
3
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub test_component_class_prefix : Tests { |
52
|
1
|
|
|
1
|
0
|
1217
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $check_prefix = sub { |
55
|
3
|
|
|
3
|
|
6
|
my $interp = shift; |
56
|
3
|
|
|
|
|
101
|
my $regex = "^" . $interp->component_class_prefix . "::"; |
57
|
3
|
|
|
|
|
58
|
like( $interp->load('/foo.mc'), qr/$regex/, "prefix at beginning of path" ); |
58
|
1
|
|
|
|
|
6
|
}; |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
7
|
$self->add_comp( path => '/foo.mc', src => 'foo' ); |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
9
|
my @interp = |
63
|
1
|
|
|
|
|
3
|
map { $self->create_interp() } ( 0 .. 1 ); |
64
|
1
|
|
|
|
|
31
|
ok( $interp[0]->component_class_prefix ne $interp[1]->component_class_prefix, |
65
|
|
|
|
|
|
|
"different prefixes" ); |
66
|
1
|
|
|
|
|
761
|
ok( $interp[0]->load('/foo.mc') ne $interp[1]->load('/foo.mc'), "different classnames" ); |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
649
|
$check_prefix->( $interp[0] ); |
69
|
1
|
|
|
|
|
350
|
$check_prefix->( $interp[1] ); |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
347
|
$interp[2] = $self->create_interp( component_class_prefix => 'Blah' ); |
72
|
1
|
|
|
|
|
28
|
is( $interp[2]->component_class_prefix, 'Blah', 'specified prefix' ); |
73
|
1
|
|
|
|
|
409
|
$check_prefix->( $interp[2] ); |
74
|
1
|
|
|
1
|
|
351
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub test_no_data_dir : Tests { |
77
|
1
|
|
|
1
|
0
|
248
|
my $self = shift; |
78
|
1
|
|
|
|
|
9
|
my $interp = Mason->new( comp_root => $self->comp_root ); |
79
|
1
|
|
|
|
|
26
|
ok( -d $interp->data_dir ); |
80
|
1
|
|
|
1
|
|
226
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub test_bad_param : Tests { |
83
|
1
|
|
|
1
|
0
|
1340
|
my $self = shift; |
84
|
1
|
|
|
1
|
|
10
|
throws_ok { $self->create_interp( foo => 5 ) } qr/Found unknown attribute/; |
|
1
|
|
|
|
|
100
|
|
85
|
1
|
|
|
1
|
|
246
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub test_comp_exists : Tests { |
88
|
1
|
|
|
1
|
0
|
1016
|
my $self = shift; |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
10
|
$self->add_comp( path => '/comp_exists/one.mc', src => 'hi' ); |
91
|
1
|
|
|
|
|
7
|
my $interp = $self->interp; |
92
|
1
|
|
|
|
|
29
|
ok( $interp->comp_exists('/comp_exists/one.mc') ); |
93
|
1
|
|
|
|
|
530
|
ok( !$interp->comp_exists('/comp_exists/two.mc') ); |
94
|
1
|
|
|
1
|
|
390
|
throws_ok { $interp->comp_exists('one.mc') } qr/not an absolute/; |
|
1
|
|
|
|
|
79
|
|
95
|
1
|
|
|
1
|
|
281
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub test_out_method : Tests { |
98
|
1
|
|
|
1
|
0
|
716
|
my $self = shift; |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
8
|
$self->add_comp( path => '/out_method/hi.mc', src => 'hi' ); |
101
|
|
|
|
|
|
|
|
102
|
1
|
|
|
|
|
3
|
my $buffer = ''; |
103
|
|
|
|
|
|
|
my $try = sub { |
104
|
5
|
|
|
5
|
|
14
|
my ( $out_method, $expect_result, $expect_buffer, $expect_stdout, $desc ) = @_; |
105
|
5
|
|
|
|
|
5
|
my ( $result, $stdout ); |
106
|
5
|
100
|
|
|
|
25
|
my @params = ( $out_method ? ( { out_method => $out_method } ) : () ); |
107
|
|
|
|
|
|
|
($stdout) = capture { |
108
|
5
|
|
|
|
|
4259
|
$result = $self->interp->run( @params, '/out_method/hi' ); |
109
|
5
|
|
|
|
|
118
|
}; |
110
|
5
|
|
|
|
|
3154
|
is( $stdout, $expect_stdout, "stdout - $desc" ); |
111
|
5
|
|
|
|
|
2652
|
is( $buffer, $expect_buffer, "buffer - $desc" ); |
112
|
5
|
|
|
|
|
1944
|
is( $result->output, $expect_result, "result->output - $desc" ); |
113
|
1
|
|
|
|
|
8
|
}; |
114
|
|
|
|
|
|
|
|
115
|
1
|
|
|
|
|
3
|
$try->( undef, 'hi', '', '', 'undef' ); |
116
|
1
|
|
|
1
|
|
8
|
$try->( sub { print $_[0] }, '', '', 'hi', 'sub print' ); |
|
1
|
|
|
|
|
61
|
|
117
|
1
|
|
|
1
|
|
10
|
$try->( sub { $buffer .= uc( $_[0] ) }, '', 'HI', '', 'sub buffer .=' ); |
|
1
|
|
|
|
|
4
|
|
118
|
1
|
|
|
|
|
6
|
$try->( \$buffer, '', 'HIhi', '', '\$buffer' ); |
119
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
2
|
$buffer = ''; |
121
|
1
|
|
|
1
|
|
14
|
$self->setup_interp( out_method => sub { print scalar( reverse( $_[0] ) ) } ); |
|
1
|
|
|
|
|
69
|
|
122
|
1
|
|
|
|
|
27
|
$try->( undef, '', '', 'ih', 'print reverse' ); |
123
|
1
|
|
|
1
|
|
414
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub test_no_source_line_numbers : Tests { |
126
|
1
|
|
|
1
|
0
|
176
|
my $self = shift; |
127
|
|
|
|
|
|
|
|
128
|
1
|
|
|
|
|
11
|
$self->test_parse( src => "hi\n<%init>my \$d = 0</%init>", expect => [qr/\#line/] ); |
129
|
1
|
|
|
|
|
478
|
$self->setup_interp( no_source_line_numbers => 1 ); |
130
|
1
|
|
|
|
|
25
|
$self->test_parse( src => "hi\n<%init>my \$d = 0</%init>", expect => [qr/^(?!(?s:.*)\#line)/] ); |
131
|
1
|
|
|
1
|
|
257
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub test_class_header : Tests { |
134
|
1
|
|
|
1
|
0
|
181
|
my $self = shift; |
135
|
|
|
|
|
|
|
|
136
|
1
|
|
|
|
|
8
|
$self->setup_interp( class_header => '# header' ); |
137
|
1
|
|
|
|
|
26
|
$self->test_parse( src => "hi", expect => [qr/\# header/] ); |
138
|
1
|
|
|
1
|
|
233
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |