blib/lib/Mason/t/Errors.pm

filter: Statementstmt 100% 3 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 100% 4 / 4 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
CRAP 1.0
« blib/lib/Mason/t/DollarDot.pm ↑ Summary blib/lib/Mason/t/Filters.pm »
1 package Mason::t::Errors;
2 $Mason::t::Errors::VERSION = '2.23';
3 1 ▶use Test::Class::Most parent => 'Mason::Test::Class';
Subroutine BEGIN: called CC=1 SCAR=0.0
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->( "<%%>", qr/found empty '<% %>' tag/ );
36 $try->( "<% %>", qr/found empty '<% %>' tag/ );
37 $try->( "<% %>", qr/found empty '<% %>' tag/ );
38 $try->( "% \$.Upper {{\nHi", qr/'\{\{' without matching '}}'/ );
39 $try->( "Hi\n% }}", qr/'}}' without matching '\{\{'/ );
40 $try->( '<%method 1a>Hi</%method>', qr/Invalid method name '1a'/ );
41 $try->( '<%method cmeta>Hi</%method>', qr/'cmeta' is reserved.*method name/ );
42 $try->(
43 "<%method a>Hi</%method>\n<%method a>Bye</%method>",
44 qr/Duplicate definition of method 'a'/
45 );
46 $try->( "<%before 1a>Hi</%before>", qr/Invalid method modifier name '1a'/ );
47 $try->(
48 "<%before a>Hi</%before>\n<%before a>Bye</%before>",
49 qr/Duplicate definition of method modifier 'before a'/
50 );
51 $try->(
52 '<%method b><%after main>Hi</%after></%method>',
53 qr/Cannot nest <%after> block inside <%method> block/
54 );
55 $try->( "% 'foobar' {{\nHi\n% }}\n", qr/'foobar' is neither a code ref/ );
56 $try->( "<%flags>\nfoo => 1\n</%flags>", qr/Invalid flag 'foo'/ );
57 $try->( "<%flags>\nextends => 'blah'\n</%flags>",
58 qr/could not load '\/blah' for extends flag/ );
59 $try->( "<%flags>\nextends => %foo\n</%flags>", qr/Global symbol/ );
60 $try->( '<% $foo %>', qr/Global symbol "\$foo" requires explicit package name/ );
61 $try->( 'die "blargh";', qr/blargh/, path => '/blargh.mp' );
62  
63 # Error line numbers
64 #
65 $try->( "%\nb\n% die;", qr/Died at .* line 3/ );
66 $try->( "<%method foo>\n1\n2\n3\n</%method>\n% die;", qr/Died at .* line 6/ );
67 }
68  
69 sub test_bad_allow_globals : Tests {
70 my $self = shift;
71 throws_ok { $self->create_interp( allow_globals => ['@p'] ) } qr/only scalar globals supported/;
72 throws_ok { $self->create_interp( allow_globals => ['i-'] ) } qr/not a valid/;
73 }
74  
75 sub test_non_comp_errors : Tests {
76 my $self = shift;
77 throws_ok { $self->interp->_make_request()->current_comp_class }
78 qr/cannot determine current_comp_class/;
79 throws_ok { Mason->new() } qr/Attribute \(comp_root\) is required/;
80 }
81  
82 1;
« blib/lib/Mason/t/DollarDot.pm ↑ Summary blib/lib/Mason/t/Filters.pm »