Support more C++ file extensions for MSVC in the compile script.
[platform/upstream/automake.git] / lib / Automake / tests / DisjConditions-t.pl
1 # Copyright (C) 2001, 2002, 2003, 2008  Free Software Foundation, Inc.
2 #
3 # This file is part of GNU Automake.
4 #
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)
8 # any later version.
9 #
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.
14 #
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/>.
17
18 BEGIN {
19   use Config;
20   if (eval { require 5.007_002; }       # for CLONE support
21       && $Config{useithreads})
22     {
23       require threads;
24       import threads;
25     }
26   else
27     {
28       exit 77;
29     }
30 }
31 use Automake::Condition qw/TRUE FALSE/;
32 use Automake::DisjConditions;
33
34 sub test_basics ()
35 {
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;
48       })->join;
49     })->join;
50   })->join;
51 }
52
53 sub build_set (@)
54 {
55   my @conds = @_;
56   my @set = ();
57   for my $cond (@conds)
58     {
59       push @set, new Automake::Condition @$cond;
60     }
61   return new Automake::DisjConditions @set;
62 }
63
64 sub test_invert ()
65 {
66   my @tests = ([[["FALSE"]],
67                 [["TRUE"]]],
68
69                [[["TRUE"]],
70                 [["FALSE"]]],
71
72                [[["COND1_TRUE", "COND2_TRUE"],
73                  ["COND3_FALSE", "COND2_TRUE"]],
74                 [["COND2_FALSE"],
75                  ["COND1_FALSE", "COND3_TRUE"]]],
76
77                [[["COND1_TRUE", "COND2_TRUE"],
78                  ["TRUE"]],
79                 [["FALSE"]]],
80
81                [[["COND1_TRUE", "COND2_TRUE"],
82                  ["FALSE"]],
83                 [["COND1_FALSE"],
84                  ["COND2_FALSE"]]],
85
86                [[["COND1_TRUE"],
87                  ["COND2_FALSE"]],
88                 [["COND1_FALSE", "COND2_TRUE"]]]
89                );
90
91   for my $t (@tests)
92     {
93       my $set = build_set @{$t->[0]};
94       return 1
95         if threads->new(sub {
96           my $res = build_set @{$t->[1]};
97           my $inv = $set->invert;
98           if ($inv != $res)
99             {
100               print " (I) " . $set->string . "\n\t"
101                 . $inv->string . ' != ' . $res->string . "\n";
102               return 1;
103             }
104           return 0
105         })-> join;
106     }
107   return 0;
108 }
109
110 sub test_simplify ()
111 {
112   my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
113                  ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"]],
114                 [["FOO_TRUE", "BAR_FALSE"]]],
115
116                [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
117                  ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
118                  ["FOO_TRUE", "BAR_TRUE"]],
119                 [["FOO_TRUE"]]],
120
121                [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
122                  ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
123                  ["FOO_TRUE", "BAR_TRUE"],
124                  ["FOO_FALSE"]],
125                 [["TRUE"]]],
126
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"]]],
132
133                [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
134                  ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
135                              ["BAR_TRUE",  "BAZ_TRUE"],
136                              ["BAR_FALSE", "BAZ_TRUE"],
137                  ["FOO_FALSE"]],
138                 [["FOO_FALSE"], ["BAZ_TRUE"], ["BAR_FALSE"]]],
139
140                [[["B_TRUE"],
141                  ["A_FALSE", "B_TRUE"]],
142                 [["B_TRUE"]]],
143
144                [[["B_TRUE"],
145                  ["A_FALSE", "B_FALSE", "C_TRUE"],
146                  ["A_FALSE", "B_FALSE", "C_FALSE"]],
147                 [["A_FALSE"], ["B_TRUE"]]],
148
149                [[["B_TRUE"],
150                  ["A_FALSE", "B_FALSE", "C_TRUE"],
151                  ["A_FALSE", "B_FALSE", "C_FALSE"],
152                  ["A_TRUE", "B_FALSE"]],
153                 [["TRUE"]]],
154
155                [[["A_TRUE", "B_TRUE"],
156                  ["A_TRUE", "B_FALSE"],
157                  ["A_TRUE", "C_FALSE", "D_FALSE"]],
158                 [["A_TRUE"]]],
159
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"]]],
172
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"]]],
191
192                [[["A_FALSE"],
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"]],
199                 [["TRUE"]]],
200
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",
208                   "V31_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",
215                   "V31_FALSE"],
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",
222                   "V31_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",
229                   "V31_FALSE"]],
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"
236                   ]]]);
237
238   for my $t (@tests)
239     {
240       my $set = build_set @{$t->[0]};
241       return 1
242         if threads->new(sub {
243           my $res = build_set @{$t->[1]};
244           return threads->new(sub {
245
246             # Make sure simplify() yields the expected result.
247             my $sim = $set->simplify;
248             return threads->new(sub {
249               if ($sim != $res)
250                 {
251                   print " (S1) " . $set->string . "\n\t"
252                     . $sim->string . ' != ' . $res->string . "\n";
253                   return 1;
254                 }
255
256               # Make sure simplify() is idempotent.
257               my $sim2 = $sim->simplify;
258               return threads->new(sub {
259                 if ($sim2 != $sim)
260                   {
261                     print " (S2) " . $sim->string . "\n\t"
262                       . $sim2->string . ' != ' . $sim->string . "\n";
263                     return 1;
264                   }
265
266                 # Also exercise invert() while we are at it.
267
268                 my $inv1 = $set->invert->simplify;
269                 return threads->new(sub {
270                   my $inv2 = $sim->invert->simplify;
271                   return threads->new(sub {
272                     if ($inv1 != $inv2)
273                       {
274                         print " (S3) " . $set->string . ", " . $sim->string . "\n\t"
275                           . $inv1->string . ' -= ' . $inv2->string . "\n";
276                         return 1;
277                       }
278                   })->join;
279                 })->join;
280               })->join;
281             })->join;
282           })->join;
283         })->join;
284     }
285
286   return 0;
287 }
288
289 sub test_sub_conditions ()
290 {
291   my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
292                  ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
293                  ["FOO_FALSE"]],
294                 ["FOO_TRUE"],
295                 [["BAR_FALSE", "BAZ_FALSE"],
296                  ["BAR_FALSE", "BAZ_TRUE"]]],
297
298                [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
299                  ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
300                  ["FOO_FALSE"]],
301                 ["FOO_TRUE", "BAR_FALSE"],
302                 [["BAZ_FALSE"],
303                  ["BAZ_TRUE"]]],
304
305                [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
306                  ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
307                  ["FOO_FALSE"]],
308                 ["FOO_TRUE", "BAR_TRUE"],
309                 [["FALSE"]]],
310
311                [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
312                  ["FOO_TRUE", "BAZ_TRUE"],
313                  ["FOO_FALSE"]],
314                 ["FOO_TRUE", "BAR_TRUE"],
315                 [["BAZ_TRUE"]]],
316
317                [[["FOO_TRUE", "BAR_FALSE"],
318                  ["FOO_TRUE", "BAR_TRUE"]],
319                 ["FOO_TRUE", "BAR_TRUE"],
320                 [["TRUE"]]],
321
322                [[["TRUE"]],
323                 ["TRUE"],
324                 [["TRUE"]]],
325
326                [[["FALSE"]],
327                 ["TRUE"],
328                 [["FALSE"]]],
329
330                [[["FALSE"]],
331                 ["FALSE"],
332                 [["FALSE"]]]);
333
334   for my $t (@tests)
335     {
336       my $t1 = build_set @{$t->[0]};
337       return 1
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 {
343
344               # Make sure sub_conditions() yields the expected result.
345               my $s = $t1->sub_conditions ($t2);
346               threads->new(sub {
347                 if ($s != $t3)
348                   {
349                     print " (SC) " . $t1->string . "\n\t"
350                       . $s->string . ' != ' . $t3->string . "\n";
351                     return 1;
352                   }
353               })->join;
354             })->join;
355           })->join;
356         })->join;
357     }
358 }
359
360 sub test_ambig ()
361 {
362   my @tests = ([[["TRUE"]],
363                 ["TRUE"],
364                 "multiply defined"],
365                [[["C1_TRUE"]],
366                 ["C1_TRUE"],
367                 "multiply defined"],
368                [[["TRUE"]],
369                 ["C1_FALSE"],
370                 "which includes"],
371                [[["C1_TRUE"]],
372                 ["C1_TRUE", "C2_TRUE"],
373                 "which includes"],
374                [[["C1_TRUE", "C2_TRUE"]],
375                 ["C2_TRUE"],
376                 "which is included in"],
377                [[["C1_TRUE"]],
378                 ["C2_TRUE"],
379                 ''],
380                [[["C1_TRUE"],
381                  ["C2_FALSE"]],
382                 ["C1_FALSE", "C2_TRUE"],
383                 '']);
384
385   my $failed = 0;
386   for my $t (@tests)
387     {
388       my $t1 = build_set @{$t->[0]};
389       $failed = 1
390         if threads->new(sub {
391           my $t2 = new Automake::Condition @{$t->[1]};
392           my $t3 = $t->[2];
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/)
397                 {
398                   print " (A1) " . $t1->string . " vs. " . $t2->string . "\n\t"
399                     . "Error message '$ans' does not match '$t3'\n";
400                   return 1;
401                 }
402               if (!$t3 && $ans ne '')
403                 {
404                   print " (A2) " . $t1->string . " vs. " . $t2->string . "\n\t"
405                     . "Unexpected error message: $ans\n";
406                   return 1;
407                 }
408             })->join;
409           })->join;
410         })->join;
411     }
412   return $failed;
413 }
414
415 exit (test_basics
416       || test_invert
417       || test_simplify
418       || test_sub_conditions
419       || test_ambig);
420
421 ### Setup "GNU" style for perl-mode and cperl-mode.
422 ## Local Variables:
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
436 ## End: