Skip to content

Commit 01c3810

Browse files
phil-blaingitster
authored andcommitted
test-lib-functions: keep user's debugger config files and TERM in 'debug'
The 'debug' function in test-lib-functions.sh is used to invoke a debugger at a specific line in a test. It inherits the value of HOME and TERM set by 'test-lib.sh': HOME="$TRASH_DIRECTORY" and TERM=dumb. Changing the value of HOME means that any customization configured in a developers' debugger configuration file (like $HOME/.gdbinit or $HOME/.lldbinit) are not available in the debugger invoked by 'test_pause'. Changing the value of TERM to 'dumb' means that colored output is disabled in the debugger. To make the debugging experience with 'debug' more pleasant, leverage the variable USER_HOME, added in the previous commit, to copy a developer's ~/.gdbinit and ~/.lldbinit to the test HOME. We do not set HOME to USER_HOME as in 'test_pause' to avoid user configuration in $USER_HOME/.gitconfig from interfering with the command being debugged. Also, add a flag to launch the debugger with the original value of TERM, and add the same warning as for 'test_pause'. Helped-by: Carlo Marcelo Arenas Belón <[email protected]> Signed-off-by: Philippe Blain <[email protected]> Acked-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent add5240 commit 01c3810

File tree

2 files changed

+50
-16
lines changed

2 files changed

+50
-16
lines changed

t/README

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,12 @@ see test-lib-functions.sh for the full list and their options.
800800
argument. This is primarily meant for use during the
801801
development of a new test script.
802802

803-
- debug <git-command>
803+
- debug [options] <git-command>
804804

805805
Run a git command inside a debugger. This is primarily meant for
806-
use when debugging a failing test script.
806+
use when debugging a failing test script. With '-t', use your
807+
original TERM instead of test-lib.sh's "dumb", so that your
808+
debugger interface has colors.
807809

808810
- test_done
809811

t/test-lib-functions.sh

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,25 +190,57 @@ test_pause () {
190190
# Wrap git with a debugger. Adding this to a command can make it easier
191191
# to understand what is going on in a failing test.
192192
#
193+
# Usage: debug [options] <git command>
194+
# -d <debugger>
195+
# --debugger=<debugger>
196+
# Use <debugger> instead of GDB
197+
# -t
198+
# Use your original TERM instead of test-lib.sh's "dumb".
199+
# This usually restores color output in the debugger.
200+
# WARNING: the command being debugged might behave differently than when
201+
# running the test.
202+
#
193203
# Examples:
194204
# debug git checkout master
195205
# debug --debugger=nemiver git $ARGS
196206
# debug -d "valgrind --tool=memcheck --track-origins=yes" git $ARGS
197207
debug () {
198-
case "$1" in
199-
-d)
200-
GIT_DEBUGGER="$2" &&
201-
shift 2
202-
;;
203-
--debugger=*)
204-
GIT_DEBUGGER="${1#*=}" &&
205-
shift 1
206-
;;
207-
*)
208-
GIT_DEBUGGER=1
209-
;;
210-
esac &&
211-
GIT_DEBUGGER="${GIT_DEBUGGER}" "$@" <&6 >&5 2>&7
208+
GIT_DEBUGGER=1 &&
209+
DEBUG_TERM=$TERM &&
210+
while test $# != 0
211+
do
212+
case "$1" in
213+
-t)
214+
DEBUG_TERM="$USER_TERM"
215+
;;
216+
-d)
217+
GIT_DEBUGGER="$2" &&
218+
shift
219+
;;
220+
--debugger=*)
221+
GIT_DEBUGGER="${1#*=}"
222+
;;
223+
*)
224+
break
225+
;;
226+
esac
227+
shift
228+
done &&
229+
230+
dotfiles=".gdbinit .lldbinit"
231+
232+
for dotfile in $dotfiles
233+
do
234+
dotfile="$USER_HOME/$dotfile" &&
235+
test -f "$dotfile" && cp "$dotfile" "$HOME" || :
236+
done &&
237+
238+
TERM="$DEBUG_TERM" GIT_DEBUGGER="${GIT_DEBUGGER}" "$@" <&6 >&5 2>&7 &&
239+
240+
for dotfile in $dotfiles
241+
do
242+
rm -f "$HOME/$dotfile"
243+
done
212244
}
213245

214246
# Usage: test_commit [options] <message> [<file> [<contents> [<tag>]]]

0 commit comments

Comments
 (0)