mirror of
git://git.sv.gnu.org/autoconf
synced 2025-01-06 10:25:53 +08:00
Test AS_VAR interfaces.
* tests/m4sh.at (AS@&t@_VAR): New test. * lib/m4sugar/m4sh.m4 (AS_VAR_PUSHDEF): Force expansion of _AS_TR_SH_PREPARE at top level, rather than argument collection. (AS_TR_SH): Support command substitution. Signed-off-by: Eric Blake <ebb9@byu.net>
This commit is contained in:
parent
6e3761f85f
commit
c7f3d4ef19
@ -1,5 +1,11 @@
|
||||
2008-10-17 Eric Blake <ebb9@byu.net>
|
||||
|
||||
Test AS_VAR interfaces.
|
||||
* tests/m4sh.at (AS@&t@_VAR): New test.
|
||||
* lib/m4sugar/m4sh.m4 (AS_VAR_PUSHDEF): Force expansion of
|
||||
_AS_TR_SH_PREPARE at top level, rather than argument collection.
|
||||
(AS_TR_SH): Support command substitution.
|
||||
|
||||
Add AS_VAR_COPY.
|
||||
* lib/m4sugar/m4sh.m4 (AS_VAR_COPY): New macro.
|
||||
(AS_VAR_IF): Use it, instead of the broken AS_VAR_GET.
|
||||
|
@ -1569,7 +1569,8 @@ AS_LITERAL_IF([$1],
|
||||
m4_dquote(m4_dquote(m4_defn([m4_cr_not_symbols2])))[[,
|
||||
[pp[]]]]dnl
|
||||
m4_dquote(m4_dquote(m4_for(,1,255,,[[_]])))[[)],
|
||||
[`AS_ECHO(["$1"]) | $as_tr_sh`])])
|
||||
[`AS_ECHO(["m4_bpatsubst(m4_dquote(m4_expand([$1])),
|
||||
[[\\`]], [\\\&])"]) | $as_tr_sh`])])
|
||||
|
||||
|
||||
# _AS_TR_CPP_PREPARE
|
||||
@ -1695,8 +1696,15 @@ m4_define([AS_VAR_POPDEF],
|
||||
# Define the m4 macro VARNAME to an accessor to the shell variable
|
||||
# named VALUE. VALUE does not need to be a valid shell variable name:
|
||||
# the transliteration is handled here. To be dnl'ed.
|
||||
#
|
||||
# AS_TR_SH attempts to play with diversions if _AS_TR_SH_PREPARE has
|
||||
# not been expanded. However, users are expected to do subsequent
|
||||
# calls that trigger AS_LITERAL_IF([VARNAME]), and that macro performs
|
||||
# expansion inside an argument collection context, where diversions
|
||||
# don't work. Therefore, we must require the preparation ourselves.
|
||||
m4_define([AS_VAR_PUSHDEF],
|
||||
[AS_LITERAL_IF([$2],
|
||||
[AS_REQUIRE([_AS_TR_SH_PREPARE])dnl
|
||||
AS_LITERAL_IF([$2],
|
||||
[m4_pushdef([$1], [AS_TR_SH($2)])],
|
||||
[as_$1=AS_TR_SH($2)
|
||||
m4_pushdef([$1], [$as_[$1]])])])
|
||||
|
@ -884,6 +884,102 @@ ok 7
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ---------- ##
|
||||
## AS_VAR_*. ##
|
||||
## ---------- ##
|
||||
|
||||
AT_SETUP([AS@&t@_VAR])
|
||||
AT_KEYWORDS([m4sh AS@&t@_VAR_COPY AS@&t@_VAR_SET AS@&t@_VAR_GET])
|
||||
AT_KEYWORDS([AS@&t@_VAR_TEST_SET AS@&t@_VAR_SET_IF AS@&t@_VAR_IF])
|
||||
AT_KEYWORDS([AS@&t@_VAR_PUSHDEF AS@&t@_VAR_POPDEF])
|
||||
|
||||
AT_DATA_M4SH([script.as], [[dnl
|
||||
AS_INIT
|
||||
# Literals.
|
||||
dnl AS_VAR_SET_IF also covers AS_VAR_TEST_SET
|
||||
AS_VAR_SET_IF([foo], [echo oops], [echo ok])
|
||||
AS_VAR_SET([foo], ['\a "weird" `value` with; $fun '\''characters
|
||||
']) # 'font-lock
|
||||
AS_VAR_COPY([bar], [foo])
|
||||
echo "$bar-"
|
||||
echo "AS_VAR_GET([foo])-"
|
||||
AS_VAR_SET_IF([foo], [echo ok], [echo oops])
|
||||
AS_VAR_IF([foo], [string], [echo oops], [echo ok])
|
||||
AS_VAR_PUSHDEF([tmp], [foo])
|
||||
AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
|
||||
'], [echo ok], [echo oops]) # 'font-lock
|
||||
AS_VAR_POPDEF([tmp])
|
||||
m4_ifdef([tmp], [echo oops])
|
||||
|
||||
# Indirects via shell vars.
|
||||
echo '===='
|
||||
num=1
|
||||
AS_VAR_SET_IF([foo$num], [echo oops], [echo ok])
|
||||
AS_VAR_SET([foo$num], ['\a "weird" `value` with; $fun '\''characters
|
||||
']) # 'font-lock
|
||||
AS_VAR_COPY([bar], [foo$num])
|
||||
num=2
|
||||
AS_VAR_COPY([foo$num], [bar])
|
||||
echo "$foo2-"
|
||||
echo "AS_VAR_GET([foo$num])-"
|
||||
AS_VAR_SET_IF([foo$num], [echo ok], [echo oops])
|
||||
AS_VAR_IF([foo$num], [string], [echo oops], [echo ok])
|
||||
AS_VAR_PUSHDEF([tmp], [foo$num])
|
||||
AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
|
||||
'], [echo ok], [echo oops]) # 'font-lock
|
||||
AS_VAR_POPDEF([tmp])
|
||||
m4_ifdef([tmp], [echo oops])
|
||||
|
||||
# Indirects via command substitution.
|
||||
echo '===='
|
||||
AS_VAR_SET_IF([`echo foo3`], [echo oops], [echo ok])
|
||||
AS_VAR_SET([`echo foo3`], ['\a "weird" `value` with; $fun '\''characters
|
||||
']) # 'font-lock
|
||||
AS_VAR_COPY([bar], [`echo foo3`])
|
||||
num=2
|
||||
AS_VAR_COPY([`echo foo4`], [bar])
|
||||
echo "$foo4-"
|
||||
echo "AS_VAR_GET([`echo foo4`])-"
|
||||
AS_VAR_SET_IF([`echo foo4`], [echo ok], [echo oops])
|
||||
AS_VAR_IF([`echo foo4`], [string], [echo oops], [echo ok])
|
||||
AS_VAR_PUSHDEF([tmp], [`echo foo4`])
|
||||
AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
|
||||
'], [echo ok], [echo oops]) # 'font-lock
|
||||
AS_VAR_POPDEF([tmp])
|
||||
m4_ifdef([tmp], [echo oops])
|
||||
:
|
||||
]])
|
||||
|
||||
AT_CHECK_M4SH
|
||||
AT_CHECK([./script], [], [[ok
|
||||
\a "weird" `value` with; $fun 'characters
|
||||
-
|
||||
\a "weird" `value` with; $fun 'characters
|
||||
-
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
====
|
||||
ok
|
||||
\a "weird" `value` with; $fun 'characters
|
||||
-
|
||||
\a "weird" `value` with; $fun 'characters-
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
====
|
||||
ok
|
||||
\a "weird" `value` with; $fun 'characters
|
||||
-
|
||||
\a "weird" `value` with; $fun 'characters-
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ----------------- ##
|
||||
## AS_INIT cleanup. ##
|
||||
## ----------------- ##
|
||||
|
Loading…
Reference in New Issue
Block a user