aclocal-macrodir.tap 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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_DIR with
  17. # aclocal. See also related test 'aclocal-macrodir.tap'.
  18. am_create_testdir=empty
  19. . test-init.sh
  20. plan_ 7
  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_DIR is honored"
  65. cat > configure.ac <<'END'
  66. AC_INIT([md], [10.0])
  67. AC_CONFIG_MACRO_DIR([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. test_begin "AC_CONFIG_MACRO_DIR([foo]) interaction with --install"
  81. cat > configure.ac << 'END'
  82. AC_INIT([inst], [1.0])
  83. AC_CONFIG_MACRO_DIR([the-dir])
  84. THE_MACRO
  85. END
  86. mkdir sys-dir the-dir
  87. echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
  88. test ! -r the-dir/my.m4 \
  89. && $ACLOCAL --install --system-acdir ./sys-dir \
  90. && diff sys-dir/my.m4 the-dir/my.m4 \
  91. || r='not ok'
  92. test_end
  93. #---------------------------------------------------------------------------
  94. test_begin "'-I' option wins over AC_CONFIG_MACRO_DIR"
  95. cat > configure.ac <<'END'
  96. AC_INIT([md], [4.6])
  97. AC_CONFIG_MACRO_DIR([dir1])
  98. MY_FOO
  99. END
  100. mkdir dir1 dir2
  101. echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4
  102. echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4
  103. $ACLOCAL -I dir2 \
  104. && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \
  105. && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \
  106. && $AUTOCONF \
  107. && not $FGREP '::ko::ko::' configure \
  108. && $FGREP '::ok::ok::' configure \
  109. || r='not ok'
  110. test_end
  111. #---------------------------------------------------------------------------
  112. test_begin "AC_CONFIG_MACRO_DIR([foo]) can create directory 'foo'"
  113. cat > configure.ac << 'END'
  114. AC_INIT([x], [1.0])
  115. AC_CONFIG_MACRO_DIR([foo])
  116. MY_MACRO
  117. END
  118. mkdir acdir
  119. echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4
  120. test ! -d foo \
  121. && $ACLOCAL --install --system-acdir ./acdir \
  122. && diff acdir/bar.m4 foo/bar.m4 \
  123. || r='not ok'
  124. test_end
  125. #---------------------------------------------------------------------------
  126. test_begin "AC_CONFIG_MACRO_DIR([non-existent]) warns with -Wunsupported"
  127. cat > configure.ac << 'END'
  128. AC_INIT([oops], [1.0])
  129. AC_CONFIG_MACRO_DIR([non-existent])
  130. AM_INIT_AUTOMAKE
  131. END
  132. $ACLOCAL -Wno-error 2>stderr \
  133. && cat stderr >&2 \
  134. && grep "couldn't open directory 'non-existent'" stderr \
  135. && test -f aclocal.m4 \
  136. || r='not ok'
  137. rm -rf aclocal.m4 autom4te*.cache
  138. $ACLOCAL -Werror -Wno-unsupported \
  139. && test -f aclocal.m4 \
  140. || r='not ok'
  141. test_end
  142. #---------------------------------------------------------------------------
  143. test_begin "AC_CONFIG_MACRO_DIR([not-exist]) and ACLOCAL_AMFLAGS = -I not-exist"
  144. cat > configure.ac << 'END'
  145. AC_INIT([oops], [1.0])
  146. AC_CONFIG_MACRO_DIR([not-exist])
  147. END
  148. cat > Makefile.am << 'END'
  149. ACLOCAL_AMFLAGS = -I not-exist
  150. END
  151. $ACLOCAL -Wno-error 2>stderr \
  152. && cat stderr >&2 \
  153. && test $(grep -c "couldn't open directory 'not-exist'" stderr) -eq 1 \
  154. || r='not ok'
  155. test_end
  156. #---------------------------------------------------------------------------
  157. # Avoid spurious failures with pre-2.70 autoconf.
  158. # FIXME: remove this in automake 2.0, once we require Autoconf 2.70.
  159. if echo 'AC_INIT AC_CONFIG_MACRO_DIRS' | $AUTOCONF -o/dev/null -; then
  160. test_begin "AC_CONFIG_MACRO_DIR interaction with AC_REQUIRE"
  161. unindent > configure.ac <<'END'
  162. AC_INIT([req], [1.0])
  163. AC_CONFIG_MACRO_DIR([macro-dir])
  164. AC_DEFUN([MY_FOO], [AC_REQUIRE([MY_BAR])])
  165. MY_FOO
  166. END
  167. mkdir macro-dir
  168. echo 'AC_DEFUN([MY_BAR], [//my//bar//])' > macro-dir/x.m4
  169. st=0; $ACLOCAL 2>stderr || st=$?
  170. cat stderr >&2
  171. test $st -eq 0 \
  172. && test ! -s stderr \
  173. && $FGREP 'm4_include([macro-dir/x.m4])' aclocal.m4 \
  174. && $AUTOCONF \
  175. && not $EGREP 'MY_(FOO|BAR)' configure \
  176. && $FGREP '//my//bar//' configure \
  177. || r='not ok'
  178. test_end
  179. else
  180. skip_ -r "autoconf is too old (AC_CONFIG_MACRO_DIRS not defined)"
  181. fi
  182. :