2 # Copyright (C) 2010-2012 Free Software Foundation, Inc.
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)
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.
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/>.
17 # Check that building from, or installing to, directories with shell
18 # metacharacters succeed.
19 # Original report from James Amundson about file names with spaces.
20 # Other characters added by Paul Eggert.
24 # Usage: is_in_list ITEM [LIST...]
29 *[\ \ ]"$item"[\ \ ]*) return 0;;
34 # Helper subroutine for test data definition.
35 # Usage: define_problematic_string NAME STRING
36 define_problematic_string ()
39 eval "instspc__$tst=\$1" \
40 || fatal_ "define_problematic_string: bad argument: '$tst'"
42 all_test_names_list="$all_test_names_list $tst"
43 # Some of the "problematic" characters cannot be used in the name of
44 # a build or install directory on a POSIX host. These lists should
45 # be empty, but are not due to limitations in Autoconf, Automake, Make,
47 if is_in_list fail-builddir "$@"; then
48 builddir_xfails="$builddir_xfails $tst"
50 if is_in_list fail-destdir "$@"; then
51 destdir_xfails="$destdir_xfails $tst"
55 # Be sure to avoid interferences from the environment.
56 all_test_names_list=''
63 build) is_in_list "$2" $builddir_xfails;;
64 dest) is_in_list "$2" $destdir_xfails;;
65 *) fatal_ "incorrect 'expected_to_fail' usage";;
69 # Helper subroutines for creation of input data files.
74 unindent >> configure.ac << 'EOF'
88 unindent > source.c << 'EOF'
90 main (int argc, char **argv)
96 unindent > Makefile.am << 'EOF'
97 foodir = $(prefix)/foo
98 fooexecdir = $(prefix)/foo
100 foo_HEADERS = sub/base.h
101 nobase_foo_HEADERS = sub/nobase.h
103 dist_foo_DATA = sub/base.dat
104 nobase_dist_foo_DATA = sub/nobase.dat
106 dist_fooexec_SCRIPTS = sub/base.sh
107 nobase_dist_fooexec_SCRIPTS = sub/nobase.sh
109 fooexec_PROGRAMS = sub/base
110 nobase_fooexec_PROGRAMS = sub/nobase
111 sub_base_SOURCES = source.c
112 sub_nobase_SOURCES = source.c
114 fooexec_LIBRARIES = sub/libbase.a
115 nobase_fooexec_LIBRARIES = sub/libnobase.a
116 sub_libbase_a_SOURCES = source.c
117 sub_libnobase_a_SOURCES = source.c
121 test -f '$(DESTDIR)/$(file)-prefix/foo/sub/nobase.h'
122 test ! -f '$(DESTDIR)/$(file)-prefix/foo/nobase.h'
123 test -f '$(DESTDIR)/$(file)-prefix/foo/base.h'
124 test -f '$(DESTDIR)/$(file)-prefix/foo/sub/nobase.dat'
125 test ! -f '$(DESTDIR)/$(file)-prefix/foo/nobase.dat'
126 test -f '$(DESTDIR)/$(file)-prefix/foo/base.dat'
127 test -f '$(DESTDIR)/$(file)-prefix/foo/sub/nobase.sh'
128 test ! -f '$(DESTDIR)/$(file)-prefix/foo/nobase.sh'
129 test -f '$(DESTDIR)/$(file)-prefix/foo/base.sh'
130 test -f '$(DESTDIR)/$(file)-prefix/foo/sub/nobase$(EXEEXT)'
131 test ! -f '$(DESTDIR)/$(file)-prefix/foo/nobase$(EXEEXT)'
132 test -f '$(DESTDIR)/$(file)-prefix/foo/base$(EXEEXT)'
133 test -f '$(DESTDIR)/$(file)-prefix/foo/sub/libnobase.a'
134 test ! -f '$(DESTDIR)/$(file)-prefix/foo/libnobase.a'
135 test -f '$(DESTDIR)/$(file)-prefix/foo/libbase.a'
138 $ACLOCAL || framework_failure_ "aclocal failed"
139 $AUTOCONF || framework_failure_ "autoconf failed"
140 $AUTOMAKE -a || framework_failure_ "automake failed"
143 # ================= #
145 # ----------------- #
147 # Some control characters that are white space.
149 cr='
\r' # carriage return
151 ht=' ' # horizontal tab
153 ' # line feed (aka newline)
155 # Hack to save typing and make code visually clearer.
156 def=define_problematic_string
158 $def squote \' fail-builddir fail-destdir
159 $def dquote '"' fail-builddir fail-destdir
160 $def bquote '`' fail-builddir fail-destdir
161 $def sharp '#' fail-builddir fail-destdir
162 $def dollar '$' fail-builddir fail-destdir
164 $def bslash '\' fail-builddir
165 $def ampersand '&' fail-builddir
189 $def linefeed "$lf" fail-builddir fail-destdir
192 $def carriageret "$cr"
193 $def quadrigraph0 '@&t@' fail-builddir
194 $def quadrigraph1 '@<:@'
195 $def quadrigraph2 '@:>@'
196 $def quadrigraph3 '@S|@'
197 $def quadrigraph4 '@%:@'
200 $def a_lf_b "a${lf}b" fail-builddir fail-destdir
203 $def miscglob1 '?[a-z]*'
204 $def miscglob2 '.*?[0-9]'
212 # Allow the user to select a subset of the tests.
213 if test $# -gt 0; then
215 for test_name in $test_names_list; do
216 case " $all_test_names_list " in
218 *) fatal_ "invalid user-specified test_name '$test_name'"
221 # We need to determine the TAP plan adaptively.
222 n=`for t in $test_names_list; do echo $t; done | wc -l`
223 plan_ `expr $n '*' 2` # Two tests per "problematic string".
226 test_names_list=$all_test_names_list
227 # Prefer static TAP plan if possible, it minimizes the chance of errors.
231 ocwd=`pwd` || fatal_ "cannot get current working directory"
235 for test_name in $test_names_list; do
237 eval "test_string=\${instspc__$test_name}" \
238 || fatal_ "invalid test name: '$test_name'"
240 if test x"$test_string" = x; then
241 if test x"$test_name" != xcarriageret; then
242 fatal_ "invalid test name: '$test_name'"
244 # MSYS version 1.0.17 still mishandles carriage returns; see
246 skip_ -r "carriage-return treated as null char" "$test_name in builddir"
247 skip_ -r "carriage-return treated as null char" "$test_name in destdir"
252 # Skip the next checks if this system doesn't support the required
253 # characters in file names.
255 mkdir "./$test_string" || {
256 skip_ -r "mkdir failed" "$test_name in builddir"
257 skip_ -r "mkdir failed" "$test_name in destdir"
263 # On MSYS 1.0.17, "mkdir ./a:" creates ./a, and "cd ./a:" takes you
264 # to a strange directory with pwd equal to "a". But only for
265 # interactive shells. Or something? In this script, "cd ./a:" fails
266 # on MSYS. Marvelous.
267 ( cd "./$test_string" ) || {
268 rmdir "./$test_string" || fatal_ "removing directory"
269 skip_ -r "cd failed" "$test_name in builddir"
270 skip_ -r "cd failed" "$test_name in destdir"
276 # Where are the "weird" characters going to be used, in $(builddir)
277 # or in $(DESTDIR)? They are always going to be used in $(prefix)
278 # though; should we maybe separate this into a dedicated check?
279 for where in build dest; do
284 dest=$ocwd/dest-$test_name
287 build=build-$test_name
288 dest=$ocwd/$test_string
289 mkdir "$build" || fatal_ "cannot create '$build'"
292 fatal_ "invalid where '$where'"
296 cd "$build" || fatal_ "cannot chdir into '$build'"
298 # Some make implementations eliminate leading and trailing whitespace
299 # from macros passed on the command line, and some eliminate leading
300 # whitespace from macros set from environment variables, so prepend
301 # './' and use the latter here.
303 ../configure --prefix "/$test_string-prefix" \
305 && DESTDIR="$dest" file="./$test_string" $MAKE -e test-inst \
308 description="$test_name in ${where}dir"
309 if expected_to_fail "$where" "$test_name"; then
311 reason="long-standing limitation"
316 # Test case outcome is here.
317 result_ "$r" -D "$directive" -r "$reason" -- "$description"
319 cd "$ocwd" || fatal_ "cannot chdir back to test directory"
321 # Remove subdirectories for tests that have passed, to avoid ending up
322 # with a too big test directory. This is especially important since
323 # some tests in this tests are expected to fail, and this will cause
324 # the test directory not to be removed when the script terminates.
325 if not am_keeping_testdirs && test "$r" = ok; then
326 rm_rf_ "$build" "$dest" || fatal_ "removing temporary subdirectory"
328 : For lesser shells with broken 'set -e'.
331 done # $instspc_action