bug-autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CVS autoconf testsuite failure on Tru64 unix


From: Noah Misch
Subject: Re: CVS autoconf testsuite failure on Tru64 unix
Date: Tue, 14 Dec 2004 23:04:36 -0800
User-agent: Mutt/1.5.6i

On Fri, Dec 10, 2004 at 04:55:30PM -0800, Paul Eggert wrote:
>     at_cmd_expanded="autoconf -t TRACE2:'${)===(}@'"

I think this fix is sound:

When the user runs `./testsuite -x', _AT_CHECK needs to expand all shell
parameters in the command it executes to see if that produces a command
containing newlines.  If it does, _AT_CHECK disables shell tracing for that
command to avoid spurious test failures.

For that purpose, it is safe to expand valid parameter expansions that the shell
will never expand.  That will not effect the outcome of a test for whether an
expanded command contains a newline.  The design of the old regular expression
reflected different priorities.

There was some delay in preparing this because I was trying to port a simple
shell parser I had written in shell to M4.  It ended up slightly too large and
much too ugly for a fringe task like this one.

A full `./testsuite -v -x' passes with this patch, and `ash' no longer reports
any syntax errors in `testsuite'.

2004-12-14  Noah Misch  <address@hidden>

        * lib/m4sugar/m4sh.m4 (AS_ESCAPE_FOR_EXPAND): Escape parameter
        expansions that are invalid, not those that backslashes escape.
        Fixes `testsuite' syntax problem reported by Nicolas Joly.
        (AS_RE_PARAMETER, AS_RE_PARAMETER_EXP): New macros.
        (AS_ESCAPE): Fix comment.
        * tests/m4sh.at (AS_ESCAPE_FOR_EXPAND - syntax)
        (AS_ESCAPE_FOR_EXPAND - parameters): New tests.
        (AS_DIRNAME, AS_BASENAME, AS_MKDIR_P, AS_HELP_STRING): Remove
        excess quoting that appears in output.

diff -urp -X dontdiff --exclude Makefile.am ac-clean/lib/m4sugar/m4sh.m4 
ac-invalid_pexp/lib/m4sugar/m4sh.m4
--- ac-clean/lib/m4sugar/m4sh.m4        2004-12-13 14:46:03.516266181 -0500
+++ ac-invalid_pexp/lib/m4sugar/m4sh.m4 2004-12-14 23:38:00.192351344 -0500
@@ -475,7 +475,7 @@ $as_unset $1 || test "${$1+set}" != set 
 # too.
 
 
