1 # Copyright (C) 2001, 2002, 2003, 2008 Free Software Foundation, Inc.
3 # This file is part of GNU Automake.
5 # GNU Automake is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
10 # GNU Automake is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (eval { require 5.007_002
; } # for CLONE support
21 && $Config{useithreads
})
31 use Automake
::Condition qw
/TRUE FALSE/;
32 use Automake
::DisjConditions
;
36 my $cond = new Automake
::Condition
"COND1_TRUE", "COND2_FALSE";
37 return threads
->new (sub {
38 my $other = new Automake
::Condition
"COND3_FALSE";
39 return threads
->new (sub {
40 my $set1 = new Automake
::DisjConditions
$cond, $other;
41 return threads
->new (sub {
42 my $set2 = new Automake
::DisjConditions
$other, $cond;
43 return 1 unless $set1 == $set2;
44 return 1 if $set1->false;
45 return 1 if $set1->true;
46 return 1 unless (new Automake
::DisjConditions
)->false;
47 return 1 if (new Automake
::DisjConditions
)->true;
59 push @set, new Automake
::Condition @
$cond;
61 return new Automake
::DisjConditions
@set;
66 my @tests = ([[["FALSE"]],
72 [[["COND1_TRUE", "COND2_TRUE"],
73 ["COND3_FALSE", "COND2_TRUE"]],
75 ["COND1_FALSE", "COND3_TRUE"]]],
77 [[["COND1_TRUE", "COND2_TRUE"],
81 [[["COND1_TRUE", "COND2_TRUE"],
88 [["COND1_FALSE", "COND2_TRUE"]]]
93 my $set = build_set @
{$t->[0]};
96 my $res = build_set @
{$t->[1]};
97 my $inv = $set->invert;
100 print " (I) " . $set->string . "\n\t"
101 . $inv->string . ' != ' . $res->string . "\n";
112 my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
113 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"]],
114 [["FOO_TRUE", "BAR_FALSE"]]],
116 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
117 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
118 ["FOO_TRUE", "BAR_TRUE"]],
121 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
122 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
123 ["FOO_TRUE", "BAR_TRUE"],
127 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
128 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
129 ["BAR_TRUE", "BAZ_TRUE"],
130 ["BAR_FALSE", "BAZ_TRUE"]],
131 [["BAZ_TRUE"], ["FOO_TRUE", "BAR_FALSE"]]],
133 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
134 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
135 ["BAR_TRUE", "BAZ_TRUE"],
136 ["BAR_FALSE", "BAZ_TRUE"],
138 [["FOO_FALSE"], ["BAZ_TRUE"], ["BAR_FALSE"]]],
141 ["A_FALSE", "B_TRUE"]],
145 ["A_FALSE", "B_FALSE", "C_TRUE"],
146 ["A_FALSE", "B_FALSE", "C_FALSE"]],
147 [["A_FALSE"], ["B_TRUE"]]],
150 ["A_FALSE", "B_FALSE", "C_TRUE"],
151 ["A_FALSE", "B_FALSE", "C_FALSE"],
152 ["A_TRUE", "B_FALSE"]],
155 [[["A_TRUE", "B_TRUE"],
156 ["A_TRUE", "B_FALSE"],
157 ["A_TRUE", "C_FALSE", "D_FALSE"]],
160 [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
161 ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
162 ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
163 ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
164 ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
165 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
166 ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
167 ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"]],
168 [ ["B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
169 ["B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
170 ["B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
171 ["B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"]]],
173 [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
174 ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
175 ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
176 ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
177 ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
178 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
179 ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
180 ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
181 ["A_FALSE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"],
182 ["A_FALSE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
183 ["A_FALSE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
184 ["A_FALSE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
185 ["A_TRUE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
186 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
187 ["A_TRUE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
188 ["A_TRUE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"]],
189 [["C_FALSE", "E_FALSE"],
190 ["C_TRUE", "E_TRUE"]]],
193 ["A_TRUE", "B_FALSE"],
194 ["A_TRUE", "B_TRUE", "C_FALSE"],
195 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE"],
196 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_FALSE"],
197 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE", "F_FALSE"],
198 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"]],
201 # Simplify should work with up to 31 variables.
202 [[["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
203 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
204 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
205 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
206 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
207 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
209 ["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
210 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
211 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
212 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
213 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
214 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
216 ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
217 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
218 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
219 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
220 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
221 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
223 ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
224 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
225 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
226 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
227 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
228 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
230 [[ "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
231 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
232 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
233 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
234 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
235 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE"
240 my $set = build_set @
{$t->[0]};
242 if threads
->new(sub {
243 my $res = build_set @
{$t->[1]};
244 return threads
->new(sub {
246 # Make sure simplify() yields the expected result.
247 my $sim = $set->simplify;
248 return threads
->new(sub {
251 print " (S1) " . $set->string . "\n\t"
252 . $sim->string . ' != ' . $res->string . "\n";
256 # Make sure simplify() is idempotent.
257 my $sim2 = $sim->simplify;
258 return threads
->new(sub {
261 print " (S2) " . $sim->string . "\n\t"
262 . $sim2->string . ' != ' . $sim->string . "\n";
266 # Also exercise invert() while we are at it.
268 my $inv1 = $set->invert->simplify;
269 return threads
->new(sub {
270 my $inv2 = $sim->invert->simplify;
271 return threads
->new(sub {
274 print " (S3) " . $set->string . ", " . $sim->string . "\n\t"
275 . $inv1->string . ' -= ' . $inv2->string . "\n";
289 sub test_sub_conditions
()
291 my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
292 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
295 [["BAR_FALSE", "BAZ_FALSE"],
296 ["BAR_FALSE", "BAZ_TRUE"]]],
298 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
299 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
301 ["FOO_TRUE", "BAR_FALSE"],
305 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
306 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
308 ["FOO_TRUE", "BAR_TRUE"],
311 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
312 ["FOO_TRUE", "BAZ_TRUE"],
314 ["FOO_TRUE", "BAR_TRUE"],
317 [[["FOO_TRUE", "BAR_FALSE"],
318 ["FOO_TRUE", "BAR_TRUE"]],
319 ["FOO_TRUE", "BAR_TRUE"],
336 my $t1 = build_set @
{$t->[0]};
338 if threads
->new(sub {
339 my $t2 = new Automake
::Condition @
{$t->[1]};
340 return threads
->new(sub {
341 my $t3 = build_set @
{$t->[2]};
342 return threads
->new(sub {
344 # Make sure sub_conditions() yields the expected result.
345 my $s = $t1->sub_conditions ($t2);
349 print " (SC) " . $t1->string . "\n\t"
350 . $s->string . ' != ' . $t3->string . "\n";
362 my @tests = ([[["TRUE"]],
372 ["C1_TRUE", "C2_TRUE"],
374 [[["C1_TRUE", "C2_TRUE"]],
376 "which is included in"],
382 ["C1_FALSE", "C2_TRUE"],
388 my $t1 = build_set @
{$t->[0]};
390 if threads
->new(sub {
391 my $t2 = new Automake
::Condition @
{$t->[1]};
393 return threads
->new(sub {
394 my ($ans, $cond) = $t1->ambiguous_p ("FOO", $t2);
395 return threads
->new(sub {
396 if ($t3 && $ans !~ /FOO.*$t3/)
398 print " (A1) " . $t1->string . " vs. " . $t2->string . "\n\t"
399 . "Error message '$ans' does not match '$t3'\n";
402 if (!$t3 && $ans ne '')
404 print " (A2) " . $t1->string . " vs. " . $t2->string . "\n\t"
405 . "Unexpected error message: $ans\n";
418 || test_sub_conditions
421 ### Setup "GNU" style for perl-mode and cperl-mode.
423 ## perl-indent-level: 2
424 ## perl-continued-statement-offset: 2
425 ## perl-continued-brace-offset: 0
426 ## perl-brace-offset: 0
427 ## perl-brace-imaginary-offset: 0
428 ## perl-label-offset: -2
429 ## cperl-indent-level: 2
430 ## cperl-brace-offset: 0
431 ## cperl-continued-brace-offset: 0
432 ## cperl-label-offset: -2
433 ## cperl-extra-newline-before-brace: t
434 ## cperl-merge-trailing-else: nil
435 ## cperl-continued-statement-offset: 2