Skip to content

Commit 03aa378

Browse files
peffgitster
authored andcommitted
t: send verbose test-helper output to fd 4
Test helper functions like test_must_fail may produce messages to stderr when they see a problem. When the tests are run with "--verbose", this ends up on the test script's stderr, and the user can read it. But there's a problem. Some tests record stderr as part of the test, like: test_must_fail git foo 2>output && test_i18ngrep expected.message output In this case the error text goes into "output". This makes the --verbose output less useful (it also means we might accidentally match it in the second, though in practice we tend to produce these messages only on error, so we'd abort the test when the first command fails). Let's instead send this user-facing output directly to descriptor 4, which always points to the original stderr (or /dev/null in non-verbose mode). And it's already forbidden to redirect descriptor 4, since we use it for BASH_XTRACEFD, as explained in 9be795f (t5615: avoid re-using descriptor 4, 2017-12-08). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e3a8078 commit 03aa378

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

t/test-lib-functions.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -625,22 +625,22 @@ test_must_fail () {
625625
exit_code=$?
626626
if test $exit_code -eq 0 && ! list_contains "$_test_ok" success
627627
then
628-
echo >&2 "test_must_fail: command succeeded: $*"
628+
echo >&4 "test_must_fail: command succeeded: $*"
629629
return 1
630630
elif test_match_signal 13 $exit_code && list_contains "$_test_ok" sigpipe
631631
then
632632
return 0
633633
elif test $exit_code -gt 129 && test $exit_code -le 192
634634
then
635-
echo >&2 "test_must_fail: died by signal $(($exit_code - 128)): $*"
635+
echo >&4 "test_must_fail: died by signal $(($exit_code - 128)): $*"
636636
return 1
637637
elif test $exit_code -eq 127
638638
then
639-
echo >&2 "test_must_fail: command not found: $*"
639+
echo >&4 "test_must_fail: command not found: $*"
640640
return 1
641641
elif test $exit_code -eq 126
642642
then
643-
echo >&2 "test_must_fail: valgrind error: $*"
643+
echo >&4 "test_must_fail: valgrind error: $*"
644644
return 1
645645
fi
646646
return 0
@@ -678,7 +678,7 @@ test_expect_code () {
678678
return 0
679679
fi
680680

681-
echo >&2 "test_expect_code: command exited with $exit_code, we wanted $want_code $*"
681+
echo >&4 "test_expect_code: command exited with $exit_code, we wanted $want_code $*"
682682
return 1
683683
}
684684

@@ -742,18 +742,18 @@ test_i18ngrep () {
742742
shift
743743
! grep "$@" && return 0
744744

745-
echo >&2 "error: '! grep $@' did find a match in:"
745+
echo >&4 "error: '! grep $@' did find a match in:"
746746
else
747747
grep "$@" && return 0
748748

749-
echo >&2 "error: 'grep $@' didn't find a match in:"
749+
echo >&4 "error: 'grep $@' didn't find a match in:"
750750
fi
751751

752752
if test -s "$last_arg"
753753
then
754-
cat >&2 "$last_arg"
754+
cat >&4 "$last_arg"
755755
else
756-
echo >&2 "<File '$last_arg' is empty>"
756+
echo >&4 "<File '$last_arg' is empty>"
757757
fi
758758

759759
return 1
@@ -764,7 +764,7 @@ test_i18ngrep () {
764764
# not output anything when they fail.
765765
verbose () {
766766
"$@" && return 0
767-
echo >&2 "command failed: $(git rev-parse --sq-quote "$@")"
767+
echo >&4 "command failed: $(git rev-parse --sq-quote "$@")"
768768
return 1
769769
}
770770

0 commit comments

Comments
 (0)