[Top][All Lists]

[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_ESCAPE): Fix comment.
        * tests/m4sh.at (AS_ESCAPE_FOR_EXPAND - syntax)
        (AS_ESCAPE_FOR_EXPAND - parameters): New tests.
        excess quoting that appears in output.

diff -urp -X dontdiff --exclude Makefile.am ac-clean/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.
 # ---------------------------------
 # Escape the CHARS in STRING.
@@ -483,15 +483,42 @@ m4_define([AS_ESCAPE],
             m4_ifval([$2], [[\([$2]\)]], [[\([\"$`]\)]]),
 # ----------------------------
-# 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_bpatsubsts([AS_ESCAPE([$1], [`"\])],
-               [^\(\(\\\\\\\\\)*\\\\\)\$], [\1\\$],
-           [\([^\\]\(\\\\\\\\\)*\\\\\)\$], [\1\\$])])
+               [\\\(\$[^{]\)],                          [\1],
+               \\\(m4_defn([AS_RE_PARAMETER_EXP])\),    [\1])])
+# ---------------
+# The definition of AS_RE_PARAMETER is a regular expression that only matches
+# every valid POSIX shell parameter.
+# -------------------
+# 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.
 # ---------------------------------------------------------------
diff -urp -X dontdiff --exclude Makefile.am ac-clean/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.
@@ -160,7 +160,7 @@ AT_CLEANUP
 ## ------------- ##
 # Build nested dirs.
@@ -217,7 +217,7 @@ AT_CLEANUP
 ## ------------ ##
 # Build nested dirs.
@@ -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.
@@ -421,3 +421,212 @@ AT_CHECK([./script], [0],
+## -------------------- ##
+## -------------------- ##
+AT_SETUP([AS@&address@hidden - syntax])
+# 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 
+# implementation that attempted to parse shell syntax.
+# 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.
+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(['echo $x G'NU
+\$x])" # mishandled
+AT_CHECK([./script], 0,
+`echo YZ`
+echo 'YZ'
+echo '\YZ'
+echo "YZ"
+x`echo foo \`echo YZ bar\` YZ` YZ
+'?' YZ
+'echo YZ G'NU
+AT_SETUP([AS@&address@hidden - parameters])
+# The current AS_ESCAPE_FOR_EXPAND works by escaping all ``', `"', `\', and `$'
+# and then unquoting `$' where it will not yield an invalid parameter 
+# 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.
+# Shell constructs.
+echo 'AS_ESCAPE_FOR_EXPAND([wwyz])'
+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([${>-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.
+# 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([./script], 0,
+\\$foo bar
+no wan
+no [w]ay
+[no [w]ay]
+GNU , Autoconf
+GNU ( Autoconf
+GNU ) Autoconf
+GNU() Autoconf

reply via email to

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