From e5343765c216cd8bff74da01986e61c3fe093eb1 Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Sat, 23 Jun 2012 00:06:10 +0200 Subject: [PATCH] maintcheck: guard against `...` for command substitution in test cases 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 --- 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 -- 2.7.4