3 # Regression tests for attrs.pm and the C<sub x : attrs> syntax.
8 eval 'require attrs; 1' or do {
15 no warnings qw(deprecated); # else attrs cries.
24 print "1..".NTESTS."\n";
26 eval 'sub t1 ($) { use attrs "locked"; $_[0]++ }';
27 (print "not "), $failed=1 if $@;
28 print "ok ",++$test,"\n";
31 eval 'sub t2 { use attrs "locked"; $_[0]++ }';
32 (print "not "), $failed=1 if $@;
33 print "ok ",++$test,"\n";
36 eval 'sub t3 ($) : locked ;';
37 (print "not "), $failed=1 if $@;
38 print "ok ",++$test,"\n";
41 eval 'sub t4 : locked ;';
42 (print "not "), $failed=1 if $@;
43 print "ok ",++$test,"\n";
47 eval '$anon1 = sub ($) { use attrs qw(locked method); $_[0]++ }';
48 (print "not "), $failed=1 if $@;
49 print "ok ",++$test,"\n";
53 eval '$anon2 = sub { use attrs qw(locked method); $_[0]++ }';
54 (print "not "), $failed=1 if $@;
55 print "ok ",++$test,"\n";
59 eval '$anon3 = sub { use attrs "method"; $_[0]->[1] }';
60 (print "not "), $failed=1 if $@;
61 print "ok ",++$test,"\n";
64 my @attrs = attrs::get($anon3 ? $anon3 : \&ns);
65 (print "not "), $failed=1 unless "@attrs" eq "method";
66 print "ok ",++$test,"\n";
69 @attrs = sort +attrs::get($anon2 ? $anon2 : \&ns);
70 (print "not "), $failed=1 unless "@attrs" eq "locked method";
71 print "ok ",++$test,"\n";
74 @attrs = sort +attrs::get($anon1 ? $anon1 : \&ns);
75 (print "not "), $failed=1 unless "@attrs" eq "locked method";
76 print "ok ",++$test,"\n";
79 eval 'sub e1 ($) : plugh ;';
80 unless ($@ && $@ =~ m/^Invalid CODE attribute: ["']?plugh["']? at/) {
87 print "ok ",++$test,"\n";
90 eval 'sub e2 ($) : plugh(0,0) xyzzy ;';
91 unless ($@ && $@ =~ m/^Invalid CODE attributes: ["']?plugh\(0,0\)["']? /) {
98 print "ok ",++$test,"\n";
101 eval 'sub e3 ($) : plugh(0,0 xyzzy ;';
102 unless ($@ && $@ =~ m/Unterminated attribute parameter in attribute list at/) {
109 print "ok ",++$test,"\n";
112 eval 'sub e4 ($) : plugh + xyzzy ;';
113 unless ($@ && $@ =~ m/Invalid separator character '[+]' in attribute list at/) {
120 print "ok ",++$test,"\n";
125 local $SIG{__WARN__} = sub {$w = shift} ;
126 eval 'sub w1 ($) { use warnings "deprecated"; use attrs "locked"; $_[0]++ }';
127 (print "not "), $failed=1 if $@;
128 print "ok ",++$test,"\n";
130 (print "not "), $failed=1
131 if $w !~ /^pragma "attrs" is deprecated, use "sub NAME : ATTRS" instead at/;
132 print "ok ",++$test,"\n";
137 # Other tests should be added above this line
139 sub NTESTS () { $ntests }