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 autoconf; see the file COPYING. If not, write to
17 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
20 use Automake::Condition qw/TRUE FALSE/;
24 my @tests = (# [[Conditions], is_true?, is_false?, string, subst-string]
25 [[], 1, 0, 'TRUE', ''],
26 [['TRUE'], 1, 0, 'TRUE', ''],
27 [['FALSE'], 0, 1, 'FALSE', '#'],
28 [['A_TRUE'], 0, 0, 'A_TRUE', '@A_TRUE@'],
29 [['A_TRUE', 'B_FALSE'],
30 0, 0, 'A_TRUE B_FALSE', '@A_TRUE@@B_FALSE@'],
31 [['B_TRUE', 'FALSE'], 0, 1, 'FALSE', '#'],
32 [['B_TRUE', 'B_FALSE'], 0, 1, 'FALSE', '#']);
36 my $a = new Automake::Condition @{$_->[0]};
37 return 1 if $_->[1] != $a->true;
38 return 1 if $_->[1] != ($a == TRUE);
39 return 1 if $_->[2] != $a->false;
40 return 1 if $_->[2] != ($a == FALSE);
41 return 1 if $_->[3] ne $a->string;
42 return 1 if $_->[4] ne $a->subst_string;
52 # [Implied-Conditions],
53 # [Not-Implied-Conditions]]
56 [['A_TRUE'], ['A_TRUE', 'B_FALSE'], ['FALSE']]],
58 [['TRUE'], ['A_TRUE']],
59 [['A_TRUE', 'B_FALSE'], ['FALSE']]],
60 [['A_TRUE', 'B_FALSE'],
61 [['TRUE'], ['A_TRUE'], ['B_FALSE'], ['A_TRUE', 'B_FALSE']],
62 [['FALSE'], ['C_FALSE'], ['C_FALSE', 'A_TRUE']]]);
66 my $a = new Automake::Condition @{$t->[0]};
67 for my $u (@{$t->[1]})
69 my $b = new Automake::Condition @$u;
70 if (! $b->true_when ($a))
72 print "`" . $b->string .
73 "' not implied by `" . $a->string . "'?\n";
77 for my $u (@{$t->[2]})
79 my $b = new Automake::Condition @$u;
80 if ($b->true_when ($a))
82 print "`" . $b->string .
83 "' implied by `" . $a->string . "'?\n";
87 return 1 if $b->true_when ($a);
93 sub test_reduce_and ()
95 my @tests = (# If no conditions are given, TRUE should be returned
97 # An empty condition is TRUE
99 # A single condition should be passed through unchanged
101 [["FALSE"], ["FALSE"]],
102 [["TRUE"], ["TRUE"]],
103 # TRUE and false should be discarded and overwhelm
104 # the result, respectively
105 [["FOO", "TRUE"], ["FOO"]],
106 [["FOO", "FALSE"], ["FALSE"]],
107 # Repetitions should be removed
108 [["FOO", "FOO"], ["FOO"]],
109 [["TRUE", "FOO", "FOO"], ["FOO"]],
110 [["FOO", "TRUE", "FOO"], ["FOO"]],
111 [["FOO", "FOO", "TRUE"], ["FOO"]],
112 # Two different conditions should be preserved,
113 # but TRUEs should be removed
114 [["FOO", "BAR"], ["BAR,FOO"]],
115 [["TRUE", "FOO", "BAR"], ["BAR,FOO"]],
116 [["FOO", "TRUE", "BAR"], ["BAR,FOO"]],
117 [["FOO", "BAR", "TRUE"], ["BAR,FOO"]],
118 # A condition implied by another condition should be removed.
119 [["FOO BAR", "BAR"], ["FOO BAR"]],
120 [["BAR", "FOO BAR"], ["FOO BAR"]],
121 [["TRUE", "FOO BAR", "BAR"], ["FOO BAR"]],
122 [["FOO BAR", "TRUE", "BAR"], ["FOO BAR"]],
123 [["FOO BAR", "BAR", "TRUE"], ["FOO BAR"]],
125 [["BAR FOO", "BAR"], ["BAR FOO"]],
126 [["BAR", "BAR FOO"], ["BAR FOO"]],
127 [["TRUE", "BAR FOO", "BAR"], ["BAR FOO"]],
128 [["BAR FOO", "TRUE", "BAR"], ["BAR FOO"]],
129 [["BAR FOO", "BAR", "TRUE"], ["BAR FOO"]],
131 # Check that reduction happens even when there are
132 # two conditions to remove.
133 [["FOO", "FOO BAR", "BAR"], ["FOO BAR"]],
134 [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["FOO BAR", "FOO BAZ"]],
135 [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
138 # Duplicated conditionals should be removed.
139 [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
141 # Equivalent conditions in different forms should be
142 # reduced: which one is left is unfortunately order
144 [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
145 [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
150 my ($inref, $outref) = @$_;
151 my @inconds = map { new Automake::Condition $_ } @$inref;
152 my @outconds = map { (new Automake::Condition $_)->string } @$outref;
154 map { $_->string } (Automake::Condition::reduce_and (@inconds));
155 my $result = join (",", sort @res);
156 my $exresult = join (",", @outconds);
158 if ($result ne $exresult)
160 print '"' . join(",", @$inref) . '" => "' .
161 $result . '" expected "' .
162 $exresult . '"' . "\n";
169 sub test_reduce_or ()
171 my @tests = (# If no conditions are given, FALSE should be returned
173 # An empty condition is TRUE
175 # A single condition should be passed through unchanged
177 [["FALSE"], ["FALSE"]],
178 [["TRUE"], ["TRUE"]],
179 # FALSE and TRUE should be discarded and overwhelm
180 # the result, respectively
181 [["FOO", "TRUE"], ["TRUE"]],
182 [["FOO", "FALSE"], ["FOO"]],
183 # Repetitions should be removed
184 [["FOO", "FOO"], ["FOO"]],
185 [["FALSE", "FOO", "FOO"], ["FOO"]],
186 [["FOO", "FALSE", "FOO"], ["FOO"]],
187 [["FOO", "FOO", "FALSE"], ["FOO"]],
188 # Two different conditions should be preserved,
189 # but FALSEs should be removed
190 [["FOO", "BAR"], ["BAR,FOO"]],
191 [["FALSE", "FOO", "BAR"], ["BAR,FOO"]],
192 [["FOO", "FALSE", "BAR"], ["BAR,FOO"]],
193 [["FOO", "BAR", "FALSE"], ["BAR,FOO"]],
194 # A condition implying another condition should be removed.
195 [["FOO BAR", "BAR"], ["BAR"]],
196 [["BAR", "FOO BAR"], ["BAR"]],
197 [["FALSE", "FOO BAR", "BAR"], ["BAR"]],
198 [["FOO BAR", "FALSE", "BAR"], ["BAR"]],
199 [["FOO BAR", "BAR", "FALSE"], ["BAR"]],
201 [["BAR FOO", "BAR"], ["BAR"]],
202 [["BAR", "BAR FOO"], ["BAR"]],
203 [["FALSE", "BAR FOO", "BAR"], ["BAR"]],
204 [["BAR FOO", "FALSE", "BAR"], ["BAR"]],
205 [["BAR FOO", "BAR", "FALSE"], ["BAR"]],
207 # Check that reduction happens even when there are
208 # two conditions to remove.
209 [["FOO", "FOO BAR", "BAR"], ["BAR,FOO"]],
210 [["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["BAZ,FOO"]],
211 [["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"],
214 # Duplicated conditionals should be removed.
215 [["FOO", "BAR", "BAR"], ["BAR,FOO"]],
217 # Equivalent conditions in different forms should be
218 # reduced: which one is left is unfortunately order
220 [["BAR FOO", "FOO BAR"], ["FOO BAR"]],
221 [["FOO BAR", "BAR FOO"], ["BAR FOO"]]);
226 my ($inref, $outref) = @$_;
227 my @inconds = map { new Automake::Condition $_ } @$inref;
228 my @outconds = map { (new Automake::Condition $_)->string } @$outref;
230 map { $_->string } (Automake::Condition::reduce_or (@inconds));
231 my $result = join (",", sort @res);
232 my $exresult = join (",", @outconds);
234 if ($result ne $exresult)
236 print '"' . join(",", @$inref) . '" => "' .
237 $result . '" expected "' .
238 $exresult . '"' . "\n";
245 exit (test_basics || test_true_when || test_reduce_and || test_reduce_or);
247 ### Setup "GNU" style for perl-mode and cperl-mode.
249 ## perl-indent-level: 2
250 ## perl-continued-statement-offset: 2
251 ## perl-continued-brace-offset: 0
252 ## perl-brace-offset: 0
253 ## perl-brace-imaginary-offset: 0
254 ## perl-label-offset: -2
255 ## cperl-indent-level: 2
256 ## cperl-brace-offset: 0
257 ## cperl-continued-brace-offset: 0
258 ## cperl-label-offset: -2
259 ## cperl-extra-newline-before-brace: t
260 ## cperl-merge-trailing-else: nil
261 ## cperl-continued-statement-offset: 2