2003-11-24 Paolo Bonzini <bonzini@gnu.org>

* lib/m4sugar/m4sh.m4 (AS_REQUIRE_SHELL_FN): New macro.
        * tests/m4sh.at (AS_REQUIRE_SHELL_FN and m4_require): New test.

Approved by Paul Eggert.
This commit is contained in:
Paolo Bonzini 2003-11-24 10:44:52 +00:00
parent 9e56967aa4
commit f2193aa86c
2 changed files with 57 additions and 0 deletions

View File

@ -134,6 +134,19 @@ m4_define([AS_REQUIRE],
[m4_divert_text([M4SH-INIT], [m4_default([$2], [$1])])])])
# AS_REQUIRE_SHELL_FN(NAME-TO-CHECK, BODY-TO-EXPAND)
# --------------------------------------------------
# BODY-TO-EXPAND is the body of a shell function to be emitted in the
# M4SH-INIT section when expanded (required or not). Unlike other
# xx_REQUIRE macros, BODY-TO-EXPAND is mandatory.
#
m4_define([AS_REQUIRE_SHELL_FN],
[m4_provide_if([AS_SHELL_FN_$1], [],
[m4_provide([AS_SHELL_FN_$1])m4_divert_text([M4SH-INIT], [$1() {
$2
}])])])
# AS_SHELL_SANITIZE
# -----------------
# Try to be as Bourne and/or POSIX as possible.

View File

@ -350,6 +350,50 @@ AT_CHECK([./script])
AT_CLEANUP
## ------------------------------------ ##
## AS_REQUIRE_SHELL_FN and m4_require. ##
## ------------------------------------ ##
# Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
# in the main diversion, and not in M4SH-INIT.
AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
AT_DATA_M4SH([script.as], [[dnl
AS_INIT
m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
m4_defun([error_if_emitted_in_m4sh_init], [
if test x$still_in_m4sh_init = xyes; then
AS_ERROR([requirement emitted in M4SH-INIT])
fi
])
m4_defun([TEST_FUNC_BODY], [
m4_require([error_if_emitted_in_m4sh_init])
: echo in shell function, with parameter = [$]1
])
m4_defun([test_init], [
AS_REQUIRE([in_m4_sh_init])
AS_REQUIRE_SHELL_FN([test_func], [TEST_FUNC_BODY])
AS_REQUIRE([not_in_m4_sh_init])
])
test_init
test_func parameter1
]])
AT_CHECK_M4SH
AT_CHECK([./script])
AT_CLEANUP
## -------------- ##
## AS_HELP_STRING ##
## -------------- ##