Support more C++ file extensions for MSVC in the compile script.
[platform/upstream/automake.git] / lib / Automake / tests / Condition.pl
1 # Copyright (C) 2001, 2002, 2003  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 use Automake::Condition qw/TRUE FALSE/;
19
20 sub test_basics ()
21 {
22   my @tests = (# [[Conditions], is_true?, is_false?, string, subst-string]
23                [[], 1, 0, 'TRUE', ''],
24                [['TRUE'], 1, 0, 'TRUE', ''],
25                [['FALSE'], 0, 1, 'FALSE', '#'],
26                [['A_TRUE'], 0, 0, 'A_TRUE', '@A_TRUE@'],
27                [['A_TRUE', 'B_FALSE'],
28                 0, 0, 'A_TRUE B_FALSE', '@A_TRUE@@B_FALSE@'],
29                [['B_TRUE', 'FALSE'], 0, 1, 'FALSE', '#'],
30                [['B_TRUE', 'B_FALSE'], 0, 1, 'FALSE', '#']);
31
32   for (@tests)
33     {
34       my $a = new Automake::Condition @{$_->[0]};
35       return 1 if $_->[1] != $a->true;
36       return 1 if $_->[1] != ($a == TRUE);
37       return 1 if $_->[2] != $a->false;
38       return 1 if $_->[2] != ($a == FALSE);
39       return 1 if $_->[3] ne $a->string;
40       return 1 if $_->[4] ne $a->subst_string;
41     }
42   return 0;
43 }
44
45 sub test_true_when ()
46 {
47   my $failed = 0;
48
49   my @tests = (# [When,
50                #  [Implied-Conditions],
51                #  [Not-Implied-Conditions]]
52                [['TRUE'],
53                 [['TRUE']],
54                 [['A_TRUE'], ['A_TRUE', 'B_FALSE'], ['FALSE']]],
55                [['A_TRUE'],
56                 [['TRUE'], ['A_TRUE']],
57                 [['A_TRUE', 'B_FALSE'], ['FALSE']]],
58                [['A_TRUE', 'B_FALSE'],
59                 [['TRUE'], ['A_TRUE'], ['B_FALSE'], ['A_TRUE', 'B_FALSE']],
60                 [['FALSE'], ['C_FALSE'], ['C_FALSE', 'A_TRUE']]]);
61
62   for my $t (@tests)
63     {
64       my $a = new Automake::Condition @{$t->[0]};
65       for my $u (@{$t->[1]})
66         {
67           my $b = new Automake::Condition @$u;
68           if (! $b->true_when ($a))
69             {
70               print "`" . $b->string .
71                 "' not implied by `" . $a->string . "'?\n";
72               $failed = 1;
73             }
74         }
75       for my $u (@{$t->[2]})
76         {
77           my $b = new Automake::Condition @$u;
78           if ($b->true_when ($a))
79             {
80               print "`" . $b->string .
81                 "' implied by `" . $a->string . "'?\n";
82               $failed = 1;
83             }
84
85           return 1 if $b->true_when ($a);
86         }
87     }
88   return $failed;
89 }
90
91 sub test_reduce_and ()
92 {
93   my @tests = (# If no conditions are given, TRUE should be returned
94                [[], ["TRUE"]],
95                # An empty condition is TRUE
96                [[""], ["TRUE"]],
97                # A single condition should be passed through unchanged
98                [["FOO"], ["FOO"]],
99                [["FALSE"], ["FALSE"]],
100                [["TRUE"], ["TRUE"]],
101                # TRUE and false should be discarded and overwhelm
102                # the result, respectively
103                [["FOO", "TRUE"], ["FOO"]],
104                [["FOO", "FALSE"], ["FALSE"]],
105                # Repetitions should be removed
106                [["FOO", "FOO"], ["FOO"]],
107                [["TRUE", "FOO", "FOO"], ["FOO"]],
108                [["FOO", "TRUE", "FOO"], ["FOO"]],
109                [["FOO", "FOO", "TRUE"], ["FOO"]],
110                # Two different conditions should be preserved,
111                # but TRUEs should be removed
112                [["FOO", "BAR"], ["BAR,FOO"]],
113                [["TRUE", "FOO", "BAR"], ["BAR,FOO"]],
114                [["FOO", "TRUE", "BAR"], ["BAR,FOO"]],
115                [["FOO", "BAR", "TRUE"], ["BAR,FOO"]],
116                # A condition implied by another condition should be removed.
117                [["FOO BAR", "BAR"], ["FOO BAR"]],
118                [["BAR", "FOO BAR"], ["FOO BAR"]],
119                [["TRUE", "FOO BAR", "BAR"], ["FOO BAR"]],
120                [["FOO BAR", "TRUE", "BAR"], ["FOO BAR"]],
121                [["FOO BAR", "BAR", "TRUE"], ["FOO BAR"]],
122
123                [["BAR FOO", "BAR"], ["BAR FOO"]],
124                [["BAR", "BAR FOO"], ["BAR FOO"]],
125                [["TRUE", "BAR FOO", "BAR"], ["BAR FOO"]],
126                [["BAR FOO", "TRUE", "BAR"], ["BAR FOO"]],
127                [["BAR FOO", "BAR", "TRUE"], ["BAR FOO"]],
128
129                # Check that reduction happens even when there are
130                # two conditions to remove.
131                [["FOO", "FOO BAR", "BAR"], ["FOO BAR"]],
132                [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["FOO BAR", "FOO BAZ"]],
133                [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
134                 ["FOO BAZ BAR"]],
135
136                # Duplicated conditionals should be removed.
137                [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
138
139                # Equivalent conditions in different forms should be
140                # reduced: which one is left is unfortunately order
141                # dependent.
142                [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
143                [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
144
145   my $failed = 0;
146   foreach (@tests)
147     {
148       my ($inref, $outref) = @$_;
149       my @inconds = map { new Automake::Condition $_ } @$inref;
150       my @outconds = map { (new Automake::Condition $_)->string } @$outref;
151       my @res =
152         map { $_->string } (Automake::Condition::reduce_and (@inconds));
153       my $result = join (",", sort @res);
154       my $exresult = join (",", @outconds);
155
156       if ($result ne $exresult)
157         {
158           print '"' . join(",", @$inref) . '" => "' .
159             $result . '" expected "' .
160               $exresult . '"' . "\n";
161           $failed = 1;
162         }
163     }
164   return $failed;
165 }
166
167 sub test_reduce_or ()
168 {
169   my @tests = (# If no conditions are given, FALSE should be returned
170                [[], ["FALSE"]],
171                # An empty condition is TRUE
172                [[""], ["TRUE"]],
173                # A single condition should be passed through unchanged
174                [["FOO"], ["FOO"]],
175                [["FALSE"], ["FALSE"]],
176                [["TRUE"], ["TRUE"]],
177                # FALSE and TRUE should be discarded and overwhelm
178                # the result, respectively
179                [["FOO", "TRUE"], ["TRUE"]],
180                [["FOO", "FALSE"], ["FOO"]],
181                # Repetitions should be removed
182                [["FOO", "FOO"], ["FOO"]],
183                [["FALSE", "FOO", "FOO"], ["FOO"]],
184                [["FOO", "FALSE", "FOO"], ["FOO"]],
185                [["FOO", "FOO", "FALSE"], ["FOO"]],
186                # Two different conditions should be preserved,
187                # but FALSEs should be removed
188                [["FOO", "BAR"], ["BAR,FOO"]],
189                [["FALSE", "FOO", "BAR"], ["BAR,FOO"]],
190                [["FOO", "FALSE", "BAR"], ["BAR,FOO"]],
191                [["FOO", "BAR", "FALSE"], ["BAR,FOO"]],
192                # A condition implying another condition should be removed.
193                [["FOO BAR", "BAR"], ["BAR"]],
194                [["BAR", "FOO BAR"], ["BAR"]],
195                [["FALSE", "FOO BAR", "BAR"], ["BAR"]],
196                [["FOO BAR", "FALSE", "BAR"], ["BAR"]],
197                [["FOO BAR", "BAR", "FALSE"], ["BAR"]],
198
199                [["BAR FOO", "BAR"], ["BAR"]],
200                [["BAR", "BAR FOO"], ["BAR"]],
201                [["FALSE", "BAR FOO", "BAR"], ["BAR"]],
202                [["BAR FOO", "FALSE", "BAR"], ["BAR"]],
203                [["BAR FOO", "BAR", "FALSE"], ["BAR"]],
204
205                # Check that reduction happens even when there are
206                # two conditions to remove.
207                [["FOO", "FOO BAR", "BAR"], ["BAR,FOO"]],
208                [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["BAZ,FOO"]],
209                [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
210                 ["BAZ,FOO"]],
211
212                # Duplicated conditionals should be removed.
213                [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
214
215                # Equivalent conditions in different forms should be
216                # reduced: which one is left is unfortunately order
217                # dependent.
218                [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
219                [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
220
221   my $failed = 0;
222   foreach (@tests)
223     {
224       my ($inref, $outref) = @$_;
225       my @inconds = map { new Automake::Condition $_ } @$inref;
226       my @outconds = map { (new Automake::Condition $_)->string } @$outref;
227       my @res =
228         map { $_->string } (Automake::Condition::reduce_or (@inconds));
229       my $result = join (",", sort @res);
230       my $exresult = join (",", @outconds);
231
232       if ($result ne $exresult)
233         {
234           print '"' . join(",", @$inref) . '" => "' .
235             $result . '" expected "' .
236               $exresult . '"' . "\n";
237           $failed = 1;
238         }
239     }
240   return $failed;
241 }
242
243 exit (test_basics || test_true_when || test_reduce_and || test_reduce_or);
244
245 ### Setup "GNU" style for perl-mode and cperl-mode.
246 ## Local Variables:
247 ## perl-indent-level: 2
248 ## perl-continued-statement-offset: 2
249 ## perl-continued-brace-offset: 0
250 ## perl-brace-offset: 0
251 ## perl-brace-imaginary-offset: 0
252 ## perl-label-offset: -2
253 ## cperl-indent-level: 2
254 ## cperl-brace-offset: 0
255 ## cperl-continued-brace-offset: 0
256 ## cperl-label-offset: -2
257 ## cperl-extra-newline-before-brace: t
258 ## cperl-merge-trailing-else: nil
259 ## cperl-continued-statement-offset: 2
260 ## End: