Skip to content

Commit 94201a2

Browse files
szedergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5827506 commit 94201a2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

t/README

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ appropriately before running "make".
8484

8585
-x::
8686
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`.
9088
Ignored in test scripts that set the variable 'test_untraceable'
9189
to a non-empty value, unless it's run with a Bash version
9290
supporting BASH_XTRACEFD, i.e. v4.1 or later.
@@ -455,6 +453,22 @@ Don't:
455453
causing the next test to start in an unexpected directory. Do so
456454
inside a subshell if necessary.
457455

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+
458472
- Break the TAP output
459473

460474
The raw output from your test may be interpreted by a TAP harness. TAP

0 commit comments

Comments
 (0)