| 1 | package Mason::t::Interp; | ||||||||||
| 2 | 1 | $Mason::t::Interp::VERSION = '2.24'; | |||||||||
| 3 | 1 | ▶ | use Test::Class::Most parent => 'Mason::Test::Class'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Capture::Tiny qw(capture); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | { package MyInterp; use Moose; extends 'Mason::Interp'; __PACKAGE__->meta->make_immutable() } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | $MyInterp::VERSION = '2.24'; | |||||||||
| 8 | 1 | ▶ | sub test_base_interp_class : Tests { | ||||||||
|
Subroutine
test_base_interp_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 9 | 1 | my $self = shift; | |||||||||
| 10 | 1 | my $interp = $self->create_interp( base_interp_class => 'MyInterp' ); | |||||||||
| 11 | 1 | is( ref($interp), 'MyInterp' ); | |||||||||
| 12 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | sub test_find_paths : Tests { | ||||||||
|
Subroutine
test_find_paths: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 15 | 1 | my $self = shift; | |||||||||
| 16 | 1 | my $r1 = $self->temp_dir . "/r1"; | |||||||||
| 17 | 1 | my $r2 = $self->temp_dir . "/r2"; | |||||||||
| 18 | 1 | my $interp = $self->create_interp( comp_root => [ $r1, $r2 ] ); | |||||||||
| 19 | 1 | my @files = | |||||||||
| 20 | ( "$r1/foo.mc", "$r1/foo/bar.mc", "$r2/foo/baz.mc", "$r1/foo/blarg.mc", "$r2/foo/blarg.mc" ); | ||||||||||
| 21 | 1 | foreach my $file (@files) { | |||||||||
| 22 | 5 | $self->mkpath_and_write_file( $file, " " ); | |||||||||
| 23 | } | ||||||||||
| 24 | cmp_set( | ||||||||||
| 25 | 1 | [ $interp->all_paths("/") ], | |||||||||
| 26 | [qw(/foo.mc /foo/bar.mc /foo/baz.mc /foo/blarg.mc)], | ||||||||||
| 27 | "all_paths(/)" | ||||||||||
| 28 | ); | ||||||||||
| 29 | 1 | 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 | 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 | cmp_set( [ $interp->all_paths("/bar") ], [], "all_paths(/bar)" ); | |||||||||
| 40 | |||||||||||
| 41 | 1 | 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 | cmp_set( [ $interp->glob_paths("/foo/bl*.mc") ], | |||||||||
| 47 | [qw(/foo/blarg.mc)], "glob_paths(/foo/bl*.mc)" ); | ||||||||||
| 48 | 1 | cmp_set( [ $interp->glob_paths("/foo/d*") ], [], "glob_paths(/foo/d*)" ); | |||||||||
| 49 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 50 | |||||||||||
| 51 | 1 | ▶ | sub test_component_class_prefix : Tests { | ||||||||
|
Subroutine
test_component_class_prefix: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 52 | 1 | my $self = shift; | |||||||||
| 53 | |||||||||||
| 54 | 3 | ▶ | my $check_prefix = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 55 | 3 | my $interp = shift; | |||||||||
| 56 | 3 | my $regex = "^" . $interp->component_class_prefix . "::"; | |||||||||
| 57 | 3 | like( $interp->load('/foo.mc'), qr/$regex/, "prefix at beginning of path" ); | |||||||||
| 58 | 1 | }; | |||||||||
| 59 | |||||||||||
| 60 | 1 | $self->add_comp( path => '/foo.mc', src => 'foo' ); | |||||||||
| 61 | |||||||||||
| 62 | my @interp = | ||||||||||
| 63 | 1 | map { $self->create_interp() } ( 0 .. 1 ); | |||||||||
| 64 | 1 | ok( $interp[0]->component_class_prefix ne $interp[1]->component_class_prefix, | |||||||||
| 65 | "different prefixes" ); | ||||||||||
| 66 | 1 | ok( $interp[0]->load('/foo.mc') ne $interp[1]->load('/foo.mc'), "different classnames" ); | |||||||||
| 67 | |||||||||||
| 68 | 1 | $check_prefix->( $interp[0] ); | |||||||||
| 69 | 1 | $check_prefix->( $interp[1] ); | |||||||||
| 70 | |||||||||||
| 71 | 1 | $interp[2] = $self->create_interp( component_class_prefix => 'Blah' ); | |||||||||
| 72 | 1 | is( $interp[2]->component_class_prefix, 'Blah', 'specified prefix' ); | |||||||||
| 73 | 1 | $check_prefix->( $interp[2] ); | |||||||||
| 74 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 75 | |||||||||||
| 76 | 1 | ▶ | sub test_no_data_dir : Tests { | ||||||||
|
Subroutine
test_no_data_dir: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 77 | 1 | my $self = shift; | |||||||||
| 78 | 1 | my $interp = Mason->new( comp_root => $self->comp_root ); | |||||||||
| 79 | 1 | ok( -d $interp->data_dir ); | |||||||||
| 80 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 81 | |||||||||||
| 82 | 1 | ▶ | sub test_bad_param : Tests { | ||||||||
|
Subroutine
test_bad_param: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 83 | 1 | my $self = shift; | |||||||||
| 84 | 1 | ▶ | throws_ok { $self->create_interp( foo => 5 ) } qr/Found unknown attribute/; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 85 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 86 | |||||||||||
| 87 | 1 | ▶ | sub test_comp_exists : Tests { | ||||||||
|
Subroutine
test_comp_exists: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 88 | 1 | my $self = shift; | |||||||||
| 89 | |||||||||||
| 90 | 1 | $self->add_comp( path => '/comp_exists/one.mc', src => 'hi' ); | |||||||||
| 91 | 1 | my $interp = $self->interp; | |||||||||
| 92 | 1 | ok( $interp->comp_exists('/comp_exists/one.mc') ); | |||||||||
| 93 | 1 | ok( !$interp->comp_exists('/comp_exists/two.mc') ); | |||||||||
| 94 | 1 | ▶ | throws_ok { $interp->comp_exists('one.mc') } qr/not an absolute/; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 95 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 96 | |||||||||||
| 97 | 1 | ▶ | sub test_out_method : Tests { | ||||||||
|
Subroutine
test_out_method: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 98 | 1 | my $self = shift; | |||||||||
| 99 | |||||||||||
| 100 | 1 | $self->add_comp( path => '/out_method/hi.mc', src => 'hi' ); | |||||||||
| 101 | |||||||||||
| 102 | 1 | my $buffer = ''; | |||||||||
| 103 | 5 | ▶ | my $try = sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 104 | 5 | my ( $out_method, $expect_result, $expect_buffer, $expect_stdout, $desc ) = @_; | |||||||||
| 105 | 5 | my ( $result, $stdout ); | |||||||||
| 106 | 5 | ▶ | my @params = ( $out_method ? ( { out_method => $out_method } ) : () ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 107 | 5 | ▶ | ($stdout) = capture { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 108 | 5 | $result = $self->interp->run( @params, '/out_method/hi' ); | |||||||||
| 109 | 5 | }; | |||||||||
| 110 | 5 | is( $stdout, $expect_stdout, "stdout - $desc" ); | |||||||||
| 111 | 5 | is( $buffer, $expect_buffer, "buffer - $desc" ); | |||||||||
| 112 | 5 | is( $result->output, $expect_result, "result->output - $desc" ); | |||||||||
| 113 | 1 | }; | |||||||||
| 114 | |||||||||||
| 115 | 1 | $try->( undef, 'hi', '', '', 'undef' ); | |||||||||
| 116 | 1 | ▶ | $try->( sub { print $_[0] }, '', '', 'hi', 'sub print' ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 117 | 1 | ▶ | $try->( sub { $buffer .= uc( $_[0] ) }, '', 'HI', '', 'sub buffer .=' ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 118 | 1 | $try->( \$buffer, '', 'HIhi', '', '\$buffer' ); | |||||||||
| 119 | |||||||||||
| 120 | 1 | $buffer = ''; | |||||||||
| 121 | 1 | ▶ | $self->setup_interp( out_method => sub { print scalar( reverse( $_[0] ) ) } ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 122 | 1 | $try->( undef, '', '', 'ih', 'print reverse' ); | |||||||||
| 123 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 124 | |||||||||||
| 125 | 1 | ▶ | sub test_no_source_line_numbers : Tests { | ||||||||
|
Subroutine
test_no_source_line_numbers: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 126 | 1 | my $self = shift; | |||||||||
| 127 | |||||||||||
| 128 | 1 | $self->test_parse( src => "hi\n<%init>my \$d = 0</%init>", expect => [qr/\#line/] ); | |||||||||
| 129 | 1 | $self->setup_interp( no_source_line_numbers => 1 ); | |||||||||
| 130 | 1 | $self->test_parse( src => "hi\n<%init>my \$d = 0</%init>", expect => [qr/^(?!(?s:.*)\#line)/] ); | |||||||||
| 131 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 132 | |||||||||||
| 133 | 1 | ▶ | sub test_class_header : Tests { | ||||||||
|
Subroutine
test_class_header: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 134 | 1 | my $self = shift; | |||||||||
| 135 | |||||||||||
| 136 | 1 | $self->setup_interp( class_header => '# header' ); | |||||||||
| 137 | 1 | $self->test_parse( src => "hi", expect => [qr/\# header/] ); | |||||||||
| 138 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 139 | |||||||||||
| 140 | 1 | 1; | |||||||||