aclocal-macrodirs.tap 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. #! /bin/sh
  2. # Copyright (C) 2012-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. # Several tests on the use of the m4 macro AC_CONFIG_MACRO_DIRS with
  17. # aclocal. See also related test 'aclocal-macrodir.tap'.
  18. am_create_testdir=empty
  19. . test-init.sh
  20. plan_ 15
  21. ocwd=$(pwd) || fatal_ "getting current working directory"
  22. unset ACLOCAL_PATH
  23. #
  24. # General utility functions and variables.
  25. #
  26. # TODO: These should maybe be refactored, generalized and
  27. # moved into 't/ax/tap-functions.sh' ...
  28. #
  29. tcount=0
  30. r=invalid
  31. description=''
  32. directive=''
  33. test_begin ()
  34. {
  35. if test -n "$description"; then
  36. fatal_ "'test_begin' called, but another test seems active already"
  37. else
  38. r=ok
  39. description=$1
  40. directive=${2-}
  41. echo "$description" > README.txt
  42. shift
  43. fi
  44. tcount=$(($tcount + 1)) && test $tcount -gt 0 \
  45. || fatal_ "failed to bump the test count"
  46. mkdir $tcount.d
  47. cd $tcount.d
  48. }
  49. test_end ()
  50. {
  51. if test -z "$description"; then
  52. fatal_ "'test_end' called, but no test seems active"
  53. else
  54. cd "$ocwd" || fatal_ "cannot chdir back to top-level directory"
  55. result_ "$r" -D "$directive" -- "$description"
  56. # Don't leave directories for successful subtests hanging around.
  57. if test -z "$directive" && test "$r" = ok; then
  58. rm -rf "$tcount.d" || fatal_ "removing subdir $tcount.d"
  59. fi
  60. r=invalid directive= description=
  61. fi
  62. }
  63. #---------------------------------------------------------------------------
  64. test_begin "AC_CONFIG_MACRO_DIRS is honored"
  65. cat > configure.ac <<'END'
  66. AC_INIT([md], [10.0])
  67. AC_CONFIG_MACRO_DIRS([macro-dir])
  68. MY_FOO
  69. END
  70. mkdir macro-dir
  71. echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > macro-dir/foo.m4
  72. $ACLOCAL \
  73. && $FGREP 'm4_include([macro-dir/foo.m4])' aclocal.m4 \
  74. && $AUTOCONF \
  75. && not $FGREP 'MY_FOO' configure \
  76. && $FGREP '::my::foo::' configure \
  77. || r='not ok'
  78. test_end
  79. #---------------------------------------------------------------------------
  80. three_dirs_check ()
  81. {
  82. mkdir dir1 dir2 dir3
  83. echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > dir1/foo.m4
  84. echo 'AC_DEFUN([MY_BAR], [!!my!!bar!!])' > dir2/zap.m4
  85. echo 'AC_DEFUN([MY_BAZ], [==my==baz==])' > dir3/0.m4
  86. $ACLOCAL \
  87. && $FGREP 'm4_include([dir1/foo.m4])' aclocal.m4 \
  88. && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
  89. && $FGREP 'm4_include([dir3/0.m4])' aclocal.m4 \
  90. && $AUTOCONF \
  91. && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \
  92. && $FGREP '::my::foo::' configure \
  93. && $FGREP '!!my!!bar!!' configure \
  94. && $FGREP '==my==baz==' configure \
  95. || r='not ok'
  96. }
  97. #---------------------------------------------------------------------------
  98. test_begin "AC_CONFIG_MACRO_DIRS several arguments"
  99. cat > configure.ac <<'END'
  100. AC_INIT([more-args], [0.2])
  101. AC_CONFIG_MACRO_DIRS([dir1 dir2 dir3])
  102. MY_FOO
  103. MY_BAR
  104. MY_BAZ
  105. END
  106. three_dirs_check
  107. test_end
  108. #---------------------------------------------------------------------------
  109. test_begin "AC_CONFIG_MACRO_DIRS several calls"
  110. cat > configure.ac <<'END'
  111. AC_INIT([more-calls], [2.0])
  112. AC_CONFIG_MACRO_DIRS([dir1])
  113. AC_CONFIG_MACRO_DIRS([dir2 dir3])
  114. MY_FOO
  115. MY_BAR
  116. MY_BAZ
  117. END
  118. three_dirs_check
  119. test_end
  120. #---------------------------------------------------------------------------
  121. test_begin "AC_CONFIG_MACRO_DIRS extra whitespace"
  122. bslash=\\
  123. cat > configure.ac <<END
  124. AC_INIT([more-args], [0.2])
  125. AC_CONFIG_MACRO_DIRS([ dir1${bslash}
  126. ${tab} dir2 ${tab}${tab}dir3
  127. ${bslash}
  128. ])
  129. MY_FOO
  130. MY_BAR
  131. MY_BAZ
  132. END
  133. three_dirs_check
  134. test_end
  135. #---------------------------------------------------------------------------
  136. test_begin "AC_CONFIG_MACRO_DIRS precedence"
  137. cat > configure.ac <<'END'
  138. AC_INIT([more-calls], [2.0])
  139. AC_CONFIG_MACRO_DIRS([dir1])
  140. AC_CONFIG_MACRO_DIRS([dir2 dir3])
  141. MY_FOO
  142. MY_BAR
  143. MY_BAZ
  144. END
  145. mkdir dir1 dir2 dir3
  146. echo 'AC_DEFUN([MY_FOO], [OK-Foo])' > dir1/b.m4
  147. echo 'AC_DEFUN([MY_FOO], [KO-Foo])' > dir2/a.m4
  148. echo 'AC_DEFUN([MY_BAR], [OK-Bar])' > dir2/1.m4
  149. echo 'AC_DEFUN([MY_BAR], [KO-Bar])' > dir3/0.m4
  150. echo 'AC_DEFUN([MY_BAZ], [OK-Baz])' > dir3/x.m4
  151. $ACLOCAL \
  152. && $FGREP 'm4_include([dir1/b.m4])' aclocal.m4 \
  153. && $FGREP 'm4_include([dir2/1.m4])' aclocal.m4 \
  154. && $FGREP 'm4_include([dir3/x.m4])' aclocal.m4 \
  155. && test $($FGREP -c 'm4_include([dir1' aclocal.m4) -eq 1 \
  156. && test $($FGREP -c 'm4_include([dir2' aclocal.m4) -eq 1 \
  157. && test $($FGREP -c 'm4_include([dir3' aclocal.m4) -eq 1 \
  158. && $AUTOCONF \
  159. && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \
  160. && $FGREP 'OK-Foo' configure \
  161. && $FGREP 'OK-Bar' configure \
  162. && $FGREP 'OK-Baz' configure \
  163. && not $FGREP 'KO-' configure \
  164. || r='not ok'
  165. test_end
  166. #---------------------------------------------------------------------------
  167. test_begin "AC_CONFIG_MACRO_DIRS interaction with --install"
  168. cat > configure.ac << 'END'
  169. AC_INIT([inst], [1.0])
  170. AC_CONFIG_MACRO_DIRS([the-dir])
  171. THE_MACRO
  172. END
  173. mkdir sys-dir the-dir
  174. echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
  175. test ! -r the-dir/my.m4 \
  176. && $ACLOCAL --install --system-acdir ./sys-dir \
  177. && diff sys-dir/my.m4 the-dir/my.m4 \
  178. || r='not ok'
  179. test_end
  180. #---------------------------------------------------------------------------
  181. two_dirs_install_check ()
  182. {
  183. mkdir sys-dir dir1 dir2
  184. echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
  185. echo 'AC_DEFUN([AX_FOO], [:])' > dir2/zap.m4
  186. test ! -r dir1/my.m4 \
  187. && $ACLOCAL --install --system-acdir ./sys-dir \
  188. && diff sys-dir/my.m4 dir1/my.m4 \
  189. && test ! -e dir2/my.m4 \
  190. && $FGREP 'm4_include([dir1/my.m4])' aclocal.m4 \
  191. && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
  192. || r='not ok'
  193. }
  194. #---------------------------------------------------------------------------
  195. test_begin "several AC_CONFIG_MACRO_DIRS arguments and --install"
  196. cat > configure.ac << 'END'
  197. AC_INIT([inst2a], [1.0])
  198. AC_CONFIG_MACRO_DIRS([dir1 dir2])
  199. THE_MACRO
  200. AX_FOO
  201. END
  202. two_dirs_install_check
  203. test_end
  204. #---------------------------------------------------------------------------
  205. test_begin "several AC_CONFIG_MACRO_DIRS calls and --install"
  206. cat > configure.ac << 'END'
  207. AC_INIT([inst2b], [1.0])
  208. AC_CONFIG_MACRO_DIRS([dir1])
  209. AC_CONFIG_MACRO_DIRS([dir2])
  210. THE_MACRO
  211. AX_FOO
  212. END
  213. two_dirs_install_check
  214. test_end
  215. #---------------------------------------------------------------------------
  216. test_begin "'-I' option wins over AC_CONFIG_MACRO_DIRS"
  217. cat > configure.ac <<'END'
  218. AC_INIT([md], [4.6])
  219. AC_CONFIG_MACRO_DIRS([dir1])
  220. MY_FOO
  221. END
  222. mkdir dir1 dir2
  223. echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4
  224. echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4
  225. $ACLOCAL -I dir2 \
  226. && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \
  227. && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \
  228. && $AUTOCONF \
  229. && not $FGREP '::ko::ko::' configure \
  230. && $FGREP '::ok::ok::' configure \
  231. || r='not ok'
  232. test_end
  233. #---------------------------------------------------------------------------
  234. test_begin "AC_CONFIG_MACRO_DIRS([foo]) can create directory 'foo'"
  235. cat > configure.ac << 'END'
  236. AC_INIT([x], [1.0])
  237. AC_CONFIG_MACRO_DIRS([foo])
  238. MY_MACRO
  239. END
  240. mkdir acdir
  241. echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4
  242. test ! -d foo \
  243. && $ACLOCAL --install --system-acdir ./acdir \
  244. && diff acdir/bar.m4 foo/bar.m4 \
  245. || r='not ok'
  246. test_end
  247. #---------------------------------------------------------------------------
  248. test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) warns (1)"
  249. cat > configure.ac << 'END'
  250. AC_INIT([oops], [1.0])
  251. AC_CONFIG_MACRO_DIRS([non-existent])
  252. AM_INIT_AUTOMAKE
  253. END
  254. $ACLOCAL -Wno-error 2>stderr \
  255. && cat stderr >&2 \
  256. && grep "couldn't open directory 'non-existent'" stderr \
  257. && test -f aclocal.m4 \
  258. || r='not ok'
  259. rm -rf aclocal.m4 autom4te*.cache
  260. $ACLOCAL -Werror -Wno-unsupported \
  261. && test -f aclocal.m4 \
  262. || r='not ok'
  263. test_end
  264. #---------------------------------------------------------------------------
  265. test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) warns (2)"
  266. cat > configure.ac << 'END'
  267. AC_INIT([oops], [1.0])
  268. AC_CONFIG_MACRO_DIRS([dir-ok])
  269. AC_CONFIG_MACRO_DIRS([dir-ko])
  270. END
  271. mkdir dir-ok
  272. not $ACLOCAL 2>stderr \
  273. && cat stderr >&2 \
  274. && grep "couldn't open directory 'dir-ko'" stderr \
  275. && not grep "dir-ok" stderr \
  276. && test ! -e aclocal.m4 \
  277. || r='not ok'
  278. test_end
  279. #---------------------------------------------------------------------------
  280. test_begin "AC_CONFIG_MACRO_DIRS([existent non-existent]) errors out"
  281. cat > configure.ac << 'END'
  282. AC_INIT([oops], [1.0])
  283. AC_CONFIG_MACRO_DIRS([dir-ok])
  284. AC_CONFIG_MACRO_DIRS([dir-ko])
  285. END
  286. mkdir dir-ok
  287. not $ACLOCAL -Wnone --install 2>stderr \
  288. && cat stderr >&2 \
  289. && grep "couldn't open directory 'dir-ko'" stderr \
  290. && test ! -e dir-ko \
  291. || r='not ok'
  292. test_end
  293. #---------------------------------------------------------------------------
  294. test_begin "AC_CONFIG_MACRO_DIRS([not-exist]) and ACLOCAL_AMFLAGS = -I not-exist"
  295. cat > configure.ac << 'END'
  296. AC_INIT([oops], [1.0])
  297. AC_CONFIG_MACRO_DIRS([not-exist])
  298. END
  299. cat > Makefile.am << 'END'
  300. ACLOCAL_AMFLAGS = -I not-exist
  301. END
  302. $ACLOCAL -Wno-error 2>stderr \
  303. && cat stderr >&2 \
  304. && test $(grep -c "couldn't open directory 'not-exist'" stderr) -eq 1 \
  305. || r='not ok'
  306. test_end
  307. #---------------------------------------------------------------------------
  308. # Avoid spurious failures with pre-2.70 autoconf.
  309. # FIXME: remove this in automake 2.0, once we require Autoconf 2.70.
  310. if echo 'AC_INIT AC_CONFIG_MACRO_DIRS' | $AUTOCONF -o/dev/null -; then
  311. test_begin "AC_CONFIG_MACRO_DIRS interaction with AC_REQUIRE"
  312. unindent > configure.ac <<'END'
  313. AC_INIT([req], [1.0])
  314. AC_CONFIG_MACRO_DIRS([m1 m2])
  315. AC_DEFUN([MY_FOO], [
  316. AC_REQUIRE([MY_BAR])
  317. AC_REQUIRE([MY_BAZ])
  318. ])
  319. MY_FOO
  320. END
  321. mkdir m1 m2
  322. echo 'AC_DEFUN([MY_BAR], [^^my^^bar^^])' > m1/x.m4
  323. echo 'AC_DEFUN([MY_BAZ], [~~my~~baz~~])' > m2/x.m4
  324. st=0; $ACLOCAL 2>stderr || st=$?
  325. cat stderr >&2
  326. test $st -eq 0 \
  327. && test ! -s stderr \
  328. && $FGREP 'm4_include([m1/x.m4])' aclocal.m4 \
  329. && $FGREP 'm4_include([m2/x.m4])' aclocal.m4 \
  330. && $AUTOCONF \
  331. && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \
  332. && $FGREP '^^my^^bar^^' configure \
  333. && $FGREP '~~my~~baz~~' configure \
  334. || r='not ok'
  335. test_end
  336. else
  337. skip_ -r "autoconf is too old (AC_CONFIG_MACRO_DIRS not defined)"
  338. fi
  339. :