Skip to content

Commit 6a94088

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80980a1 commit 6a94088

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

t/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,11 @@ library for your script to use.
563563
argument. This is primarily meant for use during the
564564
development of a new test script.
565565

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+
566571
- test_done
567572

568573
Your test script must have test_done at the end. Its purpose

t/test-lib-functions.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ test_pause () {
145145
fi
146146
}
147147

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+
148156
# Call test_commit with the arguments "<message> [<file> [<contents> [<tag>]]]"
149157
#
150158
# This will commit a file with the given contents and the given commit

wrap-for-bin.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ GIT_TEXTDOMAINDIR='@@BUILD_DIR@@/po/build/locale'
1919
PATH='@@BUILD_DIR@@/bin-wrappers:'"$PATH"
2020
export GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR
2121

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

0 commit comments

Comments
 (0)