@@ -18,6 +18,7 @@ my ($attrs, $ret) = ("", "");
1818sub Q ::MODIFY_CODE_ATTRIBUTES { my ($name , $ref , @attrs ) = @_ ; $attrs = " @attrs " ;return ;}
1919$SIG {__WARN__ } = sub { push @warnings , shift ;};
2020
21+ @warnings = ();
2122$ret = eval ' package Q; sub A(bar) : prototype(bad) : dummy1 {} prototype \&A;' ;
2223is $ret , " bad" , " Prototype is set to \" bad\" " ;
2324is $attrs , " dummy1" , " MODIFY_CODE_ATTRIBUTES called, but not for prototype(..)" ;
@@ -27,20 +28,24 @@ like shift @warnings, qr/Illegal character in prototype for Q::A : bad/,
2728 " Second warning is bad prototype - bad" ;
2829like shift @warnings , qr / Prototype \' bar\' overridden by attribute \' prototype\( bad\)\' in Q::A/ ,
2930 " Third warning is Prototype overridden" ;
30- is @warnings , 0, " No more warnings" ;
31+ is @warnings , 0, " No more warnings"
32+ or diag " Next warning: $warnings [0]" ;
3133
3234# The override warning should not be hidden by no warnings (similar to prototype changed warnings)
3335{
3436 no warnings ' illegalproto' ;
37+ @warnings = ();
3538 $ret = eval ' package Q; sub B(bar) : prototype(bad) dummy2 {4} prototype \&B;' ;
3639 is $ret , " bad" , " Prototype is set to \" bad\" " ;
3740 is $attrs , " dummy2" , " MODIFY_CODE_ATTRIBUTES called, but not for prototype(..)" ;
3841 like shift @warnings , qr / Prototype \' bar\' overridden by attribute \' prototype\( bad\)\' in Q::B/ ,
3942 " First warning is Prototype overridden" ;
40- is @warnings , 0, " No more warnings" ;
43+ is @warnings , 0, " No more warnings"
44+ or diag " Next warning: $warnings [0]" ;
4145}
4246
4347# Redeclaring a sub with a prototype attribute ignores it
48+ @warnings = ();
4449$ret = eval ' package Q; sub B(ignored) : prototype(baz) : dummy3; prototype \&B;' ;
4550is $ret , " bad" , " Declaring with prototype(..) after definition doesn't change the prototype" ;
4651is $attrs , " dummy3" , " MODIFY_CODE_ATTRIBUTES called, but not for prototype(..)" ;
@@ -52,9 +57,11 @@ like shift @warnings, qr/Prototype \'ignored\' overridden by attribute \'prototy
5257 " Shifting off Prototype overridden warning" ;
5358like shift @warnings , qr / Prototype mismatch: sub Q::B \( bad\) vs \( baz\) / ,
5459 " Attempting to redeclare triggers prototype mismatch warning against first prototype" ;
55- is @warnings , 0, " No more warnings" ;
60+ is @warnings , 0, " No more warnings"
61+ or diag " Next warning: $warnings [0]" ;
5662
5763# Confirm redifining with a prototype attribute takes it
64+ @warnings = ();
5865$ret = eval ' package Q; sub B(ignored) : prototype(baz) dummy4 {5}; prototype \&B;' ;
5966is $ret , " baz" , " Redefining with prototype(..) changes the prototype" ;
6067is $attrs , " dummy4" , " MODIFY_CODE_ATTRIBUTES called, but not for prototype(..)" ;
@@ -69,29 +76,36 @@ like shift @warnings, qr/Prototype mismatch: sub Q::B \(bad\) vs \(baz\)/,
6976 " Attempting to redeclare triggers prototype mismatch warning" ;
7077like shift @warnings , qr / Subroutine B redefined/ ,
7178 " Only other warning is subroutine redefinition" ;
72- is @warnings , 0, " No more warnings" ;
79+ is @warnings , 0, " No more warnings"
80+ or diag " Next warning: $warnings [0]" ;
7381
7482# Multiple prototype declarations only takes the last one
83+ @warnings = ();
7584$ret = eval ' package Q; sub dummy6 : prototype($$) : prototype($$$) {}; prototype \&dummy6;' ;
7685is $ret , " \$\$\$ " , " Last prototype declared wins" ;
7786like shift @warnings , qr / Attribute prototype\(\$\$\$\) discards earlier prototype attribute in same sub/ ,
7887 " Multiple prototype declarations warns" ;
79- is @warnings , 0, " No more warnings" ;
88+ is @warnings , 0, " No more warnings"
89+ or diag " Next warning: $warnings [0]" ;
8090
8191# Use attributes
92+ @warnings = ();
8293eval ' package Q; use attributes __PACKAGE__, \&B, "prototype(new)";' ;
8394$ret = prototype \&Q::B;
8495is $ret , " new" , " use attributes also sets the prototype" ;
8596like shift @warnings , qr / Prototype mismatch: sub Q::B \( baz\) vs \( new\) / ,
8697 " Prototype mismatch warning triggered" ;
87- is @warnings , 0, " No more warnings" ;
98+ is @warnings , 0, " No more warnings"
99+ or diag " Next warning: $warnings [0]" ;
88100
101+ @warnings = ();
89102eval ' package Q; use attributes __PACKAGE__, \&B, "prototype(\$\$~";' ;
90103$ret = prototype \&Q::B;
91104is $ret , " new" , " A malformed prototype doesn't reset it" ;
92105like $@ , qr / Unterminated attribute parameter in attribute list/ , " Malformed prototype croaked" ;
93106is @warnings , 0, " Malformed prototype isn't just a warning" ;
94107
108+ @warnings = ();
95109eval ' use attributes __PACKAGE__, \&foo, "prototype($$\x{100}";' ;
96110$ret = prototype \&Q::B;
97111is $ret , " new" , " A malformed prototype doesn't reset it" ;
@@ -114,7 +128,8 @@ is @warnings, 0, "Malformed prototype isn't just a warning";
114128 " (anon) baz triggers illegal proto warnings" ;
115129 like shift @warnings , qr / Prototype \' bar\' overridden by attribute \' prototype\( baz\)\' in Q::__ANON__/ ,
116130 " (anon) overridden warning triggered in anonymous sub" ;
117- is @warnings , 0, " No more warnings" ;
131+ is @warnings , 0, " No more warnings"
132+ or diag " Next warning: $warnings [0]" ;
118133}
119134
120135# Testing lexical subs
@@ -129,7 +144,8 @@ is @warnings, 0, "Malformed prototype isn't just a warning";
129144 " (lexical) baz triggers illegal proto warnings" ;
130145 like shift @warnings , qr / Prototype \' bar\' overridden by attribute \' prototype\( baz\)\' in lexsub1/ ,
131146 " (lexical) overridden warning triggered in anonymous sub" ;
132- is @warnings , 0, " No more warnings" ;
147+ is @warnings , 0, " No more warnings"
148+ or diag " Next warning: $warnings [0]" ;
133149}
134150
135151# ex: set ts=8 sts=4 sw=4 et:
0 commit comments