X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Fattrs.t;h=1ed92a1a8d274c472d3aeebca52cb2578d10415e;hb=48e3bbddf569369fe6921f305df6ab7290c91152;hp=615e4d33430a0b5bf3e9cfcd1085d0b1114fd2a8;hpb=cb50131aab68ac6dda048612c6e853b8cb08701e;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/attrs.t b/t/op/attrs.t index 615e4d3..1ed92a1 100644 --- a/t/op/attrs.t +++ b/t/op/attrs.t @@ -4,7 +4,7 @@ BEGIN { chdir 't' if -d 't'; - unshift @INC, '../lib'; + @INC = '../lib'; } sub NTESTS () ; @@ -19,6 +19,7 @@ print "1..".NTESTS."\n"; $SIG{__WARN__} = sub { die @_ }; sub mytest { + my $bad = ''; if (!$@ ne !$_[0] || $_[0] && $@ !~ $_[0]) { if ($@) { my $x = $@; @@ -35,15 +36,15 @@ sub mytest { print "# Expected success\n"; } $failed = 1; - print "not "; + $bad = 'not '; } elsif (@_ == 3 && $_[1] ne $_[2]) { print "# Got: $_[1]\n"; print "# Expected: $_[2]\n"; $failed = 1; - print "not "; + $bad = 'not '; } - print "ok ",++$test,"\n"; + print $bad."ok ".++$test."\n"; } eval 'sub t1 ($) : locked { $_[0]++ }'; @@ -142,15 +143,20 @@ eval 'my A $x : plugh plover;'; mytest qr/^SCALAR package attributes may clash with future reserved words: ["']?plugh["']? /; BEGIN {++$ntests} +eval 'package Cat; my Cat @socks;'; +mytest qr/^Can't declare class for non-scalar \@socks in "my"/; +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'; +eval 'package Z; sub Y::bar : foo'; mytest qr/^X at /; BEGIN {++$ntests} -my @attrs = eval 'attributes::get \&Y::bar'; +eval 'package Z; sub Y::baz : locked {}'; +my @attrs = eval 'attributes::get \&Y::baz'; mytest '', "@attrs", "locked"; BEGIN {++$ntests} @@ -168,6 +174,45 @@ BEGIN {++$ntests} mytest '', "@attrs", "locked method Z"; BEGIN {++$ntests} +# Test ability to modify existing sub's (or XSUB's) attributes. +eval 'package A; sub X { $_[0] } sub X : lvalue'; +@attrs = eval 'attributes::get \&A::X'; +mytest '', "@attrs", "lvalue"; +BEGIN {++$ntests} + +# Above not with just 'pure' built-in attributes. +sub Z::MODIFY_CODE_ATTRIBUTES { (); } +eval 'package Z; sub L { $_[0] } sub L : Z lvalue'; +@attrs = eval 'attributes::get \&Z::L'; +mytest '', "@attrs", "lvalue Z"; +BEGIN {++$ntests} + + +# Begin testing attributes that tie + +{ + package Ttie; + sub DESTROY {} + sub TIESCALAR { my $x = $_[1]; bless \$x, $_[0]; } + sub FETCH { ${$_[0]} } + sub STORE { + #print "# In Ttie::STORE\n"; + ::mytest ''; + ${$_[0]} = $_[1]*2; + } + package Tloop; + sub MODIFY_SCALAR_ATTRIBUTES { tie ${$_[1]}, 'Ttie', -1; (); } +} + +eval ' + package Tloop; + for my $i (0..2) { + my $x : TieLoop = $i; + $x != $i*2 and ::mytest "", $x, $i*2; + } +'; +mytest; +BEGIN {$ntests += 4} # Other tests should be added above this line