Merge branch 'jk/test-suite-tracing'
authorJunio C Hamano <gitster@pobox.com>
Fri, 5 Jan 2018 21:28:09 +0000 (13:28 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Jan 2018 21:28:09 +0000 (13:28 -0800)
Assorted fixes around running tests with "-x" tracing option.

* jk/test-suite-tracing:
t/Makefile: introduce TEST_SHELL_PATH
test-lib: make "-x" work with "--verbose-log"
t5615: avoid re-using descriptor 4
test-lib: silence "-x" cleanup under bash

1  2 
Makefile
t/test-lib.sh
diff --combined Makefile
index 2a81ae22e92cc5a92507666340d340cef3c6b418,ed96453b5cdcc7924bab39096649946826bbec9f..bb5b7cdfb695ee7f15128d5885ea74a4e34f5b9b
+++ b/Makefile
@@@ -426,8 -426,9 +426,12 @@@ all:
  # to say "export LESS=FRX (and LV=-c) if the environment variable
  # LESS (and LV) is not set, respectively".
  #
+ # Define TEST_SHELL_PATH if you want to use a shell besides SHELL_PATH for
+ # running the test scripts (e.g., bash has better support for "set -x"
+ # tracing).
++#
 +# When cross-compiling, define HOST_CPU as the canonical name of the CPU on
 +# which the built Git will run (for instance "x86_64").
  
  GIT-VERSION-FILE: FORCE
        @$(SHELL_PATH) ./GIT-VERSION-GEN
@@@ -649,12 -650,9 +653,12 @@@ TEST_PROGRAMS_NEED_X += test-ctyp
  TEST_PROGRAMS_NEED_X += test-config
  TEST_PROGRAMS_NEED_X += test-date
  TEST_PROGRAMS_NEED_X += test-delta
 +TEST_PROGRAMS_NEED_X += test-drop-caches
  TEST_PROGRAMS_NEED_X += test-dump-cache-tree
 +TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
  TEST_PROGRAMS_NEED_X += test-dump-split-index
  TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
 +TEST_PROGRAMS_NEED_X += test-example-decorate
  TEST_PROGRAMS_NEED_X += test-fake-ssh
  TEST_PROGRAMS_NEED_X += test-genrandom
  TEST_PROGRAMS_NEED_X += test-hashmap
@@@ -733,6 -731,8 +737,8 @@@ endi
  export PERL_PATH
  export PYTHON_PATH
  
+ TEST_SHELL_PATH = $(SHELL_PATH)
  LIB_FILE = libgit.a
  XDIFF_LIB = xdiff/lib.a
  VCSSVN_LIB = vcs-svn/lib.a
@@@ -763,7 -763,6 +769,7 @@@ LIB_OBJS += branch.
  LIB_OBJS += bulk-checkin.o
  LIB_OBJS += bundle.o
  LIB_OBJS += cache-tree.o
 +LIB_OBJS += checkout.o
  LIB_OBJS += color.o
  LIB_OBJS += column.o
  LIB_OBJS += combine-diff.o
@@@ -801,7 -800,6 +807,7 @@@ LIB_OBJS += ewah/ewah_rlw.
  LIB_OBJS += exec_cmd.o
  LIB_OBJS += fetch-pack.o
  LIB_OBJS += fsck.o
 +LIB_OBJS += fsmonitor.o
  LIB_OBJS += gettext.o
  LIB_OBJS += gpg-interface.o
  LIB_OBJS += graph.o
@@@ -815,8 -813,6 +821,8 @@@ LIB_OBJS += levenshtein.
  LIB_OBJS += line-log.o
  LIB_OBJS += line-range.o
  LIB_OBJS += list-objects.o
 +LIB_OBJS += list-objects-filter.o
 +LIB_OBJS += list-objects-filter-options.o
  LIB_OBJS += ll-merge.o
  LIB_OBJS += lockfile.o
  LIB_OBJS += log-tree.o
@@@ -856,7 -852,6 +862,7 @@@ LIB_OBJS += pretty.
  LIB_OBJS += prio-queue.o
  LIB_OBJS += progress.o
  LIB_OBJS += prompt.o
 +LIB_OBJS += protocol.o
  LIB_OBJS += quote.o
  LIB_OBJS += reachable.o
  LIB_OBJS += read-cache.o
  BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d'
  endif
  
 +ifeq (,$(HOST_CPU))
 +      BASIC_CFLAGS += -DGIT_HOST_CPU="\"$(firstword $(subst -, ,$(uname_M)))\""
 +else
 +      BASIC_CFLAGS += -DGIT_HOST_CPU="\"$(HOST_CPU)\""
 +endif
 +
  ifneq (,$(INLINE))
        BASIC_CFLAGS += -Dinline=$(INLINE)
  endif
@@@ -1738,6 -1727,7 +1744,7 @@@ prefix_SQ = $(subst ','\'',$(prefix)
  gitwebdir_SQ = $(subst ','\'',$(gitwebdir))
  
  SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
+ TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
  PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
  PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
  TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
@@@ -1906,9 -1896,7 +1913,9 @@@ builtin/help.sp builtin/help.s builtin/
  version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
  version.sp version.s version.o: EXTRA_CPPFLAGS = \
        '-DGIT_VERSION="$(GIT_VERSION)"' \
 -      '-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)'
 +      '-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)' \
 +      '-DGIT_BUILT_FROM_COMMIT="$(shell GIT_CEILING_DIRECTORIES=\"$(CURDIR)/..\" \
 +              git rev-parse -q --verify HEAD || :)"'
  
  $(BUILT_INS): git$X
        $(QUIET_BUILT_IN)$(RM) $@ && \
@@@ -2370,6 -2358,7 +2377,7 @@@ GIT-LDFLAGS: FORC
  # and the first level quoting from the shell that runs "echo".
  GIT-BUILD-OPTIONS: FORCE
        @echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@+
+       @echo TEST_SHELL_PATH=\''$(subst ','\'',$(TEST_SHELL_PATH_SQ))'\' >>$@+
        @echo PERL_PATH=\''$(subst ','\'',$(PERL_PATH_SQ))'\' >>$@+
        @echo DIFF=\''$(subst ','\'',$(subst ','\'',$(DIFF)))'\' >>$@+
        @echo PYTHON_PATH=\''$(subst ','\'',$(PYTHON_PATH_SQ))'\' >>$@+
diff --combined t/test-lib.sh
index e7065df2bb028aff76f3169d84873a1a3d789571,1ae0fc02d059517919d81d7862ff37cc284c747d..9a0a21f49ae7bef3d0a1b653cce811d12499672e
@@@ -80,7 -80,7 +80,7 @@@ done,*
        # from any previous runs.
        >"$GIT_TEST_TEE_OUTPUT_FILE"
  
-       (GIT_TEST_TEE_STARTED=done ${SHELL_PATH} "$0" "$@" 2>&1;
+       (GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1;
         echo $? >"$BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
        test "$(cat "$BASE.exit")" = 0
        exit
@@@ -264,7 -264,6 +264,6 @@@ d
                shift ;;
        -x)
                trace=t
-               verbose=t
                shift ;;
        --verbose-log)
                verbose_log=t
@@@ -283,6 -282,11 +282,11 @@@ the
        test -z "$verbose_log" && verbose=t
  fi
  
+ if test -n "$trace" && test -z "$verbose_log"
+ then
+       verbose=t
+ fi
  if test -n "$color"
  then
        # Save the color control sequences now rather than run tput
@@@ -586,7 -590,9 +590,9 @@@ maybe_setup_valgrind () 
  }
  
  want_trace () {
-       test "$trace" = t && test "$verbose" = t
+       test "$trace" = t && {
+               test "$verbose" = t || test "$verbose_log" = t
+       }
  }
  
  # This is a separate function because some tests use
@@@ -601,26 -607,40 +607,40 @@@ test_eval_inner_ () 
  }
  
  test_eval_ () {
-       # We run this block with stderr redirected to avoid extra cruft
-       # during a "-x" trace. Once in "set -x" mode, we cannot prevent
+       # If "-x" tracing is in effect, then we want to avoid polluting stderr
+       # with non-test commands. But once in "set -x" mode, we cannot prevent
        # the shell from printing the "set +x" to turn it off (nor the saving
        # of $? before that). But we can make sure that the output goes to
        # /dev/null.
        #
-       # The test itself is run with stderr put back to &4 (so either to
-       # /dev/null, or to the original stderr if --verbose was used).
+       # There are a few subtleties here:
+       #
+       #   - we have to redirect descriptor 4 in addition to 2, to cover
+       #     BASH_XTRACEFD
+       #
+       #   - the actual eval has to come before the redirection block (since
+       #     it needs to see descriptor 4 to set up its stderr)
+       #
+       #   - likewise, any error message we print must be outside the block to
+       #     access descriptor 4
+       #
+       #   - checking $? has to come immediately after the eval, but it must
+       #     be _inside_ the block to avoid polluting the "set -x" output
+       #
+       test_eval_inner_ "$@" </dev/null >&3 2>&4
        {
-               test_eval_inner_ "$@" </dev/null >&3 2>&4
                test_eval_ret_=$?
                if want_trace
                then
                        set +x
-                       if test "$test_eval_ret_" != 0
-                       then
-                               say_color error >&4 "error: last command exited with \$?=$test_eval_ret_"
-                       fi
                fi
-       } 2>/dev/null
+       } 2>/dev/null 4>&2
+       if test "$test_eval_ret_" != 0 && want_trace
+       then
+               say_color error >&4 "error: last command exited with \$?=$test_eval_ret_"
+       fi
        return $test_eval_ret_
  }
  
@@@ -1028,8 -1048,6 +1048,8 @@@ test -z "$NO_PERL" && test_set_prereq P
  test -z "$NO_PTHREADS" && test_set_prereq PTHREADS
  test -z "$NO_PYTHON" && test_set_prereq PYTHON
  test -n "$USE_LIBPCRE1$USE_LIBPCRE2" && test_set_prereq PCRE
 +test -n "$USE_LIBPCRE1" && test_set_prereq LIBPCRE1
 +test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2
  test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
  
  # Can we rely on git's output in the C locale?