3 # Regression tests for attributes.pm and the C< : attrs> syntax.
17 print "1..".NTESTS."\n";
19 $SIG{__WARN__} = sub { die @_ };
22 if (!$@ ne !$_[0] || $_[0] && $@ !~ $_[0]) {
29 print "# Got unexpected success\n";
32 print "# Expected: $_[0]\n";
35 print "# Expected success\n";
40 elsif (@_ == 3 && $_[1] ne $_[2]) {
41 print "# Got: $_[1]\n";
42 print "# Expected: $_[2]\n";
46 print "ok ",++$test,"\n";
49 eval 'sub t1 ($) : locked { $_[0]++ }';
53 eval 'sub t2 : locked { $_[0]++ }';
57 eval 'sub t3 ($) : locked ;';
61 eval 'sub t4 : locked ;';
66 eval '$anon1 = sub ($) : locked:method { $_[0]++ }';
71 eval '$anon2 = sub : locked : method { $_[0]++ }';
76 eval '$anon3 = sub : method { $_[0]->[1] }';
80 eval 'sub e1 ($) : plugh ;';
81 mytest qr/^Invalid CODE attributes?: ["']?plugh["']? at/;
84 eval 'sub e2 ($) : plugh(0,0) xyzzy ;';
85 mytest qr/^Invalid CODE attributes: ["']?plugh\(0,0\)["']? /;
88 eval 'sub e3 ($) : plugh(0,0 xyzzy ;';
89 mytest qr/Unterminated attribute parameter in attribute list at/;
92 eval 'sub e4 ($) : plugh + xyzzy ;';
93 mytest qr/Invalid separator character '[+]' in attribute list at/;
96 eval 'my main $x : = 0;';
108 eval 'my ($x) : = 0;';
120 eval 'my ($x,$y) : = 0;';
128 eval 'my ($x,$y) : ;';
132 eval 'my ($x,$y) : plugh;';
133 mytest qr/^Invalid SCALAR attribute: ["']?plugh["']? at/;
136 sub A::MODIFY_SCALAR_ATTRIBUTES { return }
137 eval 'my A $x : plugh;';
138 mytest qr/^SCALAR package attribute may clash with future reserved word: ["']?plugh["']? at/;
141 eval 'my A $x : plugh plover;';
142 mytest qr/^SCALAR package attributes may clash with future reserved words: ["']?plugh["']? /;
145 eval 'package Cat; my Cat @socks;';
146 mytest qr/^Can't declare class for non-scalar \@socks in "my"/;
149 sub X::MODIFY_CODE_ATTRIBUTES { die "$_[0]" }
152 *Y::bar = \&X::foo; # second time for -w
153 eval 'package Z; sub Y::bar : foo';
157 eval 'package Z; sub Y::baz : locked {}';
158 my @attrs = eval 'attributes::get \&Y::baz';
159 mytest '', "@attrs", "locked";
162 @attrs = eval 'attributes::get $anon1';
163 mytest '', "@attrs", "locked method";
167 sub Z::FETCH_CODE_ATTRIBUTES { return 'Z' }
168 my $thunk = eval 'bless +sub : method locked { 1 }, "Z"';
169 mytest '', ref($thunk), "Z";
172 @attrs = eval 'attributes::get $thunk';
173 mytest '', "@attrs", "locked method Z";
177 # Other tests should be added above this line
179 sub NTESTS () { $ntests }