instspc.tap 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. #! /bin/sh
  2. # Copyright (C) 2010-2017 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. # Check that building from, or installing to, directories with shell
  17. # metacharacters succeed.
  18. # Original report from James Amundson about file names with spaces.
  19. # Other characters added by Paul Eggert.
  20. . test-init.sh
  21. # Usage: is_in_list ITEM [LIST...]
  22. is_in_list ()
  23. {
  24. item=$1; shift;
  25. case " $* " in
  26. *[\ \ ]"$item"[\ \ ]*) return 0;;
  27. *) return 1;;
  28. esac
  29. }
  30. # Helper subroutine for test data definition.
  31. # Usage: define_problematic_string NAME STRING
  32. define_problematic_string ()
  33. {
  34. tst=$1; shift
  35. eval "instspc__$tst=\$1" \
  36. || fatal_ "define_problematic_string: bad argument: '$tst'"
  37. shift
  38. all_test_names_list="$all_test_names_list $tst"
  39. # Some of the "problematic" characters cannot be used in the name of
  40. # a build or install directory on a POSIX host. These lists should
  41. # be empty, but are not due to limitations in Autoconf, Automake, Make,
  42. # M4, or the shell.
  43. if is_in_list fail-builddir "$@"; then
  44. builddir_xfails="$builddir_xfails $tst"
  45. fi
  46. if is_in_list fail-destdir "$@"; then
  47. destdir_xfails="$destdir_xfails $tst"
  48. fi
  49. }
  50. # Be sure to avoid interferences from the environment.
  51. all_test_names_list=''
  52. builddir_xfails=''
  53. destdir_xfails=''
  54. expected_to_fail ()
  55. {
  56. case $1 in
  57. build) is_in_list "$2" $builddir_xfails;;
  58. dest) is_in_list "$2" $destdir_xfails;;
  59. *) fatal_ "incorrect 'expected_to_fail' usage";;
  60. esac
  61. }
  62. # Helper subroutines for creation of input data files.
  63. create_input_data ()
  64. {
  65. mkdir sub
  66. unindent >> configure.ac << 'EOF'
  67. AC_PROG_CC
  68. AM_PROG_AR
  69. AC_PROG_RANLIB
  70. AC_OUTPUT
  71. EOF
  72. : > sub/base.h
  73. : > sub/nobase.h
  74. : > sub/base.dat
  75. : > sub/nobase.dat
  76. : > sub/base.sh
  77. : > sub/nobase.sh
  78. unindent > source.c << 'EOF'
  79. int
  80. main (int argc, char **argv)
  81. {
  82. return 0;
  83. }
  84. EOF
  85. unindent > Makefile.am << 'EOF'
  86. foodir = $(prefix)/foo
  87. fooexecdir = $(prefix)/foo
  88. foo_HEADERS = sub/base.h
  89. nobase_foo_HEADERS = sub/nobase.h
  90. dist_foo_DATA = sub/base.dat
  91. nobase_dist_foo_DATA = sub/nobase.dat
  92. dist_fooexec_SCRIPTS = sub/base.sh
  93. nobase_dist_fooexec_SCRIPTS = sub/nobase.sh
  94. fooexec_PROGRAMS = sub/base
  95. nobase_fooexec_PROGRAMS = sub/nobase
  96. sub_base_SOURCES = source.c
  97. sub_nobase_SOURCES = source.c
  98. fooexec_LIBRARIES = sub/libbase.a
  99. nobase_fooexec_LIBRARIES = sub/libnobase.a
  100. sub_libbase_a_SOURCES = source.c
  101. sub_libnobase_a_SOURCES = source.c
  102. .PHONY: test-inst
  103. test-inst: install
  104. test -f '$(DESTDIR)/$(file)-prefix/foo/sub/nobase.h'
  105. test ! -f '$(DESTDIR)/$(file)-prefix/foo/nobase.h'
  106. test -f '$(DESTDIR)/$(file)-prefix/foo/base.h'
  107. test -f '$(DESTDIR)/$(file)-prefix/foo/sub/nobase.dat'
  108. test ! -f '$(DESTDIR)/$(file)-prefix/foo/nobase.dat'
  109. test -f '$(DESTDIR)/$(file)-prefix/foo/base.dat'
  110. test -f '$(DESTDIR)/$(file)-prefix/foo/sub/nobase.sh'
  111. test ! -f '$(DESTDIR)/$(file)-prefix/foo/nobase.sh'
  112. test -f '$(DESTDIR)/$(file)-prefix/foo/base.sh'
  113. test -f '$(DESTDIR)/$(file)-prefix/foo/sub/nobase$(EXEEXT)'
  114. test ! -f '$(DESTDIR)/$(file)-prefix/foo/nobase$(EXEEXT)'
  115. test -f '$(DESTDIR)/$(file)-prefix/foo/base$(EXEEXT)'
  116. test -f '$(DESTDIR)/$(file)-prefix/foo/sub/libnobase.a'
  117. test ! -f '$(DESTDIR)/$(file)-prefix/foo/libnobase.a'
  118. test -f '$(DESTDIR)/$(file)-prefix/foo/libbase.a'
  119. EOF
  120. $ACLOCAL || framework_failure_ "aclocal failed"
  121. $AUTOCONF || framework_failure_ "autoconf failed"
  122. $AUTOMAKE -a || framework_failure_ "automake failed"
  123. }
  124. # ================= #
  125. # Test data begin #
  126. # ----------------- #
  127. # Some control characters that are white space.
  128. bs='' # back space
  129. cr=' ' # carriage return
  130. ff=' ' # form feed
  131. ht=' ' # horizontal tab
  132. lf='
  133. ' # line feed (aka newline)
  134. # Hack to save typing and make code visually clearer.
  135. def=define_problematic_string
  136. $def squote \' fail-builddir fail-destdir
  137. $def dquote '"' fail-builddir fail-destdir
  138. $def bquote '`' fail-builddir fail-destdir
  139. $def sharp '#' fail-builddir fail-destdir
  140. $def dollar '$' fail-builddir fail-destdir
  141. $def bang '!'
  142. $def bslash '\' fail-builddir
  143. $def ampersand '&' fail-builddir
  144. $def percent '%'
  145. $def leftpar '('
  146. $def rightpar ')'
  147. $def pipe '|'
  148. $def caret '^'
  149. $def tilde '~'
  150. $def qmark '?'
  151. $def star '*'
  152. $def plus '+'
  153. $def minus '-'
  154. $def comma ','
  155. $def colon ':'
  156. $def semicol ';'
  157. $def equal '='
  158. $def less '<'
  159. $def more '>'
  160. $def at '@'
  161. $def lqbrack '['
  162. $def rqbrack ']'
  163. $def lcbrack '{'
  164. $def rcbrack '}'
  165. $def space ' '
  166. $def tab "$ht"
  167. $def linefeed "$lf" fail-builddir fail-destdir
  168. $def backspace "$bs"
  169. $def formfeed "$ff"
  170. $def carriageret "$cr"
  171. $def quadrigraph0 '@&t@' fail-builddir
  172. $def quadrigraph1 '@<:@'
  173. $def quadrigraph2 '@:>@'
  174. $def quadrigraph3 '@S|@'
  175. $def quadrigraph4 '@%:@'
  176. $def a_b 'a b'
  177. $def a__b 'a b'
  178. $def a_lf_b "a${lf}b" fail-builddir fail-destdir
  179. $def dotdotdot '...'
  180. $def dosdrive 'a:'
  181. $def miscglob1 '?[a-z]*'
  182. $def miscglob2 '.*?[0-9]'
  183. unset def
  184. # --------------- #
  185. # Test data end #
  186. # =============== #
  187. # Allow the user to select a subset of the tests.
  188. if test $# -gt 0; then
  189. test_names_list=$*
  190. for test_name in $test_names_list; do
  191. case " $all_test_names_list " in
  192. *" $test_name "*);;
  193. *) fatal_ "invalid user-specified test_name '$test_name'"
  194. esac
  195. done
  196. # We need to determine the TAP plan adaptively.
  197. n=$(for t in $test_names_list; do echo $t; done | wc -l)
  198. plan_ $(($n * 2)) # Two tests per "problematic string".
  199. unset n
  200. else
  201. test_names_list=$all_test_names_list
  202. # Prefer static TAP plan if possible, it minimizes the chance of errors.
  203. plan_ 94
  204. fi
  205. ocwd=$(pwd) || fatal_ "getting current working directory"
  206. create_input_data
  207. for test_name in $test_names_list; do
  208. eval "test_string=\${instspc__$test_name}" \
  209. || fatal_ "invalid test name: '$test_name'"
  210. if test x"$test_string" = x; then
  211. if test x"$test_name" != xcarriageret; then
  212. fatal_ "invalid test name: '$test_name'"
  213. else
  214. # MSYS version 1.0.17 still mishandles carriage returns; see
  215. # automake bug#7849.
  216. skip_ -r "carriage-return treated as null char" "$test_name in builddir"
  217. skip_ -r "carriage-return treated as null char" "$test_name in destdir"
  218. continue
  219. fi
  220. fi
  221. # Skip the next checks if this system doesn't support the required
  222. # characters in file names.
  223. mkdir "./$test_string" || {
  224. skip_ -r "mkdir failed" "$test_name in builddir"
  225. skip_ -r "mkdir failed" "$test_name in destdir"
  226. continue
  227. }
  228. case $test_string in
  229. *:*)
  230. # On MSYS 1.0.17, "mkdir ./a:" creates ./a, and "cd ./a:" takes you
  231. # to a strange directory with pwd equal to "a". But only for
  232. # interactive shells. Or something? In this script, "cd ./a:" fails
  233. # on MSYS. Marvelous.
  234. ( cd "./$test_string" ) || {
  235. rmdir "./$test_string" || fatal_ "removing directory"
  236. skip_ -r "cd failed" "$test_name in builddir"
  237. skip_ -r "cd failed" "$test_name in destdir"
  238. continue
  239. }
  240. ;;
  241. esac
  242. # Where are the "weird" characters going to be used, in $(builddir)
  243. # or in $(DESTDIR)? They are always going to be used in $(prefix)
  244. # though; should we maybe separate this into a dedicated check?
  245. for where in build dest; do
  246. case $where in
  247. build)
  248. build=./$test_string
  249. dest=$ocwd/dest-$test_name
  250. ;;
  251. dest)
  252. build=build-$test_name
  253. # Also use $test_name in the definition of $dest, to avoid
  254. # interferences among different tests in case $test_string
  255. # is strangely munged (which is not unexpected, considering
  256. # how tricky its characters are). With some shells, this
  257. # has already happened (at least on OpenIndiana 11 and on
  258. # Solaris 10).
  259. dest=$ocwd/dest-$test_name/$test_string
  260. mkdir "$build" || fatal_ "cannot create '$build'"
  261. ;;
  262. *)
  263. fatal_ "invalid where '$where'"
  264. ;;
  265. esac
  266. cd "$build" || fatal_ "cannot chdir into '$build'"
  267. # Some make implementations eliminate leading and trailing whitespace
  268. # from macros passed on the command line, and some eliminate leading
  269. # whitespace from macros set from environment variables, so prepend
  270. # './' and use the latter here.
  271. r=ok
  272. ../configure --prefix "/$test_string-prefix" \
  273. && $MAKE all \
  274. && DESTDIR="$dest" file="./$test_string" $MAKE test-inst \
  275. || r='not ok'
  276. description="$test_name in ${where}dir"
  277. if expected_to_fail "$where" "$test_name"; then
  278. directive=TODO
  279. reason="long-standing limitation"
  280. else
  281. directive=
  282. reason=
  283. fi
  284. # Test case outcome is here.
  285. result_ "$r" -D "$directive" -r "$reason" -- "$description"
  286. cd "$ocwd" || fatal_ "cannot chdir back to test directory"
  287. # Remove subdirectories for tests that have passed, to avoid ending up
  288. # with a too big test directory. This is especially important since
  289. # some tests in this tests are expected to fail, and this will cause
  290. # the test directory not to be removed when the script terminates.
  291. if not am_keeping_testdirs && test "$r" = ok; then
  292. rm_rf_ "$build" "$dest" || fatal_ "removing temporary subdirectory"
  293. fi
  294. : For shells with busted 'set -e'.
  295. done # $instspc_action
  296. done # $test_name
  297. :