Commit | Line | Data |
cb8340be |
1 | #!./perl |
2 | |
e76bdc3c |
3 | BEGIN { $^W=0 } |
4 | |
5 | use base 'assertions::compat'; |
6 | |
8c63d938 |
7 | sub callme ($ ) : assertion { |
8 | return shift; |
9 | } |
10 | |
11 | # select STDERR; $|=1; |
12 | |
13 | my @expr=( '1' => 1, |
14 | '0' => 0, |
15 | '1 && 1' => 1, |
16 | '1 && 0' => 0, |
17 | '0 && 1' => 0, |
18 | '0 && 0' => 0, |
19 | '1 || 1' => 1, |
20 | '1 || 0' => 1, |
21 | '0 || 1' => 1, |
22 | '0 || 0' => 0, |
23 | '(1)' => 1, |
24 | '(0)' => 0, |
25 | '1 && ((1) && 1)' => 1, |
26 | '1 && (0 || 1)' => 1, |
27 | '1 && ( 0' => undef, |
28 | '1 &&' => undef, |
29 | '&& 1' => undef, |
30 | '1 && || 1' => undef, |
31 | '(1 && 1) && 1)' => undef, |
32 | 'one && two' => 1, |
33 | '_ && one' => 0, |
34 | 'one && three' => 0, |
35 | '1 ' => 1, |
36 | ' 1' => 1, |
37 | ' 1 ' => 1, |
38 | ' ( 1 && 1 ) ' => 1, |
39 | ' ( 1 && 0 ) ' => 0, |
40 | '(( 1 && 1) && ( 1 || 0)) || _ && one && ( one || three)' => 1 ); |
41 | |
e76bdc3c |
42 | my $supported = assertions::compat::supported(); |
43 | |
7788eb69 |
44 | my $n=@expr/2 + ($supported ? 12 : 0); |
cb8340be |
45 | my $i=1; |
8c63d938 |
46 | print "1..$n\n"; |
cb8340be |
47 | |
8c63d938 |
48 | use assertions::activate 'one', 'two'; |
49 | require assertions; |
50 | |
51 | while (@expr) { |
52 | my $expr=shift @expr; |
53 | my $expected=shift @expr; |
aefc56c5 |
54 | my $result=eval {assertions::_calc_expr($expr)}; |
8c63d938 |
55 | if (defined $expected) { |
56 | unless (defined $result and $result == $expected) { |
aefc56c5 |
57 | print STDERR "assertions::_calc_expr($expr) failed,". |
8c63d938 |
58 | " expected '$expected' but '$result' obtained (\$@=$@)\n"; |
59 | print "not "; |
60 | } |
61 | } |
62 | else { |
63 | if (defined $result) { |
aefc56c5 |
64 | print STDERR "assertions::_calc_expr($expr) failed,". |
8c63d938 |
65 | " expected undef but '$result' obtained\n"; |
66 | print "not "; |
67 | } |
68 | } |
69 | print "ok ", $i++, "\n"; |
cb8340be |
70 | } |
71 | |
e76bdc3c |
72 | if ($supported) { |
cb8340be |
73 | |
e76bdc3c |
74 | # @expr/2+1 |
75 | if (callme(1)) { |
76 | print STDERR "assertions called by default\n"; |
77 | print "not "; |
78 | } |
79 | print "ok ", $i++, "\n"; |
80 | |
81 | # 2 |
82 | use assertions::activate 'mine'; |
83 | { |
84 | package mine; |
85 | use base 'assertions::compat'; |
86 | sub callme ($) : assertion { |
87 | return shift; |
88 | } |
89 | use assertions; |
90 | unless (callme(1)) { |
91 | print STDERR "'use assertions;' doesn't active assertions based on package name\n"; |
92 | print "not "; |
93 | } |
94 | } |
95 | print "ok ", $i++, "\n"; |
96 | |
97 | # 3 |
98 | use assertions 'foo'; |
99 | if (callme(1)) { |
100 | print STDERR "assertion deselection doesn't work\n"; |
101 | print "not "; |
102 | } |
103 | print "ok ", $i++, "\n"; |
104 | |
105 | # 4 |
106 | use assertions::activate 'bar', 'doz'; |
cb8340be |
107 | use assertions 'bar'; |
e76bdc3c |
108 | unless (callme(1)) { |
109 | print STDERR "assertion selection doesn't work\n"; |
cb8340be |
110 | print "not "; |
111 | } |
e76bdc3c |
112 | print "ok ", $i++, "\n"; |
113 | |
114 | # 5 |
115 | use assertions q(_ && doz); |
116 | unless (callme(1)) { |
117 | print STDERR "assertion activation filtering doesn't work\n"; |
118 | print "not "; |
119 | } |
120 | print "ok ", $i++, "\n"; |
121 | |
122 | # 6 |
123 | use assertions q(_ && foo); |
124 | if (callme(1)) { |
125 | print STDERR "assertion deactivation filtering doesn't work\n"; |
126 | print "not "; |
127 | } |
128 | print "ok ", $i++, "\n"; |
129 | |
130 | # 7 |
131 | if (1) { |
132 | use assertions 'bar'; |
133 | } |
134 | if (callme(1)) { |
135 | print STDERR "assertion scoping doesn't work\n"; |
136 | print "not "; |
137 | } |
138 | print "ok ", $i++, "\n"; |
cb8340be |
139 | |
e76bdc3c |
140 | # 8 |
141 | use assertions::activate 're.*'; |
142 | use assertions 'reassert'; |
143 | unless (callme(1)) { |
144 | print STDERR "assertion selection with re failed\n"; |
cb8340be |
145 | print "not "; |
146 | } |
e76bdc3c |
147 | print "ok ", $i++, "\n"; |
148 | |
149 | # 9 |
150 | my $b=12; |
151 | { |
152 | use assertions 'bar'; |
153 | callme(my $b=45); |
154 | unless ($b == 45) { |
155 | print STDERR "this shouldn't fail ever (b=$b)\n"; |
156 | print "not "; |
157 | } |
158 | } |
159 | print "ok ", $i++, "\n"; |
160 | |
161 | # 10 |
162 | { |
163 | no assertions; |
164 | callme(my $b=46); |
165 | if (defined $b) { |
166 | print STDERR "lexical declaration in assertion arg ignored (b=$b\n"; |
167 | print "not "; |
168 | } |
169 | } |
170 | print "ok ", $i++, "\n"; |
7788eb69 |
171 | |
172 | # 11 |
173 | { |
174 | use assertions::activate sub { return 1 if $_[0] eq 'via_sub' }; |
175 | use assertions 'via_sub'; |
176 | callme(my $b=47); |
177 | unless ($b == 47) { |
178 | print STDERR "this shouldn't fail ever (b=$b)\n"; |
179 | print "not "; |
180 | } |
181 | } |
182 | print "ok ", $i++, "\n"; |
183 | |
184 | # 12 |
185 | { |
186 | use assertions 'not_asserted'; |
187 | callme(my $b=48); |
188 | if ($b == 48) { |
189 | print STDERR "this shouldn't fail ever (b=$b)\n"; |
190 | print "not "; |
191 | } |
192 | } |
193 | print "ok ", $i++, "\n"; |
cb8340be |
194 | } |