Merge branch 'maint'
[platform/upstream/automake.git] / t / parallel-tests-trailing-bslash.sh
1 #! /bin/sh
2 # Copyright (C) 2012 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 # Check that the new testsuite harness do not generate recipes that can
18 # have a trailing '\', since that can cause spurious syntax errors with
19 # older bash versions (e.g., bash 2.05b).
20 # See automake bug#10436.
21
22 . ./defs || exit 1
23
24 echo AC_OUTPUT >> configure.ac
25
26 cat > Makefile.am <<'END'
27 TESTS = foo.test
28 EXTRA_DIST = $(TESTS)
29 am__backslash = \\ # foo
30 .PHONY: bad-recipe
31 bad-recipe:
32         @printf '%s\n' $(am__backslash)
33 END
34
35 cat > foo.test <<'END'
36 #!/bin/sh
37 exit 0
38 END
39 chmod +x foo.test
40
41 am__SHELL=$SHELL; export am__SHELL
42 am__PERL=$PERL; export am__PERL
43
44 cat > my-shell <<'END'
45 #!/bin/sh -e
46 set -u
47 tab='   '
48 nl='
49 '
50 am__shell_flags=
51 am__shell_command=; unset am__shell_command
52 while test $# -gt 0; do
53   case $1 in
54     # If the shell is invoked by make e.g. as "sh -ec" (seen on
55     # GNU make in POSIX mode) or "sh -ce" (seen on Solaris make).
56     -*c*)
57         flg=`echo x"$1" | sed -e 's/^x-//' -e 's/c//g'`
58         if test x"$flg" != x; then
59           am__shell_flags="$am__shell_flags -$flg"
60         fi
61         am__shell_command=$2
62         shift
63         ;;
64     -?*)
65         am__shell_flags="$am__shell_flags $1"
66         ;;
67       *)
68         break
69         ;;
70   esac
71   shift
72 done
73 if test x${am__shell_command+"set"} != x"set"; then
74   # Some make implementations, like *BSD's, pass the recipes to the shell
75   # through its standard input.  Trying to run our extra checks in this
76   # case would be too tricky, so we just skip them.
77   exec $am__SHELL $am__shell_flags ${1+"$@"}
78 else
79   am__tweaked_shell_command=`printf '%s\n' "$am__shell_command" \
80     | tr -d " $tab$nl"`
81   case ${am__tweaked_shell_command-} in
82     *\\)
83       echo "my-shell: recipe ends with backslash character" >&2
84       printf '%s\n' "=== BEGIN recipe" >&2
85       printf '%s\n' "${am__shell_command-}" >&2
86       printf '%s\n' "=== END recipe" >&2
87       exit 99
88       ;;
89   esac
90   exec $am__SHELL $am__shell_flags -c "$am__shell_command" ${1+"$@"}
91 fi
92 END
93 chmod a+x my-shell
94
95 cat my-shell
96
97 CONFIG_SHELL=$(pwd)/my-shell; export CONFIG_SHELL
98
99 $ACLOCAL
100 $AUTOCONF
101 $AUTOMAKE -a
102
103 ./configure CONFIG_SHELL="$CONFIG_SHELL"
104
105 st=0
106 $MAKE bad-recipe 2>stderr && st=1
107 cat stderr >&2
108 $FGREP "my-shell: recipe ends with backslash character" stderr || st=1
109 test $st -eq 0 || skip_ "can't catch trailing backslashes in make recipes"
110
111 $MAKE check
112
113 :