test-lib: disable trace when test is not verbose
commit9b5fe78b343d2416e5c6da28fa80303957aec371
authorJeff King <peff@peff.net>
Thu, 6 Aug 2015 05:33:57 +0000 (6 01:33 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Aug 2015 18:52:46 +0000 (7 11:52 -0700)
treea1929ac2c6b390d6cc5fa3ec4bb1691a1bdfc413
parent2a01ef8ca31ab1cb889485ba8d9a20c7ba7ab54f
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/test-lib.sh