1 # Copyright (C) 2001, 2002, 2003 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]
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', '#']);
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;
50 # [Implied-Conditions],
51 # [Not-Implied-Conditions]]
54 [['A_TRUE'], ['A_TRUE', 'B_FALSE'], ['FALSE']]],
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']]]);
64 my $a = new Automake
::Condition @
{$t->[0]};
65 for my $u (@
{$t->[1]})
67 my $b = new Automake
::Condition @
$u;
68 if (! $b->true_when ($a))
70 print "`" . $b->string .
71 "' not implied by `" . $a->string . "'?\n";
75 for my $u (@
{$t->[2]})
77 my $b = new Automake
::Condition @
$u;
78 if ($b->true_when ($a))
80 print "`" . $b->string .
81 "' implied by `" . $a->string . "'?\n";
85 return 1 if $b->true_when ($a);
91 sub test_reduce_and
()
93 my @tests = (# If no conditions are given, TRUE should be returned
95 # An empty condition is TRUE
97 # A single condition should be passed through unchanged
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"]],
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"]],
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"],
136 # Duplicated conditionals should be removed.
137 [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
139 # Equivalent conditions in different forms should be
140 # reduced: which one is left is unfortunately order
142 [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
143 [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
148 my ($inref, $outref) = @
$_;
149 my @inconds = map { new Automake
::Condition
$_ } @
$inref;
150 my @outconds = map { (new Automake
::Condition
$_)->string } @
$outref;
152 map { $_->string } (Automake
::Condition
::reduce_and
(@inconds));
153 my $result = join (",", sort @res);
154 my $exresult = join (",", @outconds);
156 if ($result ne $exresult)
158 print '"' . join(",", @
$inref) . '" => "' .
159 $result . '" expected "' .
160 $exresult . '"' . "\n";
167 sub test_reduce_or
()
169 my @tests = (# If no conditions are given, FALSE should be returned
171 # An empty condition is TRUE
173 # A single condition should be passed through unchanged
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"]],
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"]],
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"],
212 # Duplicated conditionals should be removed.
213 [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
215 # Equivalent conditions in different forms should be
216 # reduced: which one is left is unfortunately order
218 [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
219 [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
224 my ($inref, $outref) = @
$_;
225 my @inconds = map { new Automake
::Condition
$_ } @
$inref;
226 my @outconds = map { (new Automake
::Condition
$_)->string } @
$outref;
228 map { $_->string } (Automake
::Condition
::reduce_or
(@inconds));
229 my $result = join (",", sort @res);
230 my $exresult = join (",", @outconds);
232 if ($result ne $exresult)
234 print '"' . join(",", @
$inref) . '" => "' .
235 $result . '" expected "' .
236 $exresult . '"' . "\n";
243 exit (test_basics
|| test_true_when
|| test_reduce_and
|| test_reduce_or
);
245 ### Setup "GNU" style for perl-mode and cperl-mode.
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