X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Fattrs.t;h=2169e3cd7c7522e3076d7f9bf6ec22233ea239a3;hb=8a064bd6d0d7a44f3e80bed959e1dc566b57850d;hp=25abeb21b53464aba6a2c3a44a7276613d28b53f;hpb=c9124e9294bd94b9fd79577899b132159c6feb6f;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/attrs.t b/t/op/attrs.t index 25abeb2..2169e3c 100644 --- a/t/op/attrs.t +++ b/t/op/attrs.t @@ -8,13 +8,13 @@ BEGIN { require './test.pl'; } -plan tests => 47; +plan 'no_plan'; $SIG{__WARN__} = sub { die @_ }; -sub eval_ok ($) { - eval $_[0]; - is( $@, '' ); +sub eval_ok ($;$) { + eval shift; + is( $@, '', @_); } eval_ok 'sub t1 ($) : locked { $_[0]++ }'; @@ -145,3 +145,33 @@ eval 'our ${""} : foo = 1'; like $@, qr/Can't declare scalar dereference in our/; eval 'my $$foo : bar = 1'; like $@, qr/Can't declare scalar dereference in my/; + + +my @code = qw(lvalue locked method); +unshift @code, 'assertion' if $] >= 5.009; +my @other = qw(shared unique); +my %valid; +$valid{CODE} = {map {$_ => 1} @code}; +$valid{SCALAR} = {map {$_ => 1} @other}; +$valid{ARRAY} = $valid{HASH} = $valid{SCALAR}; + +our ($scalar, @array, %hash); +foreach my $value (\&foo, \$scalar, \@array, \%hash) { + my $type = ref $value; + foreach my $negate ('', '-') { + foreach my $attr (@code, @other) { + my $attribute = $negate . $attr; + eval "use attributes __PACKAGE__, \$value, '$attribute'"; + if ($valid{$type}{$attr}) { + if ($attribute eq '-shared') { + like $@, qr/^A variable may not be unshared/; + } else { + is( $@, '', "$type attribute $attribute"); + } + } else { + like $@, qr/^Invalid $type attribute: $attribute/, + "Bogus $type attribute $attribute should fail"; + } + } + } +}