File Coverage

blib/lib/Mason/t/Errors.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package Mason::t::Errors;
2             $Mason::t::Errors::VERSION = '2.22';
3 1     1   1311 use Test::Class::Most parent => 'Mason::Test::Class';
  1         41638  
  1         7  
4              
5             sub test_comp_errors : Tests {
6             my $self = shift;
7             my $try = sub {
8             my ( $src, $expect_error, %extra ) = @_;
9             $self->test_comp(
10             src => $src,
11             expect_error => $expect_error,
12             desc => $expect_error,
13             %extra
14             );
15             };
16             my $root = $self->interp->comp_root->[0];
17              
18             $try->(
19             '<& /does/not/exist &>',
20             qr/could not find component for path '\/does\/not\/exist' - component root is \Q[$root]\E/,
21             );
22             $try->( '<%method>', qr/<%method> block requires a name/ );
23             $try->( '<%before>', qr/<%before> block requires a name/ );
24             $try->( '<%init>', qr/<%init> without matching <\/%init>/ );
25             $try->( '<%attr>', qr/unknown block '<%attr>'/ );
26             $try->( '<%blah>', qr/unknown block '<%blah>'/ );
27             $try->( '<%init foo>', qr/<%init> block does not take a name/ );
28             $try->( '<%', qr/'<%' without matching '%>'/ );
29             $try->( 'foo %>', qr/'%>' without matching '<%'/ );
30             $try->( '<& foo', qr/'<&' without matching '&>'/ );
31             $try->( 'foo &>', qr/'&>' without matching '<&'/ );
32             $try->( '%my $i = 1;', qr/% must be followed by whitespace/ );
33             $try->( "<%5\n\n%>", qr/whitespace required after '<%' at .* line 1/ );
34             $try->( "<%\n\n5%>", qr/whitespace required before '%>' at .* line 3/ );
35             $try->( "% \$.Upper {{\nHi", qr/'{{' without matching '}}'/ );
36             $try->( "Hi\n% }}", qr/'}}' without matching '{{'/ );
37             $try->( '<%method 1a>Hi</%method>', qr/Invalid method name '1a'/ );
38             $try->( '<%method cmeta>Hi</%method>', qr/'cmeta' is reserved.*method name/ );
39             $try->(
40             "<%method a>Hi</%method>\n<%method a>Bye</%method>",
41             qr/Duplicate definition of method 'a'/
42             );
43             $try->( "<%before 1a>Hi</%before>", qr/Invalid method modifier name '1a'/ );
44             $try->(
45             "<%before a>Hi</%before>\n<%before a>Bye</%before>",
46             qr/Duplicate definition of method modifier 'before a'/
47             );
48             $try->(
49             '<%method b><%after main>Hi</%after></%method>',
50             qr/Cannot nest <%after> block inside <%method> block/
51             );
52             $try->( "% 'foobar' {{\nHi\n% }}\n", qr/'foobar' is neither a code ref/ );
53             $try->( "<%flags>\nfoo => 1\n</%flags>", qr/Invalid flag 'foo'/ );
54             $try->( "<%flags>\nextends => 'blah'\n</%flags>",
55             qr/could not load '\/blah' for extends flag/ );
56             $try->( "<%flags>\nextends => %foo\n</%flags>", qr/Global symbol/ );
57             $try->( '<% $foo %>', qr/Global symbol "\$foo" requires explicit package name/ );
58             $try->( 'die "blargh";', qr/blargh/, path => '/blargh.mp' );
59              
60             # Error line numbers
61             #
62             $try->( "%\nb\n% die;", qr/Died at .* line 3/ );
63             $try->( "<%method foo>\n1\n2\n3\n</%method>\n% die;", qr/Died at .* line 6/ );
64             }
65              
66             sub test_bad_allow_globals : Tests {
67             my $self = shift;
68             throws_ok { $self->create_interp( allow_globals => ['@p'] ) } qr/only scalar globals supported/;
69             throws_ok { $self->create_interp( allow_globals => ['i-'] ) } qr/not a valid/;
70             }
71              
72             sub test_non_comp_errors : Tests {
73             my $self = shift;
74             throws_ok { $self->interp->_make_request()->current_comp_class }
75             qr/cannot determine current_comp_class/;
76             throws_ok { Mason->new() } qr/Attribute \(comp_root\) is required/;
77             }
78              
79             1;