1 # Copyright (C) 2001, 2002, 2003 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 3, 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/>.
18 use Automake
::Condition qw
/TRUE FALSE/;
19 use Automake
::DisjConditions
;
23 my $cond = new Automake
::Condition
"COND1_TRUE", "COND2_FALSE";
24 my $other = new Automake
::Condition
"COND3_FALSE";
25 my $set1 = new Automake
::DisjConditions
$cond, $other;
26 my $set2 = new Automake
::DisjConditions
$other, $cond;
27 return 1 unless $set1 == $set2;
28 return 1 if $set1->false;
29 return 1 if $set1->true;
30 return 1 unless (new Automake
::DisjConditions
)->false;
31 return 1 if (new Automake
::DisjConditions
)->true;
40 push @set, new Automake
::Condition @
$cond;
42 return new Automake
::DisjConditions
@set;
47 my @tests = ([[["FALSE"]],
53 [[["COND1_TRUE", "COND2_TRUE"],
54 ["COND3_FALSE", "COND2_TRUE"]],
56 ["COND1_FALSE", "COND3_TRUE"]]],
58 [[["COND1_TRUE", "COND2_TRUE"],
62 [[["COND1_TRUE", "COND2_TRUE"],
69 [["COND1_FALSE", "COND2_TRUE"]]]
74 my $set = build_set @
{$t->[0]};
75 my $res = build_set @
{$t->[1]};
76 my $inv = $set->invert;
79 print " (I) " . $set->string . "\n\t"
80 . $inv->string . ' != ' . $res->string . "\n";
89 my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
90 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"]],
91 [["FOO_TRUE", "BAR_FALSE"]]],
93 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
94 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
95 ["FOO_TRUE", "BAR_TRUE"]],
98 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
99 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
100 ["FOO_TRUE", "BAR_TRUE"],
104 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
105 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
106 ["BAR_TRUE", "BAZ_TRUE"],
107 ["BAR_FALSE", "BAZ_TRUE"]],
108 [["BAZ_TRUE"], ["FOO_TRUE", "BAR_FALSE"]]],
110 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
111 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
112 ["BAR_TRUE", "BAZ_TRUE"],
113 ["BAR_FALSE", "BAZ_TRUE"],
115 [["FOO_FALSE"], ["BAZ_TRUE"], ["BAR_FALSE"]]],
118 ["A_FALSE", "B_TRUE"]],
122 ["A_FALSE", "B_FALSE", "C_TRUE"],
123 ["A_FALSE", "B_FALSE", "C_FALSE"]],
124 [["A_FALSE"], ["B_TRUE"]]],
127 ["A_FALSE", "B_FALSE", "C_TRUE"],
128 ["A_FALSE", "B_FALSE", "C_FALSE"],
129 ["A_TRUE", "B_FALSE"]],
132 [[["A_TRUE", "B_TRUE"],
133 ["A_TRUE", "B_FALSE"],
134 ["A_TRUE", "C_FALSE", "D_FALSE"]],
137 [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
138 ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
139 ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
140 ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
141 ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
142 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
143 ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
144 ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"]],
145 [ ["B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
146 ["B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
147 ["B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
148 ["B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"]]],
150 [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
151 ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
152 ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
153 ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
154 ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
155 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
156 ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
157 ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
158 ["A_FALSE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"],
159 ["A_FALSE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
160 ["A_FALSE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
161 ["A_FALSE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
162 ["A_TRUE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
163 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
164 ["A_TRUE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
165 ["A_TRUE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"]],
166 [["C_FALSE", "E_FALSE"],
167 ["C_TRUE", "E_TRUE"]]],
170 ["A_TRUE", "B_FALSE"],
171 ["A_TRUE", "B_TRUE", "C_FALSE"],
172 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE"],
173 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_FALSE"],
174 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE", "F_FALSE"],
175 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"]],
178 # Simplify should work with up to 31 variables.
179 [[["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
180 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
181 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
182 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
183 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
184 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
186 ["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
187 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
188 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
189 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
190 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
191 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
193 ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
194 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
195 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
196 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
197 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
198 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
200 ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
201 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
202 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
203 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
204 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
205 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
207 [[ "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
208 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
209 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
210 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
211 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
212 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE"
217 my $set = build_set @
{$t->[0]};
218 my $res = build_set @
{$t->[1]};
220 # Make sure simplify() yields the expected result.
221 my $sim = $set->simplify;
224 print " (S1) " . $set->string . "\n\t"
225 . $sim->string . ' != ' . $res->string . "\n";
229 # Make sure simplify() is idempotent.
230 my $sim2 = $sim->simplify;
233 print " (S2) " . $sim->string . "\n\t"
234 . $sim2->string . ' != ' . $sim->string . "\n";
238 # Also exercize invert() while we are at it.
240 my $inv1 = $set->invert->simplify;
241 my $inv2 = $sim->invert->simplify;
244 print " (S3) " . $set->string . ", " . $sim->string . "\n\t"
245 . $inv1->string . ' != ' . $inv2->string . "\n";
253 sub test_sub_conditions
()
255 my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
256 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
259 [["BAR_FALSE", "BAZ_FALSE"],
260 ["BAR_FALSE", "BAZ_TRUE"]]],
262 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
263 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
265 ["FOO_TRUE", "BAR_FALSE"],
269 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
270 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
272 ["FOO_TRUE", "BAR_TRUE"],
275 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
276 ["FOO_TRUE", "BAZ_TRUE"],
278 ["FOO_TRUE", "BAR_TRUE"],
281 [[["FOO_TRUE", "BAR_FALSE"],
282 ["FOO_TRUE", "BAR_TRUE"]],
283 ["FOO_TRUE", "BAR_TRUE"],
300 my $t1 = build_set @
{$t->[0]};
301 my $t2 = new Automake
::Condition @
{$t->[1]};
302 my $t3 = build_set @
{$t->[2]};
304 # Make sure sub_conditions() yields the expected result.
305 my $s = $t1->sub_conditions ($t2);
308 print " (SC) " . $t1->string . "\n\t"
309 . $s->string . ' != ' . $t3->string . "\n";
317 my @tests = ([[["TRUE"]],
327 ["C1_TRUE", "C2_TRUE"],
329 [[["C1_TRUE", "C2_TRUE"]],
331 "which is included in"],
337 ["C1_FALSE", "C2_TRUE"],
342 my $t1 = build_set @
{$t->[0]};
343 my $t2 = new Automake
::Condition @
{$t->[1]};
345 my ($ans, $cond) = $t1->ambiguous_p ("FOO", $t2);
346 if ($t3 && $ans !~ /FOO.*$t3/)
348 print " (A1) " . $t1->string . " vs. " . $t2->string . "\n\t"
349 . "Error message '$ans' does not match '$t3'\n";
352 if (!$t3 && $ans ne '')
354 print " (A2) " . $t1->string . " vs. " . $t2->string . "\n\t"
355 . "Unexpected error message: $ans\n";
365 || test_sub_conditions
368 ### Setup "GNU" style for perl-mode and cperl-mode.
370 ## perl-indent-level: 2
371 ## perl-continued-statement-offset: 2
372 ## perl-continued-brace-offset: 0
373 ## perl-brace-offset: 0
374 ## perl-brace-imaginary-offset: 0
375 ## perl-label-offset: -2
376 ## cperl-indent-level: 2
377 ## cperl-brace-offset: 0
378 ## cperl-continued-brace-offset: 0
379 ## cperl-label-offset: -2
380 ## cperl-extra-newline-before-brace: t
381 ## cperl-merge-trailing-else: nil
382 ## cperl-continued-statement-offset: 2