tests: cosmetic changes in t/extra-sources.sh
[platform/upstream/automake.git] / t / instspc.tap
1 #! /bin/sh
2 # Copyright (C) 2010-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 # 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.
21
22 . test-init.sh
23
24 # Usage: is_in_list ITEM [LIST...]
25 is_in_list ()
26 {
27   item=$1; shift;
28   case " $* " in
29     *[\ \       ]"$item"[\ \    ]*) return 0;;
30     *) return 1;;
31   esac
32 }
33
34 # Helper subroutine for test data definition.
35 # Usage: define_problematic_string NAME STRING
36 define_problematic_string ()
37 {
38   tst=$1; shift
39   eval "instspc__$tst=\$1" \
40     || fatal_ "define_problematic_string: bad argument: '$tst'"
41   shift
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,
46   # M4, or the shell.
47   if is_in_list fail-builddir "$@"; then
48     builddir_xfails="$builddir_xfails $tst"
49   fi
50   if is_in_list fail-destdir "$@"; then
51     destdir_xfails="$destdir_xfails $tst"
52   fi
53 }
54
55 # Be sure to avoid interferences from the environment.
56 all_test_names_list=''
57 builddir_xfails=''
58 destdir_xfails=''
59
60 expected_to_fail ()
61 {
62    case $1 in
63      build) is_in_list "$2" $builddir_xfails;;
64       dest) is_in_list "$2" $destdir_xfails;;
65          *) fatal_ "incorrect 'expected_to_fail' usage";;
66    esac
67 }
68
69 # Helper subroutines for creation of input data files.
70 create_input_data ()
71 {
72   mkdir sub
73
74   unindent >> configure.ac << 'EOF'
75     AC_PROG_CC
76     AM_PROG_AR
77     AC_PROG_RANLIB
78     AC_OUTPUT
79 EOF
80
81   : > sub/base.h
82   : > sub/nobase.h
83   : > sub/base.dat
84   : > sub/nobase.dat
85   : > sub/base.sh
86   : > sub/nobase.sh
87
88   unindent > source.c << 'EOF'
89     int
90     main (int argc, char **argv)
91     {
92       return 0;
93     }
94 EOF
95
96   unindent > Makefile.am << 'EOF'
97     foodir = $(prefix)/foo
98     fooexecdir = $(prefix)/foo
99
100     foo_HEADERS = sub/base.h
101     nobase_foo_HEADERS = sub/nobase.h
102
103     dist_foo_DATA = sub/base.dat
104     nobase_dist_foo_DATA = sub/nobase.dat
105
106     dist_fooexec_SCRIPTS = sub/base.sh
107     nobase_dist_fooexec_SCRIPTS = sub/nobase.sh
108
109     fooexec_PROGRAMS = sub/base
110     nobase_fooexec_PROGRAMS = sub/nobase
111     sub_base_SOURCES = source.c
112     sub_nobase_SOURCES = source.c
113
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
118
119     .PHONY: test-inst
120     test-inst: install
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'
136 EOF
137
138   $ACLOCAL     || framework_failure_ "aclocal failed"
139   $AUTOCONF    || framework_failure_ "autoconf failed"
140   $AUTOMAKE -a || framework_failure_ "automake failed"
141 }
142
143 # ================= #
144 #  Test data begin  #
145 # ----------------- #
146
147 # Some control characters that are white space.
148 bs='\b'   # back space
149 cr='\r'   # carriage return
150 ff='\f'   # form feed
151 ht='    ' # horizontal tab
152 lf='
153 '         # line feed (aka newline)
154
155 # Hack to save typing and make code visually clearer.
156 def=define_problematic_string
157
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
163 $def    bang            '!'
164 $def    bslash          '\'         fail-builddir
165 $def    ampersand       '&'         fail-builddir
166 $def    percent         '%'
167 $def    leftpar         '('
168 $def    rightpar        ')'
169 $def    pipe            '|'
170 $def    caret           '^'
171 $def    tilde           '~'
172 $def    qmark           '?'
173 $def    star            '*'
174 $def    plus            '+'
175 $def    minus           '-'
176 $def    comma           ','
177 $def    colon           ':'
178 $def    semicol         ';'
179 $def    equal           '='
180 $def    less            '<'
181 $def    more            '>'
182 $def    at              '@'
183 $def    lqbrack         '['
184 $def    rqbrack         ']'
185 $def    lcbrack         '{'
186 $def    rcbrack         '}'
187 $def    space           ' '
188 $def    tab             "$ht"
189 $def    linefeed        "$lf"       fail-builddir  fail-destdir
190 $def    backspace       "$bs"
191 $def    formfeed        "$ff"
192 $def    carriageret     "$cr"
193 $def    quadrigraph0    '@&t@'      fail-builddir
194 $def    quadrigraph1    '@<:@'
195 $def    quadrigraph2    '@:>@'
196 $def    quadrigraph3    '@S|@'
197 $def    quadrigraph4    '@%:@'
198 $def    a_b             'a b'
199 $def    a__b            'a  b'
200 $def    a_lf_b          "a${lf}b"   fail-builddir  fail-destdir
201 $def    dotdotdot       '...'
202 $def    dosdrive        'a:'
203 $def    miscglob1       '?[a-z]*'
204 $def    miscglob2       '.*?[0-9]'
205
206 unset def
207
208 # --------------- #
209 #  Test data end  #
210 # =============== #
211
212 # Allow the user to select a subset of the tests.
213 if test $# -gt 0; then
214   test_names_list=$*
215   for test_name in $test_names_list; do
216     case " $all_test_names_list " in
217       *" $test_name "*);;
218       *) fatal_ "invalid user-specified test_name '$test_name'"
219     esac
220   done
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_ $(($n * 2)) # Two tests per "problematic string".
224   unset n
225 else
226   test_names_list=$all_test_names_list
227   # Prefer static TAP plan if possible, it minimizes the chance of errors.
228   plan_ 94
229 fi
230
231 ocwd=$(pwd) || fatal_ "getting current working directory"
232
233 create_input_data
234
235 for test_name in $test_names_list; do
236
237   eval "test_string=\${instspc__$test_name}" \
238     || fatal_ "invalid test name: '$test_name'"
239
240   if test x"$test_string" = x; then
241     if test x"$test_name" != xcarriageret; then
242       fatal_ "invalid test name: '$test_name'"
243     else
244       # MSYS version 1.0.17 still mishandles carriage returns; see
245       # automake bug#7849.
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"
248       continue
249     fi
250   fi
251
252   # Skip the next checks if this system doesn't support the required
253   # characters in file names.
254
255   mkdir "./$test_string" || {
256     skip_ -r "mkdir failed" "$test_name in builddir"
257     skip_ -r "mkdir failed" "$test_name in destdir"
258     continue
259   }
260
261   case $test_string in
262   *:*)
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"
271       continue
272     }
273     ;;
274   esac
275
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
280
281     case $where in
282       build)
283         build=./$test_string
284         dest=$ocwd/dest-$test_name
285         ;;
286       dest)
287         build=build-$test_name
288         # Also use $test_name in the definition of $dest, to avoid
289         # interferences among different tests in case $test_string
290         # is strangely munged (which is not unexpected, considering
291         # how tricky its characters are).  With some shells, this
292         # has already happened (at least on OpenIndiana 11 and on
293         # Solaris 10).
294         dest=$ocwd/dest-$test_name/$test_string
295         mkdir "$build" || fatal_ "cannot create '$build'"
296         ;;
297       *)
298         fatal_ "invalid where '$where'"
299         ;;
300     esac
301
302     cd "$build" || fatal_ "cannot chdir into '$build'"
303
304     # Some make implementations eliminate leading and trailing whitespace
305     # from macros passed on the command line, and some eliminate leading
306     # whitespace from macros set from environment variables, so prepend
307     # './' and use the latter here.
308     r=ok
309     ../configure --prefix "/$test_string-prefix" \
310       && $MAKE all \
311       && DESTDIR="$dest" file="./$test_string" $MAKE test-inst \
312       || r='not ok'
313
314     description="$test_name in ${where}dir"
315     if expected_to_fail "$where" "$test_name"; then
316       directive=TODO
317       reason="long-standing limitation"
318     else
319       directive=
320       reason=
321     fi
322     # Test case outcome is here.
323     result_ "$r" -D "$directive" -r "$reason" -- "$description"
324
325     cd "$ocwd" || fatal_ "cannot chdir back to test directory"
326
327     # Remove subdirectories for tests that have passed, to avoid ending up
328     # with a too big test directory.  This is especially important since
329     # some tests in this tests are expected to fail, and this will cause
330     # the test directory not to be removed when the script terminates.
331     if not am_keeping_testdirs && test "$r" = ok; then
332       rm_rf_ "$build" "$dest" || fatal_ "removing temporary subdirectory"
333     fi
334
335     : For shells with busted 'set -e'.
336
337   done # $instspc_action
338
339 done # $test_name
340
341 :