Re: [perl #36130] chr(-1) should probably return undef
[p5sagit/p5-mst-13.2.git] / t / op / attrs.t
index 264de8a..2169e3c 100644 (file)
@@ -8,13 +8,13 @@ BEGIN {
     require './test.pl';
 }
 
-plan tests => 39;
+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]++ }';
@@ -56,6 +56,24 @@ like $@, qr/^Invalid SCALAR attribute: ["']?plugh["']? at/;
 eval '{my ($x,$y) : plugh(})}';
 like $@, qr/^Invalid SCALAR attribute: ["']?plugh\(}\)["']? at/;
 
+# More syntax tests from the attributes manpage
+eval 'my $x : switch(10,foo(7,3))  :  expensive;';
+like $@, qr/^Invalid SCALAR attributes: ["']?switch\(10,foo\(7,3\)\) : expensive["']? at/;
+eval q/my $x : Ugly('\(") :Bad;/;
+like $@, qr/^Invalid SCALAR attributes: ["']?Ugly\('\\\("\) : Bad["']? at/;
+eval 'my $x : _5x5;';
+like $@, qr/^Invalid SCALAR attribute: ["']?_5x5["']? at/;
+eval 'my $x : locked method;';
+like $@, qr/^Invalid SCALAR attributes: ["']?locked : method["']? at/;
+eval 'my $x : switch(10,foo();';
+like $@, qr/^Unterminated attribute parameter in attribute list at/;
+eval q/my $x : Ugly('(');/;
+like $@, qr/^Unterminated attribute parameter in attribute list at/;
+eval 'my $x : 5x5;';
+like $@, qr/error/;
+eval 'my $x : Y2::north;';
+like $@, qr/Invalid separator character ':' in attribute list at/;
+
 sub A::MODIFY_SCALAR_ATTRIBUTES { return }
 eval 'my A $x : plugh;';
 like $@, qr/^SCALAR package attribute may clash with future reserved word: ["']?plugh["']? at/;
@@ -127,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";
+           }
+       }
+    }
+}