1 # Copyright (C) 2001, 2002, 2003, 2008 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 2, 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 this program. If not, see <http://www.gnu.org/licenses/>.
20 if (eval { require 5.007_002
; } # for CLONE support
21 && $Config{useithreads
})
31 use Automake
::Condition qw
/TRUE FALSE/;
35 my @tests = (# [[Conditions], is_true?, is_false?, string, subst-string]
36 [[], 1, 0, 'TRUE', ''],
37 [['TRUE'], 1, 0, 'TRUE', ''],
38 [['FALSE'], 0, 1, 'FALSE', '#'],
39 [['A_TRUE'], 0, 0, 'A_TRUE', '@A_TRUE@'],
40 [['A_TRUE', 'B_FALSE'],
41 0, 0, 'A_TRUE B_FALSE', '@A_TRUE@@B_FALSE@'],
42 [['B_TRUE', 'FALSE'], 0, 1, 'FALSE', '#'],
43 [['B_TRUE', 'B_FALSE'], 0, 1, 'FALSE', '#']);
47 my $a = new Automake
::Condition @
{$_->[0]};
50 return 1 if $_->[1] != $a->true;
51 return 1 if $_->[1] != ($a == TRUE
);
52 return 1 if $_->[2] != $a->false;
53 return 1 if $_->[2] != ($a == FALSE
);
54 return 1 if $_->[3] ne $a->string;
55 return 1 if $_->[4] ne $a->subst_string;
66 # [Implied-Conditions],
67 # [Not-Implied-Conditions]]
70 [['A_TRUE'], ['A_TRUE', 'B_FALSE'], ['FALSE']]],
72 [['TRUE'], ['A_TRUE']],
73 [['A_TRUE', 'B_FALSE'], ['FALSE']]],
74 [['A_TRUE', 'B_FALSE'],
75 [['TRUE'], ['A_TRUE'], ['B_FALSE'], ['A_TRUE', 'B_FALSE']],
76 [['FALSE'], ['C_FALSE'], ['C_FALSE', 'A_TRUE']]]);
80 my $a = new Automake
::Condition @
{$t->[0]};
83 for my $u (@
{$t->[1]})
85 my $b = new Automake
::Condition @
$u;
86 return threads
->new(sub {
87 if (! $b->true_when ($a))
89 print "`" . $b->string .
90 "' not implied by `" . $a->string . "'?\n";
95 for my $u (@
{$t->[2]})
97 my $b = new Automake
::Condition @
$u;
98 return threads
->new(sub {
99 if ($b->true_when ($a))
101 print "`" . $b->string .
102 "' implied by `" . $a->string . "'?\n";
106 return threads
->new(sub {
107 return 1 if $b->true_when ($a);
116 sub test_reduce_and
()
118 my @tests = (# If no conditions are given, TRUE should be returned
120 # An empty condition is TRUE
122 # A single condition should be passed through unchanged
124 [["FALSE"], ["FALSE"]],
125 [["TRUE"], ["TRUE"]],
126 # TRUE and false should be discarded and overwhelm
127 # the result, respectively
128 [["FOO", "TRUE"], ["FOO"]],
129 [["FOO", "FALSE"], ["FALSE"]],
130 # Repetitions should be removed
131 [["FOO", "FOO"], ["FOO"]],
132 [["TRUE", "FOO", "FOO"], ["FOO"]],
133 [["FOO", "TRUE", "FOO"], ["FOO"]],
134 [["FOO", "FOO", "TRUE"], ["FOO"]],
135 # Two different conditions should be preserved,
136 # but TRUEs should be removed
137 [["FOO", "BAR"], ["BAR,FOO"]],
138 [["TRUE", "FOO", "BAR"], ["BAR,FOO"]],
139 [["FOO", "TRUE", "BAR"], ["BAR,FOO"]],
140 [["FOO", "BAR", "TRUE"], ["BAR,FOO"]],
141 # A condition implied by another condition should be removed.
142 [["FOO BAR", "BAR"], ["FOO BAR"]],
143 [["BAR", "FOO BAR"], ["FOO BAR"]],
144 [["TRUE", "FOO BAR", "BAR"], ["FOO BAR"]],
145 [["FOO BAR", "TRUE", "BAR"], ["FOO BAR"]],
146 [["FOO BAR", "BAR", "TRUE"], ["FOO BAR"]],
148 [["BAR FOO", "BAR"], ["BAR FOO"]],
149 [["BAR", "BAR FOO"], ["BAR FOO"]],
150 [["TRUE", "BAR FOO", "BAR"], ["BAR FOO"]],
151 [["BAR FOO", "TRUE", "BAR"], ["BAR FOO"]],
152 [["BAR FOO", "BAR", "TRUE"], ["BAR FOO"]],
154 # Check that reduction happens even when there are
155 # two conditions to remove.
156 [["FOO", "FOO BAR", "BAR"], ["FOO BAR"]],
157 [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["FOO BAR", "FOO BAZ"]],
158 [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
161 # Duplicated conditionals should be removed.
162 [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
164 # Equivalent conditions in different forms should be
165 # reduced: which one is left is unfortunately order
167 [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
168 [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
173 my ($inref, $outref) = @
$_;
174 my @inconds = map { new Automake
::Condition
$_ } @
$inref;
176 if threads
->new(sub {
177 my @outconds = map { (new Automake
::Condition
$_)->string } @
$outref;
178 return threads
->new(sub {
180 map { $_->string } (Automake
::Condition
::reduce_and
(@inconds));
181 return threads
->new(sub {
182 my $result = join (",", sort @res);
183 my $exresult = join (",", @outconds);
185 if ($result ne $exresult)
187 print '"' . join(",", @
$inref) . '" => "' .
188 $result . '" expected "' .
189 $exresult . '"' . "\n";
200 sub test_reduce_or
()
202 my @tests = (# If no conditions are given, FALSE should be returned
204 # An empty condition is TRUE
206 # A single condition should be passed through unchanged
208 [["FALSE"], ["FALSE"]],
209 [["TRUE"], ["TRUE"]],
210 # FALSE and TRUE should be discarded and overwhelm
211 # the result, respectively
212 [["FOO", "TRUE"], ["TRUE"]],
213 [["FOO", "FALSE"], ["FOO"]],
214 # Repetitions should be removed
215 [["FOO", "FOO"], ["FOO"]],
216 [["FALSE", "FOO", "FOO"], ["FOO"]],
217 [["FOO", "FALSE", "FOO"], ["FOO"]],
218 [["FOO", "FOO", "FALSE"], ["FOO"]],
219 # Two different conditions should be preserved,
220 # but FALSEs should be removed
221 [["FOO", "BAR"], ["BAR,FOO"]],
222 [["FALSE", "FOO", "BAR"], ["BAR,FOO"]],
223 [["FOO", "FALSE", "BAR"], ["BAR,FOO"]],
224 [["FOO", "BAR", "FALSE"], ["BAR,FOO"]],
225 # A condition implying another condition should be removed.
226 [["FOO BAR", "BAR"], ["BAR"]],
227 [["BAR", "FOO BAR"], ["BAR"]],
228 [["FALSE", "FOO BAR", "BAR"], ["BAR"]],
229 [["FOO BAR", "FALSE", "BAR"], ["BAR"]],
230 [["FOO BAR", "BAR", "FALSE"], ["BAR"]],
232 [["BAR FOO", "BAR"], ["BAR"]],
233 [["BAR", "BAR FOO"], ["BAR"]],
234 [["FALSE", "BAR FOO", "BAR"], ["BAR"]],
235 [["BAR FOO", "FALSE", "BAR"], ["BAR"]],
236 [["BAR FOO", "BAR", "FALSE"], ["BAR"]],
238 # Check that reduction happens even when there are
239 # two conditions to remove.
240 [["FOO", "FOO BAR", "BAR"], ["BAR,FOO"]],
241 [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["BAZ,FOO"]],
242 [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
245 # Duplicated conditionals should be removed.
246 [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
248 # Equivalent conditions in different forms should be
249 # reduced: which one is left is unfortunately order
251 [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
252 [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
257 my ($inref, $outref) = @
$_;
258 my @inconds = map { new Automake
::Condition
$_ } @
$inref;
260 if threads
->new(sub {
261 my @outconds = map { (new Automake
::Condition
$_)->string } @
$outref;
262 return threads
->new(sub {
264 map { $_->string } (Automake
::Condition
::reduce_or
(@inconds));
265 return threads
->new(sub {
266 my $result = join (",", sort @res);
267 my $exresult = join (",", @outconds);
269 if ($result ne $exresult)
271 print '"' . join(",", @
$inref) . '" => "' .
272 $result . '" expected "' .
273 $exresult . '"' . "\n";
284 exit (test_basics
|| test_true_when
|| test_reduce_and
|| test_reduce_or
);
286 ### Setup "GNU" style for perl-mode and cperl-mode.
288 ## perl-indent-level: 2
289 ## perl-continued-statement-offset: 2
290 ## perl-continued-brace-offset: 0
291 ## perl-brace-offset: 0
292 ## perl-brace-imaginary-offset: 0
293 ## perl-label-offset: -2
294 ## cperl-indent-level: 2
295 ## cperl-brace-offset: 0
296 ## cperl-continued-brace-offset: 0
297 ## cperl-label-offset: -2
298 ## cperl-extra-newline-before-brace: t
299 ## cperl-merge-trailing-else: nil
300 ## cperl-continued-statement-offset: 2