+2008-10-18 Paolo Bonzini <bonzini@gnu.org>
+
+ Make sure that nested AS_REQUIRE do not lose the desired diversion.
+ * lib/m4sugar/m4sh.m4 (AS_REQUIRE): Expand _m4_divert_desired before
+ passing it to m4_divert_require, so that its content is not used
+ anymore.
+ * tests/m4sh.at (Nested AS_REQUIRE): New testcase.
+
2008-10-18 Eric Blake <ebb9@byu.net>
Document bugs in { } handling.
# given diversion when expanded (required or not). The expansion
# goes in the named diversion or an earlier one.
#
+# Note: we expand _m4_divert_desired before passing it to m4_divert_require,
+# otherwise we would need to use m4_pushdef and m4_popdef instead of
+# simply m4_define.
m4_defun([AS_REQUIRE],
[m4_define([_m4_divert_desired], [m4_default_quoted([$3], [M4SH-INIT])])dnl
m4_if(m4_eval(_m4_divert(_m4_divert_dump) <= _m4_divert(_m4_divert_desired)), 1,
[m4_require([$1], [$2])],
- [m4_divert_require([_m4_divert_desired], [$1], [$2])])])
+ [m4_divert_require(_m4_divert(_m4_divert_desired), [$1], [$2])])])
# AS_REQUIRE_SHELL_FN(NAME-TO-CHECK, COMMENT, BODY-TO-EXPAND,
AT_CLEANUP
+## ------------------- ##
+## Nested AS_REQUIRE. ##
+## ------------------- ##
+
+# Hypothesis: M4sh expands the requirements of AS_REQUIRE in the
+# requested diversion, even if other AS_REQUIREs are interleaved.
+
+AT_SETUP([Nested AS@&t@_REQUIRE])
+AT_KEYWORDS([m4sh])
+
+AT_DATA_M4SH([script.as], [[dnl
+AS_INIT
+
+m4_defun([in_fn_diversion], still_in_m4sh_init_fn=yes)
+m4_defun([not_in_fn_diversion], still_in_m4sh_init_fn=no)
+
+m4_defun([NESTED], [nested_require_in_fn_diversion=$still_in_m4sh_init_fn])
+
+m4_defun([OUTER], [AS_REQUIRE([NESTED])dnl
+outer_require_in_fn_diversion=$still_in_m4sh_init_fn])
+
+m4_defun([test_init], [
+AS_REQUIRE([in_fn_diversion], , [M4SH-INIT-FN])
+AS_REQUIRE([OUTER], , [M4SH-INIT-FN])
+AS_REQUIRE([not_in_fn_diversion], , [M4SH-INIT-FN])
+])
+
+test_init
+if test $outer_require_in_fn_diversion != yes; then AS_EXIT([1]); fi
+if test $nested_require_in_fn_diversion != no; then AS_EXIT([1]); fi
+]])
+
+AT_CHECK_M4SH
+AT_CHECK([./script])
+
+AT_CLEANUP
+
+
## ------------------------------------ ##
## AS_REQUIRE_SHELL_FN and m4_require. ##
## ------------------------------------ ##