test: facilitate debugging Git executables in tests with gdb

When prefixing a Git call in the test suite with 'debug ', it will now be run with GDB, allowing the developer to debug test failures more conveniently. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Oct 30, 2015 at 12:02 UTC 6a94088cc3d539bdc15b824befc083f7ff8d0288
3 files changed +20 -1
t/README
+5
@@ -563,6 +563,11 @@ library for your script to use.
563 argument. This is primarily meant for use during the
564 development of a new test script.
565
566 + - debug <git-command>
567 +
568 + Run a git command inside a debugger. This is primarily meant for
569 + use when debugging a failing test script.
570 +
571 - test_done
572
573 Your test script must have test_done at the end. Its purpose
t/test-lib-functions.sh
+8
@@ -145,6 +145,14 @@ test_pause () {
145 fi
146 }
147
148 +# Wrap git in gdb. Adding this to a command can make it easier to
149 +# understand what is going on in a failing test.
150 +#
151 +# Example: "debug git checkout master".
152 +debug () {
153 + GIT_TEST_GDB=1 "$@"
154 +}
155 +
156 # Call test_commit with the arguments "<message> [<file> [<contents> [<tag>]]]"
157 #
158 # This will commit a file with the given contents and the given commit
wrap-for-bin.sh
+7 -1
@@ -19,4 +19,10 @@ GIT_TEXTDOMAINDIR='@@BUILD_DIR@@/po/build/locale'
19 PATH='@@BUILD_DIR@@/bin-wrappers:'"$PATH"
20 export GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR
21
22 -exec "${GIT_EXEC_PATH}/@@PROG@@" "$@"
22 +if test -n "$GIT_TEST_GDB"
23 +then
24 + unset GIT_TEST_GDB
25 + exec gdb --args "${GIT_EXEC_PATH}/@@PROG@@" "$@"
26 +else
27 + exec "${GIT_EXEC_PATH}/@@PROG@@" "$@"
28 +fi