t/README: add a note about don't saving stderr of compound commands

Explain in 't/README' why it is a bad idea to redirect and verify the stderr of compound commands, in the hope that future contributions will follow this advice and the test suite will keep working with '-x' tracing and /bin/sh. While at it, since we can now run the test suite with '-x' without needing a Bash version supporting BASH_XTRACEFD, remove the now outdated caution note about non-Bash shells from the description of the '-x' option. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Feb 24, 2018 at 00:39 UTC 94201a2b0035f441a9172d4cedbef59293247895
1 file changed +17 -3
t/README
+17 -3
@@ -84,9 +84,7 @@ appropriately before running "make".
84
85 -x::
86 Turn on shell tracing (i.e., `set -x`) during the tests
87 - themselves. Implies `--verbose`. Note that in non-bash shells,
88 - this can cause failures in some tests which redirect and test
89 - the output of shell functions. Use with caution.
87 + themselves. Implies `--verbose`.
88 Ignored in test scripts that set the variable 'test_untraceable'
89 to a non-empty value, unless it's run with a Bash version
90 supporting BASH_XTRACEFD, i.e. v4.1 or later.
@@ -455,6 +453,22 @@ Don't:
453 causing the next test to start in an unexpected directory. Do so
454 inside a subshell if necessary.
455
456 + - save and verify the standard error of compound commands, i.e. group
457 + commands, subshells, and shell functions (except test helper
458 + functions like 'test_must_fail') like this:
459 +
460 + ( cd dir && git cmd ) 2>error &&
461 + test_cmp expect error
462 +
463 + When running the test with '-x' tracing, then the trace of commands
464 + executed in the compound command will be included in standard error
465 + as well, quite possibly throwing off the subsequent checks examining
466 + the output. Instead, save only the relevant git command's standard
467 + error:
468 +
469 + ( cd dir && git cmd 2>../error ) &&
470 + test_cmp expect error
471 +
472 - Break the TAP output
473
474 The raw output from your test may be interpreted by a TAP harness. TAP