1 # Copyright (C) 2001, 2002, 2003, 2009 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/>.
18 use Automake::Condition qw/TRUE FALSE/;
22 my @tests = (# [[Conditions], is_true?, is_false?, string, subst-string, human]
23 [[], 1, 0, 'TRUE', '', 'TRUE'],
24 [['TRUE'], 1, 0, 'TRUE', '', 'TRUE'],
25 [['FALSE'], 0, 1, 'FALSE', '#', 'FALSE'],
26 [['A_TRUE'], 0, 0, 'A_TRUE', '@A_TRUE@', 'A'],
27 [['A_TRUE', 'B_FALSE'],
28 0, 0, 'A_TRUE B_FALSE', '@A_TRUE@@B_FALSE@', 'A and !B'],
29 [['B_TRUE', 'FALSE'], 0, 1, 'FALSE', '#', 'FALSE'],
30 [['B_TRUE', 'B_FALSE'], 0, 1, 'FALSE', '#', 'FALSE']);
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 return 1 if $_->[5] ne $a->human;
51 # [Implied-Conditions],
52 # [Not-Implied-Conditions]]
55 [['A_TRUE'], ['A_TRUE', 'B_FALSE'], ['FALSE']]],
57 [['TRUE'], ['A_TRUE']],
58 [['A_TRUE', 'B_FALSE'], ['FALSE']]],
59 [['A_TRUE', 'B_FALSE'],
60 [['TRUE'], ['A_TRUE'], ['B_FALSE'], ['A_TRUE', 'B_FALSE']],
61 [['FALSE'], ['C_FALSE'], ['C_FALSE', 'A_TRUE']]]);
65 my $a = new Automake::Condition @{$t->[0]};
66 for my $u (@{$t->[1]})
68 my $b = new Automake::Condition @$u;
69 if (! $b->true_when ($a))
71 print "`" . $b->string .
72 "' not implied by `" . $a->string . "'?\n";
76 for my $u (@{$t->[2]})
78 my $b = new Automake::Condition @$u;
79 if ($b->true_when ($a))
81 print "`" . $b->string .
82 "' implied by `" . $a->string . "'?\n";
86 return 1 if $b->true_when ($a);
92 sub test_reduce_and ()
94 my @tests = (# If no conditions are given, TRUE should be returned
96 # An empty condition is TRUE
98 # A single condition should be passed through unchanged
100 [["FALSE"], ["FALSE"]],
101 [["TRUE"], ["TRUE"]],
102 # TRUE and false should be discarded and overwhelm
103 # the result, respectively
104 [["FOO", "TRUE"], ["FOO"]],
105 [["FOO", "FALSE"], ["FALSE"]],
106 # Repetitions should be removed
107 [["FOO", "FOO"], ["FOO"]],
108 [["TRUE", "FOO", "FOO"], ["FOO"]],
109 [["FOO", "TRUE", "FOO"], ["FOO"]],
110 [["FOO", "FOO", "TRUE"], ["FOO"]],
111 # Two different conditions should be preserved,
112 # but TRUEs should be removed
113 [["FOO", "BAR"], ["BAR,FOO"]],
114 [["TRUE", "FOO", "BAR"], ["BAR,FOO"]],
115 [["FOO", "TRUE", "BAR"], ["BAR,FOO"]],
116 [["FOO", "BAR", "TRUE"], ["BAR,FOO"]],
117 # A condition implied by another condition should be removed.
118 [["FOO BAR", "BAR"], ["FOO BAR"]],
119 [["BAR", "FOO BAR"], ["FOO BAR"]],
120 [["TRUE", "FOO BAR", "BAR"], ["FOO BAR"]],
121 [["FOO BAR", "TRUE", "BAR"], ["FOO BAR"]],
122 [["FOO BAR", "BAR", "TRUE"], ["FOO BAR"]],
124 [["BAR FOO", "BAR"], ["BAR FOO"]],
125 [["BAR", "BAR FOO"], ["BAR FOO"]],
126 [["TRUE", "BAR FOO", "BAR"], ["BAR FOO"]],
127 [["BAR FOO", "TRUE", "BAR"], ["BAR FOO"]],
128 [["BAR FOO", "BAR", "TRUE"], ["BAR FOO"]],
130 # Check that reduction happens even when there are
131 # two conditions to remove.
132 [["FOO", "FOO BAR", "BAR"], ["FOO BAR"]],
133 [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["FOO BAR", "FOO BAZ"]],
134 [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
137 # Duplicated conditionals should be removed.
138 [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
140 # Equivalent conditions in different forms should be
141 # reduced: which one is left is unfortunately order
143 [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
144 [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
149 my ($inref, $outref) = @$_;
150 my @inconds = map { new Automake::Condition $_ } @$inref;
151 my @outconds = map { (new Automake::Condition $_)->string } @$outref;
153 map { $_->string } (Automake::Condition::reduce_and (@inconds));
154 my $result = join (",", sort @res);
155 my $exresult = join (",", @outconds);
157 if ($result ne $exresult)
159 print '"' . join(",", @$inref) . '" => "' .
160 $result . '" expected "' .
161 $exresult . '"' . "\n";
168 sub test_reduce_or ()
170 my @tests = (# If no conditions are given, FALSE should be returned
172 # An empty condition is TRUE
174 # A single condition should be passed through unchanged
176 [["FALSE"], ["FALSE"]],
177 [["TRUE"], ["TRUE"]],
178 # FALSE and TRUE should be discarded and overwhelm
179 # the result, respectively
180 [["FOO", "TRUE"], ["TRUE"]],
181 [["FOO", "FALSE"], ["FOO"]],
182 # Repetitions should be removed
183 [["FOO", "FOO"], ["FOO"]],
184 [["FALSE", "FOO", "FOO"], ["FOO"]],
185 [["FOO", "FALSE", "FOO"], ["FOO"]],
186 [["FOO", "FOO", "FALSE"], ["FOO"]],
187 # Two different conditions should be preserved,
188 # but FALSEs should be removed
189 [["FOO", "BAR"], ["BAR,FOO"]],
190 [["FALSE", "FOO", "BAR"], ["BAR,FOO"]],
191 [["FOO", "FALSE", "BAR"], ["BAR,FOO"]],
192 [["FOO", "BAR", "FALSE"], ["BAR,FOO"]],
193 # A condition implying another condition should be removed.
194 [["FOO BAR", "BAR"], ["BAR"]],
195 [["BAR", "FOO BAR"], ["BAR"]],
196 [["FALSE", "FOO BAR", "BAR"], ["BAR"]],
197 [["FOO BAR", "FALSE", "BAR"], ["BAR"]],
198 [["FOO BAR", "BAR", "FALSE"], ["BAR"]],
200 [["BAR FOO", "BAR"], ["BAR"]],
201 [["BAR", "BAR FOO"], ["BAR"]],
202 [["FALSE", "BAR FOO", "BAR"], ["BAR"]],
203 [["BAR FOO", "FALSE", "BAR"], ["BAR"]],
204 [["BAR FOO", "BAR", "FALSE"], ["BAR"]],
206 # Check that reduction happens even when there are
207 # two conditions to remove.
208 [["FOO", "FOO BAR", "BAR"], ["BAR,FOO"]],
209 [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["BAZ,FOO"]],
210 [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
213 # Duplicated conditionals should be removed.
214 [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
216 # Equivalent conditions in different forms should be
217 # reduced: which one is left is unfortunately order
219 [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
220 [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
225 my ($inref, $outref) = @$_;
226 my @inconds = map { new Automake::Condition $_ } @$inref;
227 my @outconds = map { (new Automake::Condition $_)->string } @$outref;
229 map { $_->string } (Automake::Condition::reduce_or (@inconds));
230 my $result = join (",", sort @res);
231 my $exresult = join (",", @outconds);
233 if ($result ne $exresult)
235 print '"' . join(",", @$inref) . '" => "' .
236 $result . '" expected "' .
237 $exresult . '"' . "\n";
246 my $cond = new Automake::Condition "COND1_TRUE", "COND2_FALSE";
247 my $other = new Automake::Condition "COND3_FALSE";
248 my $both = $cond->merge ($other);
249 my $both2 = $cond->merge_conds ("COND3_FALSE");
250 $cond = $both->strip ($other);
251 my @conds = $cond->conds;
252 return 1 if $both->string ne "COND1_TRUE COND2_FALSE COND3_FALSE";
253 return 1 if $cond->string ne "COND1_TRUE COND2_FALSE";
254 return 1 if $both != $both2;
264 ### Setup "GNU" style for perl-mode and cperl-mode.
266 ## perl-indent-level: 2
267 ## perl-continued-statement-offset: 2
268 ## perl-continued-brace-offset: 0
269 ## perl-brace-offset: 0
270 ## perl-brace-imaginary-offset: 0
271 ## perl-label-offset: -2
272 ## cperl-indent-level: 2
273 ## cperl-brace-offset: 0
274 ## cperl-continued-brace-offset: 0
275 ## cperl-label-offset: -2
276 ## cperl-extra-newline-before-brace: t
277 ## cperl-merge-trailing-else: nil
278 ## cperl-continued-statement-offset: 2