1 # Copyright (C) 2001, 2002, 2003, 2008, 2009 Free Software Foundation,
4 # This file is part of GNU Automake.
6 # GNU Automake is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # GNU Automake is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 use Automake::Condition qw/TRUE FALSE/;
20 use Automake::DisjConditions;
24 my $true = new Automake::DisjConditions TRUE;
25 my $false = new Automake::DisjConditions FALSE;
26 my $cond = new Automake::Condition "COND1_TRUE", "COND2_FALSE";
27 my $other = new Automake::Condition "COND3_FALSE";
28 my $another = new Automake::Condition "COND3_TRUE", "COND4_FALSE";
29 my $set1 = new Automake::DisjConditions $cond, $other;
30 my $set2 = new Automake::DisjConditions $other, $cond;
31 my $set3 = new Automake::DisjConditions FALSE, $another;
32 return 1 unless $set1 == $set2;
33 return 1 if $set1->false;
34 return 1 if $set1->true;
35 return 1 unless (new Automake::DisjConditions)->false;
36 return 1 if (new Automake::DisjConditions)->true;
37 return 1 unless $true->human eq 'TRUE';
38 return 1 unless $false->human eq 'FALSE';
39 return 1 unless $set1->human eq "(COND1 and !COND2) or (!COND3)";
40 return 1 unless $set2->human eq "(COND1 and !COND2) or (!COND3)";
41 my $one_cond_human = $set1->one_cond->human;
42 return 1 unless $one_cond_human eq "!COND3"
43 || $one_cond_human eq "COND1 and !COND2";
44 return 1 unless $set1->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
46 my $merged1 = $set1->merge ($set2);
47 my $merged2 = $set1->merge ($cond);
48 my $mult1 = $set1->multiply ($set3);
49 my $mult2 = $set1->multiply ($another);
50 return 1 unless $merged1->simplify->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
51 return 1 unless $merged2->simplify->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
52 return 1 unless $mult1->string eq "COND1_TRUE COND2_FALSE COND3_TRUE COND4_FALSE";
53 return 1 unless $mult1 == $mult2;
64 push @set, new Automake::Condition @$cond;
66 return new Automake::DisjConditions @set;
71 my @tests = ([[["FALSE"]],
77 [[["COND1_TRUE", "COND2_TRUE"],
78 ["COND3_FALSE", "COND2_TRUE"]],
80 ["COND1_FALSE", "COND3_TRUE"]]],
82 [[["COND1_TRUE", "COND2_TRUE"],
86 [[["COND1_TRUE", "COND2_TRUE"],
93 [["COND1_FALSE", "COND2_TRUE"]]]
98 my $set = build_set @{$t->[0]};
99 my $res = build_set @{$t->[1]};
100 my $inv = $set->invert;
103 print " (I) " . $set->string . "\n\t"
104 . $inv->string . ' != ' . $res->string . "\n";
113 my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
114 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"]],
115 [["FOO_TRUE", "BAR_FALSE"]]],
117 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
118 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
119 ["FOO_TRUE", "BAR_TRUE"]],
122 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
123 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
124 ["FOO_TRUE", "BAR_TRUE"],
128 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
129 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
130 ["BAR_TRUE", "BAZ_TRUE"],
131 ["BAR_FALSE", "BAZ_TRUE"]],
132 [["BAZ_TRUE"], ["FOO_TRUE", "BAR_FALSE"]]],
134 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
135 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
136 ["BAR_TRUE", "BAZ_TRUE"],
137 ["BAR_FALSE", "BAZ_TRUE"],
139 [["FOO_FALSE"], ["BAZ_TRUE"], ["BAR_FALSE"]]],
142 ["A_FALSE", "B_TRUE"]],
146 ["A_FALSE", "B_FALSE", "C_TRUE"],
147 ["A_FALSE", "B_FALSE", "C_FALSE"]],
148 [["A_FALSE"], ["B_TRUE"]]],
151 ["A_FALSE", "B_FALSE", "C_TRUE"],
152 ["A_FALSE", "B_FALSE", "C_FALSE"],
153 ["A_TRUE", "B_FALSE"]],
156 [[["A_TRUE", "B_TRUE"],
157 ["A_TRUE", "B_FALSE"],
158 ["A_TRUE", "C_FALSE", "D_FALSE"]],
161 [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
162 ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
163 ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
164 ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
165 ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
166 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
167 ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
168 ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"]],
169 [ ["B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
170 ["B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
171 ["B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
172 ["B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"]]],
174 [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
175 ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
176 ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
177 ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
178 ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
179 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
180 ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
181 ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
182 ["A_FALSE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"],
183 ["A_FALSE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
184 ["A_FALSE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
185 ["A_FALSE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
186 ["A_TRUE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
187 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
188 ["A_TRUE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
189 ["A_TRUE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"]],
190 [["C_FALSE", "E_FALSE"],
191 ["C_TRUE", "E_TRUE"]]],
194 ["A_TRUE", "B_FALSE"],
195 ["A_TRUE", "B_TRUE", "C_FALSE"],
196 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE"],
197 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_FALSE"],
198 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE", "F_FALSE"],
199 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"]],
202 # Simplify should work with up to 31 variables.
203 [[["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
204 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
205 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
206 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
207 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
208 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
210 ["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
211 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
212 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
213 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
214 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
215 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
217 ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
218 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
219 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
220 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
221 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
222 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
224 ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
225 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
226 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
227 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
228 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
229 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
231 [[ "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
232 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
233 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
234 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
235 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
236 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE"
241 my $set = build_set @{$t->[0]};
242 my $res = build_set @{$t->[1]};
244 # Make sure simplify() yields the expected result.
245 my $sim = $set->simplify;
248 print " (S1) " . $set->string . "\n\t"
249 . $sim->string . ' != ' . $res->string . "\n";
253 # Make sure simplify() is idempotent.
254 my $sim2 = $sim->simplify;
257 print " (S2) " . $sim->string . "\n\t"
258 . $sim2->string . ' != ' . $sim->string . "\n";
262 # Also exercise invert() while we are at it.
264 my $inv1 = $set->invert->simplify;
265 my $inv2 = $sim->invert->simplify;
268 print " (S3) " . $set->string . ", " . $sim->string . "\n\t"
269 . $inv1->string . ' != ' . $inv2->string . "\n";
277 sub test_sub_conditions ()
279 my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
280 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
283 [["BAR_FALSE", "BAZ_FALSE"],
284 ["BAR_FALSE", "BAZ_TRUE"]]],
286 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
287 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
289 ["FOO_TRUE", "BAR_FALSE"],
293 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
294 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
296 ["FOO_TRUE", "BAR_TRUE"],
299 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
300 ["FOO_TRUE", "BAZ_TRUE"],
302 ["FOO_TRUE", "BAR_TRUE"],
305 [[["FOO_TRUE", "BAR_FALSE"],
306 ["FOO_TRUE", "BAR_TRUE"]],
307 ["FOO_TRUE", "BAR_TRUE"],
324 my $t1 = build_set @{$t->[0]};
325 my $t2 = new Automake::Condition @{$t->[1]};
326 my $t3 = build_set @{$t->[2]};
328 # Make sure sub_conditions() yields the expected result.
329 my $s = $t1->sub_conditions ($t2);
332 print " (SC) " . $t1->string . "\n\t"
333 . $s->string . ' != ' . $t3->string . "\n";
341 my @tests = ([[["TRUE"]],
351 ["C1_TRUE", "C2_TRUE"],
353 [[["C1_TRUE", "C2_TRUE"]],
355 "which is included in"],
361 ["C1_FALSE", "C2_TRUE"],
366 my $t1 = build_set @{$t->[0]};
367 my $t2 = new Automake::Condition @{$t->[1]};
369 my ($ans, $cond) = $t1->ambiguous_p ("FOO", $t2);
370 if ($t3 && $ans !~ /FOO.*$t3/)
372 print " (A1) " . $t1->string . " vs. " . $t2->string . "\n\t"
373 . "Error message '$ans' does not match '$t3'\n";
376 if (!$t3 && $ans ne '')
378 print " (A2) " . $t1->string . " vs. " . $t2->string . "\n\t"
379 . "Unexpected error message: $ans\n";
389 || test_sub_conditions
392 ### Setup "GNU" style for perl-mode and cperl-mode.
394 ## perl-indent-level: 2
395 ## perl-continued-statement-offset: 2
396 ## perl-continued-brace-offset: 0
397 ## perl-brace-offset: 0
398 ## perl-brace-imaginary-offset: 0
399 ## perl-label-offset: -2
400 ## cperl-indent-level: 2
401 ## cperl-brace-offset: 0
402 ## cperl-continued-brace-offset: 0
403 ## cperl-label-offset: -2
404 ## cperl-extra-newline-before-brace: t
405 ## cperl-merge-trailing-else: nil
406 ## cperl-continued-statement-offset: 2