automake-patches
[Top][All Lists]
Advanced

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

[FYI] maintcheck: guard against `...` for command substitution in test c


From: Stefano Lattarini
Subject: [FYI] maintcheck: guard against `...` for command substitution in test cases
Date: Sat, 23 Jun 2012 00:14:17 +0200

But still allow them in configure.ac, Makefile.am and shell scripts
created or used inside test cases itself, because Autoconf (as of
version 2.69) does not yet ensure that $CONFIG_SHELL will be set to
a proper POSIX shell.

* syntax-checks.mk (sc_tests_command_subst): New check.
(syntax-check_rules): Add it.
* t/tap-global-log.sh: Minimal tweakings to avoid triggering the
new maintainer check.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 syntax-checks.mk    |   28 ++++++++++++++++++++++++++++
 t/tap-global-log.sh |    6 ++++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/syntax-checks.mk b/syntax-checks.mk
index 0549bc8..417ae5e 100644
--- a/syntax-checks.mk
+++ b/syntax-checks.mk
@@ -58,6 +58,7 @@ sc_AMDEP_TRUE_in_automake_in \
 sc_tests_make_without_am_makeflags \
 sc_tests_obsolete_variables \
 sc_tests_here_document_format \
+sc_tests_command_subst \
 sc_tests_Exit_not_exit \
 sc_tests_automake_fails \
 sc_tests_required_after_defs \
@@ -341,6 +342,33 @@ sc_tests_here_document_format:
          exit 1; \
        fi
 
+## Our test case should use the $(...) POSIX form for command substitution,
+## rather than the older `...` form.
+## The point of ignoring text on here-documents is that we want to exempt
+## Makefile.am rules, configure.ac code and helper shell script created and
+## used by out shell scripts, because Autoconf (as of version 2.69) does not
+## yet ensure that $CONFIG_SHELL will be set to a proper POSIX shell.
+sc_tests_command_subst:
+       @found=false; \
+       scan () { \
+         sed -n -e '/^#/d' \
+                -e '/<<.*END/,/^END/b' -e '/<<.*EOF/,/^EOF/b' \
+                -e 's/\\`/\\{backtick}/' \
+                -e "s/[^\\]'\([^']*\`[^']*\)*'/'{quoted-text}'/g" \
+                -e '/`/p' $$*; \
+       }; \
+       for file in $(xtests); do \
+         res=`scan $$file`; \
+         if test -n "$$res"; then \
+           echo "$$file:$$res"; \
+           found=true; \
+         fi; \
+       done; \
+       if $$found; then \
+         echo 'Use $$(...), not `...`, for command substitutions.' >&2; \
+         exit 1; \
+       fi
+
 ## Tests should never call exit directly, but use Exit.
 ## This is so that the exit status is transported correctly across the 0 trap.
 ## Ignore comments and our testsuite's own self tests.
diff --git a/t/tap-global-log.sh b/t/tap-global-log.sh
index 493a5a4..8267a3d 100755
--- a/t/tap-global-log.sh
+++ b/t/tap-global-log.sh
@@ -113,8 +113,10 @@ done
 
 grep '^1\.\.0 # SKIP all$' test-suite.log
 
-case `cat test-suite.log` in
-  *"`cat hodgepodge`"*) ;;
+test_suite_contents=$(cat test-suite.log)
+hodgepodge_contents=$(cat hodgepodge)
+case $test_suite_contents in
+  *"$hodgepodge_contents"*) ;;
   *) Exit 1;;
 esac
 
-- 
1.7.9.5




reply via email to

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