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