Skip to content

Commit 9b5fe78

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2a01ef8 commit 9b5fe78

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

t/test-lib.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,18 @@ maybe_setup_valgrind () {
492492
fi
493493
}
494494

495+
want_trace () {
496+
test "$trace" = t && test "$verbose" = t
497+
}
498+
495499
# This is a separate function because some tests use
496500
# "return" to end a test_expect_success block early
497501
# (and we want to make sure we run any cleanup like
498502
# "set +x").
499503
test_eval_inner_ () {
500504
# Do not add anything extra (including LF) after '$*'
501505
eval "
502-
test \"$trace\" = t && set -x
506+
want_trace && set -x
503507
$*"
504508
}
505509

@@ -515,7 +519,7 @@ test_eval_ () {
515519
{
516520
test_eval_inner_ "$@" </dev/null >&3 2>&4
517521
test_eval_ret_=$?
518-
if test "$trace" = t
522+
if want_trace
519523
then
520524
set +x
521525
if test "$test_eval_ret_" != 0

0 commit comments

Comments
 (0)