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 autoconf; see the file COPYING. If not, write to
17 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301, USA.
20 use Automake::Condition qw/TRUE FALSE/;
21 use Automake::DisjConditions;
25 my $cond = new Automake::Condition "COND1_TRUE", "COND2_FALSE";
26 my $other = new Automake::Condition "COND3_FALSE";
27 my $set1 = new Automake::DisjConditions $cond, $other;
28 my $set2 = new Automake::DisjConditions $other, $cond;
29 return 1 unless $set1 == $set2;
30 return 1 if $set1->false;
31 return 1 if $set1->true;
32 return 1 unless (new Automake::DisjConditions)->false;
33 return 1 if (new Automake::DisjConditions)->true;
42 push @set, new Automake::Condition @$cond;
44 return new Automake::DisjConditions @set;
49 my @tests = ([[["FALSE"]],
55 [[["COND1_TRUE", "COND2_TRUE"],
56 ["COND3_FALSE", "COND2_TRUE"]],
58 ["COND1_FALSE", "COND3_TRUE"]]],
60 [[["COND1_TRUE", "COND2_TRUE"],
64 [[["COND1_TRUE", "COND2_TRUE"],
71 [["COND1_FALSE", "COND2_TRUE"]]]
76 my $set = build_set @{$t->[0]};
77 my $res = build_set @{$t->[1]};
78 my $inv = $set->invert;
81 print " (I) " . $set->string . "\n\t"
82 . $inv->string . ' != ' . $res->string . "\n";
91 my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
92 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"]],
93 [["FOO_TRUE", "BAR_FALSE"]]],
95 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
96 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
97 ["FOO_TRUE", "BAR_TRUE"]],
100 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
101 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
102 ["FOO_TRUE", "BAR_TRUE"],
106 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
107 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
108 ["BAR_TRUE", "BAZ_TRUE"],
109 ["BAR_FALSE", "BAZ_TRUE"]],
110 [["BAZ_TRUE"], ["FOO_TRUE", "BAR_FALSE"]]],
112 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
113 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
114 ["BAR_TRUE", "BAZ_TRUE"],
115 ["BAR_FALSE", "BAZ_TRUE"],
117 [["FOO_FALSE"], ["BAZ_TRUE"], ["BAR_FALSE"]]],
120 ["A_FALSE", "B_TRUE"]],
124 ["A_FALSE", "B_FALSE", "C_TRUE"],
125 ["A_FALSE", "B_FALSE", "C_FALSE"]],
126 [["A_FALSE"], ["B_TRUE"]]],
129 ["A_FALSE", "B_FALSE", "C_TRUE"],
130 ["A_FALSE", "B_FALSE", "C_FALSE"],
131 ["A_TRUE", "B_FALSE"]],
134 [[["A_TRUE", "B_TRUE"],
135 ["A_TRUE", "B_FALSE"],
136 ["A_TRUE", "C_FALSE", "D_FALSE"]],
139 [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
140 ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
141 ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
142 ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
143 ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
144 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
145 ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
146 ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"]],
147 [ ["B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
148 ["B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
149 ["B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
150 ["B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"]]],
152 [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
153 ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
154 ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
155 ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
156 ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
157 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
158 ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
159 ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
160 ["A_FALSE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"],
161 ["A_FALSE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
162 ["A_FALSE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
163 ["A_FALSE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
164 ["A_TRUE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
165 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
166 ["A_TRUE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
167 ["A_TRUE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"]],
168 [["C_FALSE", "E_FALSE"],
169 ["C_TRUE", "E_TRUE"]]],
172 ["A_TRUE", "B_FALSE"],
173 ["A_TRUE", "B_TRUE", "C_FALSE"],
174 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE"],
175 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_FALSE"],
176 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE", "F_FALSE"],
177 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"]],
180 # Simplify should work with up to 31 variables.
181 [[["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
182 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
183 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
184 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
185 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
186 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
188 ["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
189 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
190 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
191 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
192 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
193 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
195 ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
196 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
197 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
198 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
199 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
200 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
202 ["V01_FALSE","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 [[ "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"
219 my $set = build_set @{$t->[0]};
220 my $res = build_set @{$t->[1]};
222 # Make sure simplify() yields the expected result.
223 my $sim = $set->simplify;
226 print " (S1) " . $set->string . "\n\t"
227 . $sim->string . ' != ' . $res->string . "\n";
231 # Make sure simplify() is idempotent.
232 my $sim2 = $sim->simplify;
235 print " (S2) " . $sim->string . "\n\t"
236 . $sim2->string . ' != ' . $sim->string . "\n";
240 # Also exercize invert() while we are at it.
242 my $inv1 = $set->invert->simplify;
243 my $inv2 = $sim->invert->simplify;
246 print " (S3) " . $set->string . ", " . $sim->string . "\n\t"
247 . $inv1->string . ' != ' . $inv2->string . "\n";
255 sub test_sub_conditions ()
257 my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
258 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
261 [["BAR_FALSE", "BAZ_FALSE"],
262 ["BAR_FALSE", "BAZ_TRUE"]]],
264 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
265 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
267 ["FOO_TRUE", "BAR_FALSE"],
271 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
272 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
274 ["FOO_TRUE", "BAR_TRUE"],
277 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
278 ["FOO_TRUE", "BAZ_TRUE"],
280 ["FOO_TRUE", "BAR_TRUE"],
283 [[["FOO_TRUE", "BAR_FALSE"],
284 ["FOO_TRUE", "BAR_TRUE"]],
285 ["FOO_TRUE", "BAR_TRUE"],
302 my $t1 = build_set @{$t->[0]};
303 my $t2 = new Automake::Condition @{$t->[1]};
304 my $t3 = build_set @{$t->[2]};
306 # Make sure sub_conditions() yields the expected result.
307 my $s = $t1->sub_conditions ($t2);
310 print " (SC) " . $t1->string . "\n\t"
311 . $s->string . ' != ' . $t3->string . "\n";
319 my @tests = ([[["TRUE"]],
329 ["C1_TRUE", "C2_TRUE"],
331 [[["C1_TRUE", "C2_TRUE"]],
333 "which is included in"],
339 ["C1_FALSE", "C2_TRUE"],
344 my $t1 = build_set @{$t->[0]};
345 my $t2 = new Automake::Condition @{$t->[1]};
347 my ($ans, $cond) = $t1->ambiguous_p ("FOO", $t2);
348 if ($t3 && $ans !~ /FOO.*$t3/)
350 print " (A1) " . $t1->string . " vs. " . $t2->string . "\n\t"
351 . "Error message '$ans' does not match '$t3'\n";
354 if (!$t3 && $ans ne '')
356 print " (A2) " . $t1->string . " vs. " . $t2->string . "\n\t"
357 . "Unexpected error message: $ans\n";
367 || test_sub_conditions
370 ### Setup "GNU" style for perl-mode and cperl-mode.
372 ## perl-indent-level: 2
373 ## perl-continued-statement-offset: 2
374 ## perl-continued-brace-offset: 0
375 ## perl-brace-offset: 0
376 ## perl-brace-imaginary-offset: 0
377 ## perl-label-offset: -2
378 ## cperl-indent-level: 2
379 ## cperl-brace-offset: 0
380 ## cperl-continued-brace-offset: 0
381 ## cperl-label-offset: -2
382 ## cperl-extra-newline-before-brace: t
383 ## cperl-merge-trailing-else: nil
384 ## cperl-continued-statement-offset: 2