test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / subst-no-trailing-empty-line.sh
1 #! /bin/sh
2 # Copyright (C) 2003-2013 Free Software Foundation, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # If the last line of a automake-rewritten definition is made only of
18 # @substitutions@, automake should take care of appending an empty
19 # variable to make sure that line cannot end up substituted as a blank
20 # line (that would confuse HP-UX Make).
21 # These checks have been introduced in commit 'Release-1-9-254-g9d0eaef'
22 # into the former test 'subst2.test'.
23
24 . test-init.sh
25
26 # These are deliberately quite long, so that the xxx_PROGRAMS definition
27 # in Makefile.am below will be split on multiple lines, with the last
28 # line containing only @substituted@ stuff that expands to empty (this is
29 # required to expose the bug we are testing).
30 v1=ABCDEFGHIJKLMNOPQRSTUVWX
31 v2=ABCDEFGHIJKLMNOPQRSTUVWXY
32 v3=ABCDEFGHIJKLMNOPQRSTUVWXYZ
33
34 # Literal backslash for use by grep.
35 bs='\\'
36
37 cat >> configure.ac <<END
38 AC_SUBST([A], [''])
39 AC_SUBST([$v1], [''])
40 AC_SUBST([$v2], [''])
41 AC_SUBST([$v3], [''])
42 AC_OUTPUT
43 END
44
45 cat >Makefile.am <<END
46 AUTOMAKE_OPTIONS = no-dependencies
47 CC = false
48 EXEEXT =
49
50 ## The "x" and "zardoz" strings and the use of '+=' are there to ensure
51 ## that these variables get rewritten by Automake.
52 noinst_PROGRAMS = x @$v1@ @$v2@ @$v3@
53 bin_PROGRAMS = @A@
54 bin_PROGRAMS += @$v1@ @$v2@ @$v3@
55 check_PROGRAMS = zardoz \$(noinst_PROGRAMS)
56
57 ## Required whenever there are @substituted@ values in the
58 ## PROGRAMS primary, otherwise automake will complain.
59 EXTRA_PROGRAMS =
60
61 test-real-empty:
62         is \$(noinst_PROGRAMS) == x
63         is \$(bin_PROGRAMS)    ==
64         is \$(check_PROGRAMS)  == zardoz x
65
66 test-fake-empty:
67         is \$(noinst_PROGRAMS) == x X
68         is \$(bin_PROGRAMS)    == X
69         is \$(check_PROGRAMS)  == zardoz x X
70 END
71
72 $ACLOCAL
73 $AUTOCONF
74 $AUTOMAKE
75 # For debugging.
76 $EGREP -n 'ABCD|am__empty' Makefile.in
77 # Sanity check.
78 test $($EGREP -c "^[ $tab]*@$v2@ @$v3@[ $tab]*$bs?$" Makefile.in) -eq 3
79
80 ./configure
81 {
82   sed -n '/^noinst_PROGRAMS *=/,/[^\\]$/p' Makefile
83   sed -n '/^bin_PROGRAMS *=/,/[^\\]$/p' Makefile
84   sed -n '/^check_PROGRAMS *=/,/[^\\]$/p' Makefile
85   sed -n '/^am__EXEEXT.*=/,/[^\\]$/p' Makefile
86 } >t-programs
87 cat t-programs
88 grep '^ *$' t-programs && exit 1
89
90 run_make test-real-empty
91 run_make test-fake-empty am__empty=X
92
93 :