3 # Regression tests for attributes.pm and the C< : attrs> syntax.
7 unshift @INC, '../lib';
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 sub X::MODIFY_CODE_ATTRIBUTES { die "$_[0]" }
148 *Y::bar = \&X::foo; # second time for -w
149 eval 'package Z; sub Y::bar : locked';
153 my @attrs = eval 'attributes::get \&Y::bar';
154 mytest '', "@attrs", "locked";
157 @attrs = eval 'attributes::get $anon1';
158 mytest '', "@attrs", "locked method";
162 sub Z::FETCH_CODE_ATTRIBUTES { return 'Z' }
163 my $thunk = eval 'bless +sub : method locked { 1 }, "Z"';
164 mytest '', ref($thunk), "Z";
167 @attrs = eval 'attributes::get $thunk';
168 mytest '', "@attrs", "locked method Z";
172 # Other tests should be added above this line
174 sub NTESTS () { $ntests }