1 | #! /bin/sh
|
---|
2 | # Copyright (C) 2001, 2002 Free Software Foundation, Inc.
|
---|
3 | #
|
---|
4 | # This file is part of GNU Automake.
|
---|
5 | #
|
---|
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)
|
---|
9 | # any later version.
|
---|
10 | #
|
---|
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.
|
---|
15 | #
|
---|
16 | # You should have received a copy of the GNU General Public License
|
---|
17 | # along with autoconf; see the file COPYING. If not, write to
|
---|
18 | # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
---|
19 | # Boston, MA 02111-1307, USA.
|
---|
20 |
|
---|
21 | # Test behavior of variable_conditions_reduce()
|
---|
22 | # This checks the result of variable_conditions_reduce() for a wide variety
|
---|
23 | # of cases.
|
---|
24 |
|
---|
25 | . ./defs || exit 1
|
---|
26 |
|
---|
27 | # FIXME: probably ought to let use override this like we do in `defs'.
|
---|
28 | amfile=../../automake
|
---|
29 |
|
---|
30 | sed 1q $amfile >>automake_tmp
|
---|
31 | cat << 'END' >> automake_tmp
|
---|
32 | my $failed = 0;
|
---|
33 | sub check_reduce($$) {
|
---|
34 | my ($inref, $outref) = @_;
|
---|
35 | my @result = sort &Automake::variable_conditions_reduce(@$inref);
|
---|
36 | my $correct = 1;
|
---|
37 | $correct = 0 if (join(",", @result) ne join(",", @$outref));
|
---|
38 |
|
---|
39 | if (! $correct) {
|
---|
40 | print '"'.join(",", @$inref) . '" => "' .
|
---|
41 | join(",", @result) . '" expected "' .
|
---|
42 | join(",", @$outref) . '"' . "\n";
|
---|
43 | $failed = 1;
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | # If no conditions are given, TRUE should be returned
|
---|
48 | check_reduce([""], ["TRUE"]);
|
---|
49 | # A single condition should be passed through unchanged
|
---|
50 | check_reduce(["FOO"], ["FOO"]);
|
---|
51 | check_reduce(["FALSE"], ["FALSE"]);
|
---|
52 | check_reduce(["TRUE"], ["TRUE"]);
|
---|
53 |
|
---|
54 | # TRUE and false should be discarded and overwhelm the result, respectively
|
---|
55 | check_reduce(["FOO", "TRUE"], ["FOO"]);
|
---|
56 | check_reduce(["FOO", "FALSE"], ["FALSE"]);
|
---|
57 |
|
---|
58 | # Repetitions should be removed
|
---|
59 | check_reduce(["FOO", "FOO"], ["FOO"]);
|
---|
60 | check_reduce(["TRUE", "FOO", "FOO"], ["FOO"]);
|
---|
61 | check_reduce(["FOO", "TRUE", "FOO"], ["FOO"]);
|
---|
62 | check_reduce(["FOO", "FOO", "TRUE"], ["FOO"]);
|
---|
63 |
|
---|
64 | # Two different conditions should be preserved, but TRUEs should be removed
|
---|
65 | check_reduce(["FOO", "BAR"], ["BAR,FOO"]);
|
---|
66 | check_reduce(["TRUE", "FOO", "BAR"], ["BAR,FOO"]);
|
---|
67 | check_reduce(["FOO", "TRUE", "BAR"], ["BAR,FOO"]);
|
---|
68 | check_reduce(["FOO", "BAR", "TRUE"], ["BAR,FOO"]);
|
---|
69 |
|
---|
70 | # A condition implied by another condition should be removed.
|
---|
71 | check_reduce(["FOO BAR", "BAR"], ["FOO BAR"]);
|
---|
72 | check_reduce(["BAR", "FOO BAR"], ["FOO BAR"]);
|
---|
73 | check_reduce(["TRUE", "FOO BAR", "BAR"], ["FOO BAR"]);
|
---|
74 | check_reduce(["FOO BAR", "TRUE", "BAR"], ["FOO BAR"]);
|
---|
75 | check_reduce(["FOO BAR", "BAR", "TRUE"], ["FOO BAR"]);
|
---|
76 |
|
---|
77 | check_reduce(["BAR FOO", "BAR"], ["BAR FOO"]);
|
---|
78 | check_reduce(["BAR", "BAR FOO"], ["BAR FOO"]);
|
---|
79 | check_reduce(["TRUE", "BAR FOO", "BAR"], ["BAR FOO"]);
|
---|
80 | check_reduce(["BAR FOO", "TRUE", "BAR"], ["BAR FOO"]);
|
---|
81 | check_reduce(["BAR FOO", "BAR", "TRUE"], ["BAR FOO"]);
|
---|
82 |
|
---|
83 | # Check that reduction happens even when there are two conditionals to remove.
|
---|
84 | check_reduce(["FOO", "FOO BAR", "BAR"], ["FOO BAR"]);
|
---|
85 | check_reduce(["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["FOO BAR", "FOO BAZ"]);
|
---|
86 | check_reduce(["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"], ["FOO BAZ BAR"]);
|
---|
87 |
|
---|
88 | # Duplicated conditionals should be removed.
|
---|
89 | check_reduce(["FOO", "BAR", "BAR"], ["BAR,FOO"]);
|
---|
90 |
|
---|
91 | # Equivalent conditionals in different forms should be reduced: which one is
|
---|
92 | # left is unfortunately order dependent.
|
---|
93 | check_reduce(["BAR FOO", "FOO BAR"], ["FOO BAR"]);
|
---|
94 | check_reduce(["FOO BAR", "BAR FOO"], ["BAR FOO"]);
|
---|
95 |
|
---|
96 | exit $failed;
|
---|
97 | END
|
---|
98 | cat $amfile >>automake_tmp
|
---|
99 | chmod +x automake_tmp
|
---|
100 |
|
---|
101 | ./automake_tmp
|
---|