From 2a01ef8ca31ab1cb889485ba8d9a20c7ba7ab54f Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 6 Aug 2015 01:31:47 -0400 Subject: test-lib: turn off "-x" tracing during chain-lint check Now that GIT_TEST_CHAIN_LINT is on by default, running: ./t0000-basic.sh -x --verbose-only=1 starts with: expecting success: find .git/objects -type f -print >should-be-empty && test_line_count = 0 should-be-empty + exit 117 error: last command exited with $?=117 + find .git/objects -type f -print + test_line_count = 0 should-be-empty + test 3 != 3 + wc -l + test 0 = 0 ok 1 - .git/objects should be empty after git init in an empty repo This is confusing, as the "exit 117" line and the error line (which is printed in red, no less!) are not part of the test at all, but are rather in the separate chain-lint test_eval. Let's unset the "trace" variable when eval-ing the chain lint check, which avoids this. Note that we cannot just do a one-shot variable like: trace= test_eval ... as the behavior of one-shot variables for function calls is not portable. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/test-lib.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 't') diff --git a/t/test-lib.sh b/t/test-lib.sh index 281c1eca0..bc20185b5 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -532,12 +532,17 @@ test_run_ () { expecting_failure=$2 if test "${GIT_TEST_CHAIN_LINT:-1}" != 0; then + # turn off tracing for this test-eval, as it simply creates + # confusing noise in the "-x" output + trace_tmp=$trace + trace= # 117 is magic because it is unlikely to match the exit # code of other programs test_eval_ "(exit 117) && $1" if test "$?" != 117; then error "bug in the test script: broken &&-chain: $1" fi + trace=$trace_tmp fi setup_malloc_check -- cgit v1.2.1 From 9b5fe78b343d2416e5c6da28fa80303957aec371 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 6 Aug 2015 01:33:57 -0400 Subject: test-lib: disable trace when test is not verbose The "-x" test-script option turns on the shell's "-x" tracing, which can help show why a particular test is failing. Unfortunately, this can create false negatives in some tests if they invoke a shell function with its stderr redirected. t5512.10 is such a test, as it does: test_must_fail git ls-remote refs*master >actual 2>&1 && test_cmp exp actual The "actual" file gets the "-x" trace for the test_must_fail function, which prevents it from matching the expected output. There's no way to avoid this without managing the trace flag inside each sub-function, which isn't really a workable solution. But unless you specifically care about t5512.10, we can work around it by enabling tracing only for the specific tests we want. You can already do: ./t5512-ls-remote.sh -x --verbose-only=16 to see the trace only for a specific test. But that doesn't _disable_ the tracing in the other tests; it just sends it to /dev/null. However, there's no point in generating a trace that the user won't see, so we can simply disable tracing whenever it doesn't have a matching verbose flag. The normal case of just "./t5512-ls-remote.sh -x" stays the same, as "-x" already implies "--verbose" (and "--verbose-only" overrides "--verbose", which is why this works at all). And for our test, we need only check $verbose, as maybe_setup_verbose will have already set that flag based on the $verbose_only list). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/test-lib.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/test-lib.sh b/t/test-lib.sh index bc20185b5..ab8461648 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -492,6 +492,10 @@ maybe_setup_valgrind () { fi } +want_trace () { + test "$trace" = t && test "$verbose" = t +} + # This is a separate function because some tests use # "return" to end a test_expect_success block early # (and we want to make sure we run any cleanup like @@ -499,7 +503,7 @@ maybe_setup_valgrind () { test_eval_inner_ () { # Do not add anything extra (including LF) after '$*' eval " - test \"$trace\" = t && set -x + want_trace && set -x $*" } @@ -515,7 +519,7 @@ test_eval_ () { { test_eval_inner_ "$@" &3 2>&4 test_eval_ret_=$? - if test "$trace" = t + if want_trace then set +x if test "$test_eval_ret_" != 0 -- cgit v1.2.1