This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Enhance lfs tests: check every seek and sysseek
[perl5.git] / t / lib / attrs.t
CommitLineData
09bef843
SB
1#!./perl
2
3# Regression tests for attrs.pm and the C<sub x : attrs> syntax.
4
5BEGIN {
6 chdir 't' if -d 't';
7 unshift @INC, '../lib';
8 eval 'require attrs; 1' or do {
9 print "1..0\n";
10 exit 0;
11 }
12}
13
14sub NTESTS () ;
15
16my $test, $ntests;
17BEGIN {$ntests=0}
18$test=0;
19my $failed = 0;
20
21print "1..".NTESTS."\n";
22
23eval 'sub t1 ($) { use attrs "locked"; $_[0]++ }';
24(print "not "), $failed=1 if $@;
25print "ok ",++$test,"\n";
26BEGIN {++$ntests}
27
28eval 'sub t2 { use attrs "locked"; $_[0]++ }';
29(print "not "), $failed=1 if $@;
30print "ok ",++$test,"\n";
31BEGIN {++$ntests}
32
33eval 'sub t3 ($) : locked ;';
34(print "not "), $failed=1 if $@;
35print "ok ",++$test,"\n";
36BEGIN {++$ntests}
37
38eval 'sub t4 : locked ;';
39(print "not "), $failed=1 if $@;
40print "ok ",++$test,"\n";
41BEGIN {++$ntests}
42
43my $anon1;
44eval '$anon1 = sub ($) { use attrs qw(locked method); $_[0]++ }';
45(print "not "), $failed=1 if $@;
46print "ok ",++$test,"\n";
47BEGIN {++$ntests}
48
49my $anon2;
50eval '$anon2 = sub { use attrs qw(locked method); $_[0]++ }';
51(print "not "), $failed=1 if $@;
52print "ok ",++$test,"\n";
53BEGIN {++$ntests}
54
55my $anon3;
56eval '$anon3 = sub { use attrs "method"; $_[0]->[1] }';
57(print "not "), $failed=1 if $@;
58print "ok ",++$test,"\n";
59BEGIN {++$ntests}
60
61my @attrs = attrs::get($anon3 ? $anon3 : \&ns);
62(print "not "), $failed=1 unless "@attrs" eq "method";
63print "ok ",++$test,"\n";
64BEGIN {++$ntests}
65
66@attrs = sort +attrs::get($anon2 ? $anon2 : \&ns);
67(print "not "), $failed=1 unless "@attrs" eq "locked method";
68print "ok ",++$test,"\n";
69BEGIN {++$ntests}
70
71@attrs = sort +attrs::get($anon1 ? $anon1 : \&ns);
72(print "not "), $failed=1 unless "@attrs" eq "locked method";
73print "ok ",++$test,"\n";
74BEGIN {++$ntests}
75
76eval 'sub e1 ($) : plugh ;';
77unless ($@ && $@ =~ m/^Invalid CODE attribute: ["']?plugh["']? at/) {
78 my $x = $@;
79 $x =~ s/\n.*\z//s;
80 print "# $x\n";
81 print "not ";
82 $failed = 1;
83}
84print "ok ",++$test,"\n";
85BEGIN {++$ntests}
86
87eval 'sub e2 ($) : plugh(0,0) xyzzy ;';
88unless ($@ && $@ =~ m/^Invalid CODE attributes: ["']?plugh\(0,0\)["']? /) {
89 my $x = $@;
90 $x =~ s/\n.*\z//s;
91 print "# $x\n";
92 print "not ";
93 $failed = 1;
94}
95print "ok ",++$test,"\n";
96BEGIN {++$ntests}
97
98eval 'sub e3 ($) : plugh(0,0 xyzzy ;';
99unless ($@ && $@ =~ m/Unterminated attribute parameter in attribute list at/) {
100 my $x = $@;
101 $x =~ s/\n.*\z//s;
102 print "# $x\n";
103 print "not ";
104 $failed = 1;
105}
106print "ok ",++$test,"\n";
107BEGIN {++$ntests}
108
109eval 'sub e4 ($) : plugh + xyzzy ;';
110unless ($@ && $@ =~ m/Invalid separator character '[+]' in attribute list at/) {
111 my $x = $@;
112 $x =~ s/\n.*\z//s;
113 print "# $x\n";
114 print "not ";
115 $failed = 1;
116}
117print "ok ",++$test,"\n";
118BEGIN {++$ntests}
119
120
121# Other tests should be added above this line
122
123sub NTESTS () { $ntests }
124
125exit $failed;