1 # Copyright (C) 2001, 2002, 2003, 2008, 2009 Free Software Foundation,
4 # This file is part of GNU Automake.
6 # GNU Automake is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # GNU Automake is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 if (eval { require 5.007_002; } # for CLONE support
22 && $Config{useithreads}
23 && !$ENV{WANT_NO_THREADS})
33 use Automake::Condition qw/TRUE FALSE/;
37 my @tests = (# [[Conditions], is_true?, is_false?, string, subst-string, human]
38 [[], 1, 0, 'TRUE', '', 'TRUE'],
39 [['TRUE'], 1, 0, 'TRUE', '', 'TRUE'],
40 [['FALSE'], 0, 1, 'FALSE', '#', 'FALSE'],
41 [['A_TRUE'], 0, 0, 'A_TRUE', '@A_TRUE@', 'A'],
42 [['A_TRUE', 'B_FALSE'],
43 0, 0, 'A_TRUE B_FALSE', '@A_TRUE@@B_FALSE@', 'A and !B'],
44 [['B_TRUE', 'FALSE'], 0, 1, 'FALSE', '#', 'FALSE'],
45 [['B_TRUE', 'B_FALSE'], 0, 1, 'FALSE', '#', 'FALSE']);
49 my $a = new Automake::Condition @{$_->[0]};
52 return 1 if $_->[1] != $a->true;
53 return 1 if $_->[1] != ($a == TRUE);
54 return 1 if $_->[2] != $a->false;
55 return 1 if $_->[2] != ($a == FALSE);
56 return 1 if $_->[3] ne $a->string;
57 return 1 if $_->[4] ne $a->subst_string;
58 return 1 if $_->[5] ne $a->human;
69 # [Implied-Conditions],
70 # [Not-Implied-Conditions]]
73 [['A_TRUE'], ['A_TRUE', 'B_FALSE'], ['FALSE']]],
75 [['TRUE'], ['A_TRUE']],
76 [['A_TRUE', 'B_FALSE'], ['FALSE']]],
77 [['A_TRUE', 'B_FALSE'],
78 [['TRUE'], ['A_TRUE'], ['B_FALSE'], ['A_TRUE', 'B_FALSE']],
79 [['FALSE'], ['C_FALSE'], ['C_FALSE', 'A_TRUE']]]);
83 my $a = new Automake::Condition @{$t->[0]};
86 for my $u (@{$t->[1]})
88 my $b = new Automake::Condition @$u;
89 return threads->new(sub {
90 if (! $b->true_when ($a))
92 print "`" . $b->string .
93 "' not implied by `" . $a->string . "'?\n";
98 for my $u (@{$t->[2]})
100 my $b = new Automake::Condition @$u;
101 return threads->new(sub {
102 if ($b->true_when ($a))
104 print "`" . $b->string .
105 "' implied by `" . $a->string . "'?\n";
109 return threads->new(sub {
110 return 1 if $b->true_when ($a);
119 sub test_reduce_and ()
121 my @tests = (# If no conditions are given, TRUE should be returned
123 # An empty condition is TRUE
125 # A single condition should be passed through unchanged
127 [["FALSE"], ["FALSE"]],
128 [["TRUE"], ["TRUE"]],
129 # TRUE and false should be discarded and overwhelm
130 # the result, respectively
131 [["FOO", "TRUE"], ["FOO"]],
132 [["FOO", "FALSE"], ["FALSE"]],
133 # Repetitions should be removed
134 [["FOO", "FOO"], ["FOO"]],
135 [["TRUE", "FOO", "FOO"], ["FOO"]],
136 [["FOO", "TRUE", "FOO"], ["FOO"]],
137 [["FOO", "FOO", "TRUE"], ["FOO"]],
138 # Two different conditions should be preserved,
139 # but TRUEs should be removed
140 [["FOO", "BAR"], ["BAR,FOO"]],
141 [["TRUE", "FOO", "BAR"], ["BAR,FOO"]],
142 [["FOO", "TRUE", "BAR"], ["BAR,FOO"]],
143 [["FOO", "BAR", "TRUE"], ["BAR,FOO"]],
144 # A condition implied by another condition should be removed.
145 [["FOO BAR", "BAR"], ["FOO BAR"]],
146 [["BAR", "FOO BAR"], ["FOO BAR"]],
147 [["TRUE", "FOO BAR", "BAR"], ["FOO BAR"]],
148 [["FOO BAR", "TRUE", "BAR"], ["FOO BAR"]],
149 [["FOO BAR", "BAR", "TRUE"], ["FOO BAR"]],
151 [["BAR FOO", "BAR"], ["BAR FOO"]],
152 [["BAR", "BAR FOO"], ["BAR FOO"]],
153 [["TRUE", "BAR FOO", "BAR"], ["BAR FOO"]],
154 [["BAR FOO", "TRUE", "BAR"], ["BAR FOO"]],
155 [["BAR FOO", "BAR", "TRUE"], ["BAR FOO"]],
157 # Check that reduction happens even when there are
158 # two conditions to remove.
159 [["FOO", "FOO BAR", "BAR"], ["FOO BAR"]],
160 [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["FOO BAR", "FOO BAZ"]],
161 [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
164 # Duplicated conditionals should be removed.
165 [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
167 # Equivalent conditions in different forms should be
168 # reduced: which one is left is unfortunately order
170 [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
171 [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
176 my ($inref, $outref) = @$_;
177 my @inconds = map { new Automake::Condition $_ } @$inref;
179 if threads->new(sub {
180 my @outconds = map { (new Automake::Condition $_)->string } @$outref;
181 return threads->new(sub {
183 map { $_->string } (Automake::Condition::reduce_and (@inconds));
184 return threads->new(sub {
185 my $result = join (",", sort @res);
186 my $exresult = join (",", @outconds);
188 if ($result ne $exresult)
190 print '"' . join(",", @$inref) . '" => "' .
191 $result . '" expected "' .
192 $exresult . '"' . "\n";
203 sub test_reduce_or ()
205 my @tests = (# If no conditions are given, FALSE should be returned
207 # An empty condition is TRUE
209 # A single condition should be passed through unchanged
211 [["FALSE"], ["FALSE"]],
212 [["TRUE"], ["TRUE"]],
213 # FALSE and TRUE should be discarded and overwhelm
214 # the result, respectively
215 [["FOO", "TRUE"], ["TRUE"]],
216 [["FOO", "FALSE"], ["FOO"]],
217 # Repetitions should be removed
218 [["FOO", "FOO"], ["FOO"]],
219 [["FALSE", "FOO", "FOO"], ["FOO"]],
220 [["FOO", "FALSE", "FOO"], ["FOO"]],
221 [["FOO", "FOO", "FALSE"], ["FOO"]],
222 # Two different conditions should be preserved,
223 # but FALSEs should be removed
224 [["FOO", "BAR"], ["BAR,FOO"]],
225 [["FALSE", "FOO", "BAR"], ["BAR,FOO"]],
226 [["FOO", "FALSE", "BAR"], ["BAR,FOO"]],
227 [["FOO", "BAR", "FALSE"], ["BAR,FOO"]],
228 # A condition implying another condition should be removed.
229 [["FOO BAR", "BAR"], ["BAR"]],
230 [["BAR", "FOO BAR"], ["BAR"]],
231 [["FALSE", "FOO BAR", "BAR"], ["BAR"]],
232 [["FOO BAR", "FALSE", "BAR"], ["BAR"]],
233 [["FOO BAR", "BAR", "FALSE"], ["BAR"]],
235 [["BAR FOO", "BAR"], ["BAR"]],
236 [["BAR", "BAR FOO"], ["BAR"]],
237 [["FALSE", "BAR FOO", "BAR"], ["BAR"]],
238 [["BAR FOO", "FALSE", "BAR"], ["BAR"]],
239 [["BAR FOO", "BAR", "FALSE"], ["BAR"]],
241 # Check that reduction happens even when there are
242 # two conditions to remove.
243 [["FOO", "FOO BAR", "BAR"], ["BAR,FOO"]],
244 [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["BAZ,FOO"]],
245 [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
248 # Duplicated conditionals should be removed.
249 [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
251 # Equivalent conditions in different forms should be
252 # reduced: which one is left is unfortunately order
254 [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
255 [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
260 my ($inref, $outref) = @$_;
261 my @inconds = map { new Automake::Condition $_ } @$inref;
263 if threads->new(sub {
264 my @outconds = map { (new Automake::Condition $_)->string } @$outref;
265 return threads->new(sub {
267 map { $_->string } (Automake::Condition::reduce_or (@inconds));
268 return threads->new(sub {
269 my $result = join (",", sort @res);
270 my $exresult = join (",", @outconds);
272 if ($result ne $exresult)
274 print '"' . join(",", @$inref) . '" => "' .
275 $result . '" expected "' .
276 $exresult . '"' . "\n";
289 my $cond = new Automake::Condition "COND1_TRUE", "COND2_FALSE";
290 return threads->new(sub {
291 my $other = new Automake::Condition "COND3_FALSE";
292 return threads->new(sub {
293 my $both = $cond->merge ($other);
294 return threads->new(sub {
295 my $both2 = $cond->merge_conds ("COND3_FALSE");
296 return threads->new(sub {
297 $cond = $both->strip ($other);
298 my @conds = $cond->conds;
299 return 1 if $both->string ne "COND1_TRUE COND2_FALSE COND3_FALSE";
300 return 1 if $cond->string ne "COND1_TRUE COND2_FALSE";
301 return 1 if $both != $both2;
315 ### Setup "GNU" style for perl-mode and cperl-mode.
317 ## perl-indent-level: 2
318 ## perl-continued-statement-offset: 2
319 ## perl-continued-brace-offset: 0
320 ## perl-brace-offset: 0
321 ## perl-brace-imaginary-offset: 0
322 ## perl-label-offset: -2
323 ## cperl-indent-level: 2
324 ## cperl-brace-offset: 0
325 ## cperl-continued-brace-offset: 0
326 ## cperl-label-offset: -2
327 ## cperl-extra-newline-before-brace: t
328 ## cperl-merge-trailing-else: nil
329 ## cperl-continued-statement-offset: 2