-# AS_ESCAPE(STRING, [CHARS = $"'\])
+# AS_ESCAPE(STRING, [CHARS = $"`\])
 # ---------------------------------
 # Escape the CHARS in STRING.
 m4_define([AS_ESCAPE],
@@ -483,15 +483,42 @@ m4_define([AS_ESCAPE],
             m4_ifval([$2], [[\([$2]\)]], [[\([\"$`]\)]]),
             [\\\1])])
 
+
 # AS_ESCAPE_FOR_EXPAND(STRING)
 # ----------------------------
-# Escape characters in STRING that have special meaning to the shell
-# within double quotes, but leave parameter expansions active.
-# These substitutions come from sed_double_backslash in GNU Libtool.
+# Specification:
+# Escape all `"', ``', and `\' in STRING.  Possibly escape some `$', but do not
+# escape any parameter expansion that the shell could expand when it interprets
+# STRING. `foo="AS_ESCAPE_FOR_EXPAND(STRING)"' shall be a valid POSIX shell
+# command.  If STRING is not a valid shell command, the result is unspecified.
+# 
+# This implementation leaves valid parameter expansions active regardless of
+# whether backslashes or single-quotes will keep the shell from ever expanding
+# them.  It escapes all invalid parameter expansions; if the shell were to ever
+# expand those, STRING would also be invalid.
 m4_define([AS_ESCAPE_FOR_EXPAND],
-[m4_bpatsubsts([AS_ESCAPE([$1], [`"\])],
-               [^\(\(\\\\\\\\\)*\\\\\)\$], [\1\\$],
-           [\([^\\]\(\\\\\\\\\)*\\\\\)\$], [\1\\$])])
+[m4_bpatsubsts(AS_ESCAPE([[$1]]),
+               [\\\(\$[^{]\)],                          [\1],
+               \\\(m4_defn([AS_RE_PARAMETER_EXP])\),    [\1])])
+
+
+# AS_RE_PARAMETER
+# ---------------
+# The definition of AS_RE_PARAMETER is a regular expression that only matches
+# every valid POSIX shell parameter.
+m4_define([AS_RE_PARAMETER],
+[\([A-Za-z_][A-Za-z0-9_]*\|[0-9]+\|address@hidden)])
+
+
+# AS_RE_PARAMETER_EXP
+# -------------------
+# The definition of AS_RE_PARAMETER_EXP is a regular expression that matches
+# many valid POSIX shell parameter expansions and does not match any invalid
+# POSIX shell parameter expansions.  This implementation matches only `${...}'
+# expansions, because only they can form grammatically invalid shell.
+m4_define([AS_RE_PARAMETER_EXP],
+\${m4_defn([AS_RE_PARAMETER])[\(\(%%?\|:?[-=+?]\|##?\).*\)?}])
+
 
 # _AS_QUOTE_IFELSE(STRING, IF-MODERN-QUOTATION, IF-OLD-QUOTATION)
 # ---------------------------------------------------------------
diff -urp -X dontdiff --exclude Makefile.am ac-clean/tests/m4sh.at 
ac-invalid_pexp/tests/m4sh.at
--- ac-clean/tests/m4sh.at      2004-08-20 15:58:08.000000000 -0400
+++ ac-invalid_pexp/tests/m4sh.at       2004-12-15 00:24:19.312811435 -0500
@@ -99,7 +99,7 @@ AT_CLEANUP
 ## ------------ ##
 
 # Build nested dirs.
-AT_SETUP([[AS@&address@hidden)
+AT_SETUP([AS@&address@hidden)
 
 AT_DATA_M4SH([script.as],
 [[AS_INIT
@@ -160,7 +160,7 @@ AT_CLEANUP
 ## ------------- ##
 
 # Build nested dirs.
-AT_SETUP([[AS@&address@hidden)
+AT_SETUP([AS@&address@hidden)
 
 AT_DATA_M4SH([script.as],
 [[AS_INIT
@@ -217,7 +217,7 @@ AT_CLEANUP
 ## ------------ ##
 
 # Build nested dirs.
-AT_SETUP([[AS@&address@hidden)
+AT_SETUP([AS@&address@hidden)
 
 AT_DATA_M4SH([script.as],
 [[AS_INIT
@@ -401,7 +401,7 @@ AT_CLEANUP
 # I'm not totally certain that we want to enforce the defaults here,
 # but at least it is being tested.
 
-AT_SETUP([[AS@&address@hidden)
+AT_SETUP([AS@&address@hidden)
 
 AT_DATA_M4SH([script.as],
 [[AS_INIT
@@ -421,3 +421,212 @@ AT_CHECK([./script], [0],
 ])
 
 AT_CLEANUP
+
+
+## -------------------- ##
+## AS_ESCAPE_FOR_EXPAND ##
+## -------------------- ##
+
+AT_SETUP([AS@&address@hidden - syntax])
+AT_KEYWORDS([AS_ESCAPE_FOR_EXPAND])
+
+# This tests the robustness of AS_ESCAPE_FOR_EXPAND in the presence of a number
+# of shell quoting features.  It does not abuse the current implementation,
+# which is ignorant of most shell constructs.  It would be a rigorous test of 
an
+# implementation that attempted to parse shell syntax.
+
+AT_DATA_M4SH([script.as],
+[[AS_INIT
+
+# The current implementation `mishandles' tests so marked in the sense that it
+# could know that the shell will never expand certain parameter expansions but
+# does not analyze for that and expands them anyway.  The specification for
+# AS_ESCAPE_FOR_EXPAND allows this, but a more intelligent implementation would
+# expect different output for those tests.
+
+x=YZ
+echo "AS_ESCAPE_FOR_EXPAND([a])"
+echo "AS_ESCAPE_FOR_EXPAND(["])"
+echo "AS_ESCAPE_FOR_EXPAND([`])"
+echo "AS_ESCAPE_FOR_EXPAND(['])"
+echo "AS_ESCAPE_FOR_EXPAND([foo,bar])"
+echo "AS_ESCAPE_FOR_EXPAND([a\$x])"  # mishandled
+echo "AS_ESCAPE_FOR_EXPAND([\$x])"   # mishandled
+echo "AS_ESCAPE_FOR_EXPAND([$x])"
+echo "AS_ESCAPE_FOR_EXPAND([a\\$x])"
+echo "AS_ESCAPE_FOR_EXPAND([a\\\\$x])"
+echo "AS_ESCAPE_FOR_EXPAND([a\\\\\$x])"   # mishandled
+echo "AS_ESCAPE_FOR_EXPAND([`echo $x`])"  # mishandled
+echo "AS_ESCAPE_FOR_EXPAND([echo '$x'])"  # mishandled
+echo "AS_ESCAPE_FOR_EXPAND([echo '\$x'])" # mishandled
+echo "AS_ESCAPE_FOR_EXPAND([echo "$x"])"
+echo "AS_ESCAPE_FOR_EXPAND([x`echo foo \`echo $x bar\` $x` $x])" # mishandled
+echo "AS_ESCAPE_FOR_EXPAND(['?' $x])"
+echo "AS_ESCAPE_FOR_EXPAND([foo
+bar])"
+echo "AS_ESCAPE_FOR_EXPAND(['echo $x G'NU
+\$x])" # mishandled
+
+]])
+
+AT_CHECK_M4SH
+AT_CHECK([./script], 0,
+[[a
+"
+`
+'
+foo,bar
+a\YZ
+\YZ
+YZ
+a\\YZ
+a\\\\YZ
+a\\\\\YZ
+`echo YZ`
+echo 'YZ'
+echo '\YZ'
+echo "YZ"
+x`echo foo \`echo YZ bar\` YZ` YZ
+'?' YZ
+foo
+bar
+'echo YZ G'NU
+\YZ
+]])
+
+AT_CLEANUP
+
+AT_SETUP([AS@&address@hidden - parameters])
+AT_KEYWORDS([AS_ESCAPE_FOR_EXPAND])
+
+# The current AS_ESCAPE_FOR_EXPAND works by escaping all ``', `"', `\', and `$'
+# and then unquoting `$' where it will not yield an invalid parameter 
expansion.
+# This verifies implementation behavior on a wide range of parameter expansions
+# and other strings containing `$'.  It also tests the behavior of the macro in
+# the presence of commas, parentheses, paired `[]', and macro names.
+
+AT_DATA_M4SH([script.as],
+[[AS_INIT
+
+# Shell constructs.
+echo 'AS_ESCAPE_FOR_EXPAND([wwyz])'
+echo 'AS_ESCAPE_FOR_EXPAND([q])'
+echo "AS_ESCAPE_FOR_EXPAND(')"
+echo 'AS_ESCAPE_FOR_EXPAND(")'
+echo 'AS_ESCAPE_FOR_EXPAND(`)'
+echo 'AS_ESCAPE_FOR_EXPAND(\)'
+echo 'AS_ESCAPE_FOR_EXPAND([foo,bar])'
+echo 'AS_ESCAPE_FOR_EXPAND([a$x])'
+echo 'AS_ESCAPE_FOR_EXPAND([\$foo bar])'
+echo "AS_ESCAPE_FOR_EXPAND(['$fo\o'\whee])"
+echo 'AS_ESCAPE_FOR_EXPAND($)'
+echo 'AS_ESCAPE_FOR_EXPAND([${>-df}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${df}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${x}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${x-y}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${x:-y}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${xyz:-AbZ}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${xyz:-}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${xyz%AbZ}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${xyz%%AbZ}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${xYz%%%AbZ}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${xYz#AbZ}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${xyz##AbZ}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${x?y}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${x:?y}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${x+y}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${x:+y}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${x=y}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${x:=y}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${45}])'
+echo 'AS_ESCAPE_FOR_EXPAND([$/])'
+echo 'AS_ESCAPE_FOR_EXPAND(address@hidden)'
+echo 'AS_ESCAPE_FOR_EXPAND([${!}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${$}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${/}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${=}])'
+echo 'AS_ESCAPE_FOR_EXPAND(address@hidden)'
+echo 'AS_ESCAPE_FOR_EXPAND([${@:-foo}])'
+echo 'AS_ESCAPE_FOR_EXPAND(address@hidden)'
+echo 'AS_ESCAPE_FOR_EXPAND([$_df])'
+echo 'AS_ESCAPE_FOR_EXPAND([${df-f3&^}])'
+echo 'AS_ESCAPE_FOR_EXPAND([GNU$])'        # Tricky one.
+echo 'AS_ESCAPE_FOR_EXPAND([${GNU
+foo}])'
+echo 'AS_ESCAPE_FOR_EXPAND([${GNU])'
+
+# M4 Expansion properties.
+m4_define([ay], [an])dnl
+echo 'AS_ESCAPE_FOR_EXPAND([no [w]ay])'
+echo 'AS_ESCAPE_FOR_EXPAND([[no [w]ay]])'
+echo 'AS_ESCAPE_FOR_EXPAND([[[no [w]ay]]])'
+
+# Behavior around M4 metacharacters.
+echo 'AS_ESCAPE_FOR_EXPAND([a,b])'
+echo 'AS_ESCAPE_FOR_EXPAND([GNU , Autoconf])'
+echo 'AS_ESCAPE_FOR_EXPAND([GNU ( Autoconf])'
+echo 'AS_ESCAPE_FOR_EXPAND([GNU ) Autoconf])'
+echo 'AS_ESCAPE_FOR_EXPAND([GNU() Autoconf])'
+
+]])
+
+AT_CHECK_M4SH
+AT_CHECK([./script], 0,
+[[wwyz
+q
+'
+\"
+\`
+\\
+foo,bar
+a$x
+\\$foo bar
+'\o'\whee
+$
+\${>-df}
+\${}
+${df}
+${x}
+${x-y}
+${x:-y}
+${xyz:-AbZ}
+${xyz:-}
+${xyz%AbZ}
+${xyz%%AbZ}
+${xYz%%%AbZ}
+${xYz#AbZ}
+${xyz##AbZ}
+${x?y}
+${x:?y}
+${x+y}
+${x:+y}
+${x=y}
+${x:=y}
+${45}
+$/
address@hidden
+${!}
+${$}
+\${/}
+\${=}
address@hidden
+${@:-foo}
address@hidden
+$_df
+${df-f3&^}
+GNU$
+\${GNU
+foo}
+\${GNU
+no wan
+no [w]ay
+[no [w]ay]
+a,b
+GNU , Autoconf
+GNU ( Autoconf
+GNU ) Autoconf
+GNU() Autoconf
+]])
+
+AT_CLEANUP




reply via email to

[Prev in Thread] Current Thread [Next in Thread]