attrs.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl -w
# Regression tests for attributes.pm and the C< : attrs> syntax.
BEGIN {
chdir 't' if -d 't';
}
sub NTESTS () ;
$test=0;
my $failed = 0;
sub mytest {
if ($@) {
my $x = $@;
$x =~ s/\n.*\z//s;
print "# Got: $x\n"
}
else {
print "# Got unexpected success\n";
}
if ($_[0]) {
print "# Expected: $_[0]\n";
}
else {
print "# Expected success\n";
}
$failed = 1;
print "not ";
}
print "# Got: $_[1]\n";
print "# Expected: $_[2]\n";
$failed = 1;
print "not ";
}
}
eval 'sub t1 ($) : locked { $_[0]++ }';
eval 'sub t2 : locked { $_[0]++ }';
eval 'sub t3 ($) : locked ;';
eval 'sub t4 : locked ;';
my $anon1;
eval '$anon1 = sub ($) : locked:method { $_[0]++ }';
my $anon2;
eval '$anon2 = sub : locked : method { $_[0]++ }';
my $anon3;
eval '$anon3 = sub : method { $_[0]->[1] }';
eval 'sub e1 ($) : plugh ;';
BEGIN {++$ntests}
BEGIN {++$ntests}
eval 'sub e3 ($) : plugh(0,0 xyzzy ;';
mytest qr/Unterminated attribute parameter in attribute list at/;
BEGIN {++$ntests}
eval 'sub e4 ($) : plugh + xyzzy ;';
BEGIN {++$ntests}
eval 'my main $x : = 0;';
mytest;
BEGIN {++$ntests}
eval 'my $x : = 0;';
mytest;
BEGIN {++$ntests}
eval 'my $x ;';
mytest;
BEGIN {++$ntests}
eval 'my ($x) : = 0;';
mytest;
BEGIN {++$ntests}
eval 'my ($x) ;';
mytest;
BEGIN {++$ntests}
eval 'my ($x) : ;';
mytest;
BEGIN {++$ntests}
eval 'my ($x,$y) : = 0;';
mytest;
BEGIN {++$ntests}
eval 'my ($x,$y) ;';
mytest;
BEGIN {++$ntests}
eval 'my ($x,$y) : ;';
mytest;
BEGIN {++$ntests}
eval 'my ($x,$y) : plugh;';
sub A::MODIFY_SCALAR_ATTRIBUTES { return }
eval 'my A $x : plugh;';
BEGIN {++$ntests}
BEGIN {++$ntests}
sub X::MODIFY_CODE_ATTRIBUTES { die "$_[0]" }
sub X::foo { 1 }
*Y::bar = \&X::foo;
*Y::bar = \&X::foo; # second time for -w
eval 'package Z; sub Y::bar : locked';
mytest qr/^X at /;
BEGIN {++$ntests}
my @attrs = eval 'attributes::get \&Y::bar';
BEGIN {++$ntests}
@attrs = eval 'attributes::get $anon1';
BEGIN {++$ntests}
sub Z::DESTROY { }
sub Z::FETCH_CODE_ATTRIBUTES { return 'Z' }
BEGIN {++$ntests}
@attrs = eval 'attributes::get $thunk';
BEGIN {++$ntests}
# Other tests should be added above this line
sub NTESTS () { $ntests }
exit $failed;