File Coverage

blib/lib/Mason/t/Errors.pm
Criterion Covered Total %
statement 60 60 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod 0 3 0.0
total 72 75 96.0


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