Reword the copyright notices to match what's suggested in GPLv3.
[automake/plouj.git] / lib / Automake / tests / DisjConditions.pl
blob8ce6b7b2f3ae5c62ff0d54615d030fdaa95db9b4
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)
8 # any later version.
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;
21 sub test_basics ()
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;
34 sub build_set (@)
36 my @conds = @_;
37 my @set = ();
38 for my $cond (@conds)
40 push @set, new Automake::Condition @$cond;
42 return new Automake::DisjConditions @set;
45 sub test_invert ()
47 my @tests = ([[["FALSE"]],
48 [["TRUE"]]],
50 [[["TRUE"]],
51 [["FALSE"]]],
53 [[["COND1_TRUE", "COND2_TRUE"],
54 ["COND3_FALSE", "COND2_TRUE"]],
55 [["COND2_FALSE"],
56 ["COND1_FALSE", "COND3_TRUE"]]],
58 [[["COND1_TRUE", "COND2_TRUE"],
59 ["TRUE"]],
60 [["FALSE"]]],
62 [[["COND1_TRUE", "COND2_TRUE"],
63 ["FALSE"]],
64 [["COND1_FALSE"],
65 ["COND2_FALSE"]]],
67 [[["COND1_TRUE"],
68 ["COND2_FALSE"]],
69 [["COND1_FALSE", "COND2_TRUE"]]]
72 for my $t (@tests)
74 my $set = build_set @{$t->[0]};
75 my $res = build_set @{$t->[1]};
76 my $inv = $set->invert;
77 if ($inv != $res)
79 print " (I) " . $set->string . "\n\t"
80 . $inv->string . ' != ' . $res->string . "\n";
81 return 1;
84 return 0;
87 sub test_simplify ()
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"]],
96 [["FOO_TRUE"]]],
98 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
99 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
100 ["FOO_TRUE", "BAR_TRUE"],
101 ["FOO_FALSE"]],
102 [["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"],
114 ["FOO_FALSE"]],
115 [["FOO_FALSE"], ["BAZ_TRUE"], ["BAR_FALSE"]]],
117 [[["B_TRUE"],
118 ["A_FALSE", "B_TRUE"]],
119 [["B_TRUE"]]],
121 [[["B_TRUE"],
122 ["A_FALSE", "B_FALSE", "C_TRUE"],
123 ["A_FALSE", "B_FALSE", "C_FALSE"]],
124 [["A_FALSE"], ["B_TRUE"]]],
126 [[["B_TRUE"],
127 ["A_FALSE", "B_FALSE", "C_TRUE"],
128 ["A_FALSE", "B_FALSE", "C_FALSE"],
129 ["A_TRUE", "B_FALSE"]],
130 [["TRUE"]]],
132 [[["A_TRUE", "B_TRUE"],
133 ["A_TRUE", "B_FALSE"],
134 ["A_TRUE", "C_FALSE", "D_FALSE"]],
135 [["A_TRUE"]]],
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"]]],
169 [[["A_FALSE"],
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"]],
176 [["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",
185 "V31_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",
192 "V31_FALSE"],
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",
199 "V31_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",
206 "V31_FALSE"]],
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"
213 ]]]);
215 for my $t (@tests)
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;
222 if ($sim != $res)
224 print " (S1) " . $set->string . "\n\t"
225 . $sim->string . ' != ' . $res->string . "\n";
226 return 1;
229 # Make sure simplify() is idempotent.
230 my $sim2 = $sim->simplify;
231 if ($sim2 != $sim)
233 print " (S2) " . $sim->string . "\n\t"
234 . $sim2->string . ' != ' . $sim->string . "\n";
235 return 1;
238 # Also exercize invert() while we are at it.
240 my $inv1 = $set->invert->simplify;
241 my $inv2 = $sim->invert->simplify;
242 if ($inv1 != $inv2)
244 print " (S3) " . $set->string . ", " . $sim->string . "\n\t"
245 . $inv1->string . ' != ' . $inv2->string . "\n";
246 return 1;
250 return 0;
253 sub test_sub_conditions ()
255 my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
256 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
257 ["FOO_FALSE"]],
258 ["FOO_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"],
264 ["FOO_FALSE"]],
265 ["FOO_TRUE", "BAR_FALSE"],
266 [["BAZ_FALSE"],
267 ["BAZ_TRUE"]]],
269 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
270 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
271 ["FOO_FALSE"]],
272 ["FOO_TRUE", "BAR_TRUE"],
273 [["FALSE"]]],
275 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
276 ["FOO_TRUE", "BAZ_TRUE"],
277 ["FOO_FALSE"]],
278 ["FOO_TRUE", "BAR_TRUE"],
279 [["BAZ_TRUE"]]],
281 [[["FOO_TRUE", "BAR_FALSE"],
282 ["FOO_TRUE", "BAR_TRUE"]],
283 ["FOO_TRUE", "BAR_TRUE"],
284 [["TRUE"]]],
286 [[["TRUE"]],
287 ["TRUE"],
288 [["TRUE"]]],
290 [[["FALSE"]],
291 ["TRUE"],
292 [["FALSE"]]],
294 [[["FALSE"]],
295 ["FALSE"],
296 [["FALSE"]]]);
298 for my $t (@tests)
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);
306 if ($s != $t3)
308 print " (SC) " . $t1->string . "\n\t"
309 . $s->string . ' != ' . $t3->string . "\n";
310 return 1;
315 sub test_ambig ()
317 my @tests = ([[["TRUE"]],
318 ["TRUE"],
319 "multiply defined"],
320 [[["C1_TRUE"]],
321 ["C1_TRUE"],
322 "multiply defined"],
323 [[["TRUE"]],
324 ["C1_FALSE"],
325 "which includes"],
326 [[["C1_TRUE"]],
327 ["C1_TRUE", "C2_TRUE"],
328 "which includes"],
329 [[["C1_TRUE", "C2_TRUE"]],
330 ["C2_TRUE"],
331 "which is included in"],
332 [[["C1_TRUE"]],
333 ["C2_TRUE"],
334 ''],
335 [[["C1_TRUE"],
336 ["C2_FALSE"]],
337 ["C1_FALSE", "C2_TRUE"],
338 '']);
340 for my $t (@tests)
342 my $t1 = build_set @{$t->[0]};
343 my $t2 = new Automake::Condition @{$t->[1]};
344 my $t3 = $t->[2];
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";
350 return 1;
352 if (!$t3 && $ans ne '')
354 print " (A2) " . $t1->string . " vs. " . $t2->string . "\n\t"
355 . "Unexpected error message: $ans\n";
356 return 1;
359 return 0;
362 exit (test_basics
363 || test_invert
364 || test_simplify
365 || test_sub_conditions
366 || test_ambig);
368 ### Setup "GNU" style for perl-mode and cperl-mode.
369 ## Local Variables:
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
383 ## End: