git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 3/3] test-lib-functions: keep user's debugger config files and TERM in 'debug'

From
Philippe Blain via GitGitGadget <gitgitgadget@gmail.com>
Date
Sep 6, 2021, 04:39 UTC
Message-ID
<ebf92b6b2c379ed007ec66e97dc4ad7aecb7ad81.1630903140.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1022.v5.git.1630903140.gitgitgadget@gmail.com>
From: Philippe Blain <levraiphilippeblain@gmail.com>

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 <carenas@gmail.com>
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
---
 t/README                |  6 +++--
 t/test-lib-functions.sh | 60 +++++++++++++++++++++++++++++++----------
 2 files changed, 50 insertions(+), 16 deletions(-)
diff --git a/t/README b/t/README
index cc8be6e67ad..e924bd81e2d 100644
--- a/t/README
+++ b/t/README
@@ -800,10 +800,12 @@ see test-lib-functions.sh for the full list and their options.
    argument.  This is primarily meant for use during the
    development of a new test script.
 
- - debug <git-command>
+ - debug [options] <git-command>
 
    Run a git command inside a debugger. This is primarily meant for
-   use when debugging a failing test script.
+   use when debugging a failing test script. With '-t', use your
+   original TERM instead of test-lib.sh's "dumb", so that your
+   debugger interface has colors.
 
  - test_done
 
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 5bed34e47e0..eef2262a360 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -190,25 +190,57 @@ test_pause () {
 # Wrap git with a debugger. Adding this to a command can make it easier
 # to understand what is going on in a failing test.
 #
+# Usage: debug [options] <git command>
+#   -d <debugger>
+#   --debugger=<debugger>
+#	Use <debugger> instead of GDB
+#   -t
+#	Use your original TERM instead of test-lib.sh's "dumb".
+#	This usually restores color output in the debugger.
+#	WARNING: the command being debugged might behave differently than when
+#	running the test.
+#
 # Examples:
 #     debug git checkout master
 #     debug --debugger=nemiver git $ARGS
 #     debug -d "valgrind --tool=memcheck --track-origins=yes" git $ARGS
 debug () {
-	case "$1" in
-	-d)
-		GIT_DEBUGGER="$2" &&
-		shift 2
-		;;
-	--debugger=*)
-		GIT_DEBUGGER="${1#*=}" &&
-		shift 1
-		;;
-	*)
-		GIT_DEBUGGER=1
-		;;
-	esac &&
-	GIT_DEBUGGER="${GIT_DEBUGGER}" "$@" <&6 >&5 2>&7
+	GIT_DEBUGGER=1 &&
+	DEBUG_TERM=$TERM &&
+	while test $# != 0
+	do
+		case "$1" in
+		-t)
+			DEBUG_TERM="$USER_TERM"
+			;;
+		-d)
+			GIT_DEBUGGER="$2" &&
+			shift
+			;;
+		--debugger=*)
+			GIT_DEBUGGER="${1#*=}"
+			;;
+		*)
+			break
+			;;
+		esac
+		shift
+	done &&
+
+	dotfiles=".gdbinit .lldbinit"
+
+	for dotfile in $dotfiles
+	do
+		dotfile="$USER_HOME/$dotfile" &&
+		test -f "$dotfile" && cp "$dotfile" "$HOME" || :
+	done &&
+
+	TERM="$DEBUG_TERM" GIT_DEBUGGER="${GIT_DEBUGGER}" "$@" <&6 >&5 2>&7 &&
+
+	for dotfile in $dotfiles
+	do
+		rm -f "$HOME/$dotfile"
+	done
 }
 
 # Usage: test_commit [options] <message> [<file> [<contents> [<tag>]]]
-- 
gitgitgadget
Previous: Philippe Blain via GitGitGadgetNext: Elijah Newren
Message 38 of 39 in “test-lib-functions.sh: keep user's HOME, TERM and SHELL for 'test_pause' and 'debug'”
  1. 0/2 test-lib-functions.sh: keep user's HOME, TERM and SHELL for 'test_pause' and 'debug'Philippe Blain via GitGitGadget, Aug 19, 2021
  2. 1/2 test-lib-functions: use user's SHELL, HOME and TERM for 'test_pause'Philippe Blain via GitGitGadget, Aug 19, 2021
  3. Carlo ArenasAug 20, 2021
  4. Philippe BlainAug 20, 2021
  5. 2/2 test-lib-functions: use user's TERM and HOME for 'debug'Philippe Blain via GitGitGadget, Aug 19, 2021
  6. Taylor BlauAug 19, 2021
  7. Carlo ArenasAug 20, 2021
  8. Eric SunshineAug 19, 2021
  9. Junio C HamanoAug 19, 2021
  10. Eric SunshineAug 19, 2021
  11. Elijah NewrenAug 19, 2021
  12. Eric SunshineAug 19, 2021
  13. Philippe BlainAug 20, 2021
  14. Eric SunshineAug 20, 2021
  15. Jeff KingAug 20, 2021
  16. 0/3 test-lib-functions.sh: keep user's HOME, TERM and SHELL for 'test_pause' and 'debug'Philippe Blain via GitGitGadget, Aug 28, 2021
  17. 1/3 test-lib-functions: use 'TEST_SHELL_PATH' in 'test_pause'Philippe Blain via GitGitGadget, Aug 28, 2021
  18. 2/3 test-lib-functions: optionally keep HOME, TERM and SHELL in 'test_pause'Philippe Blain via GitGitGadget, Aug 28, 2021
  19. Elijah NewrenAug 28, 2021
  20. Philippe BlainAug 28, 2021
  21. 3/3 test-lib-functions: optionally keep HOME and TERM in 'debug'Philippe Blain via GitGitGadget, Aug 28, 2021
  22. 0/3 test-lib-functions.sh: keep user's HOME, TERM and SHELL for 'test_pause' and 'debug'Philippe Blain via GitGitGadget, Sep 1, 2021
  23. 2/3 test-lib-functions: optionally keep HOME, TERM and SHELL in 'test_pause'Philippe Blain via GitGitGadget, Sep 1, 2021
  24. Junio C HamanoSep 1, 2021
  25. Elijah NewrenSep 1, 2021
  26. Junio C HamanoSep 1, 2021
  27. Philippe BlainSep 2, 2021
  28. 1/3 test-lib-functions: use 'TEST_SHELL_PATH' in 'test_pause'Philippe Blain via GitGitGadget, Sep 1, 2021
  29. Junio C HamanoSep 1, 2021
  30. 3/3 test-lib-functions: optionally keep HOME and TERM in 'debug'Philippe Blain via GitGitGadget, Sep 1, 2021
  31. 0/3 test-lib-functions.sh: keep user's HOME, TERM and SHELL for 'test_pause' and 'debug'Philippe Blain via GitGitGadget, Sep 6, 2021
  32. 1/3 test-lib-functions: use 'TEST_SHELL_PATH' in 'test_pause'Philippe Blain via GitGitGadget, Sep 6, 2021
  33. 2/3 test-lib-functions: optionally keep HOME, TERM and SHELL in 'test_pause'Philippe Blain via GitGitGadget, Sep 6, 2021
  34. 3/3 test-lib-functions: keep user's debugger config files and TERM in 'debug'Philippe Blain via GitGitGadget, Sep 6, 2021
  35. 0/3 test-lib-functions.sh: keep user's HOME, TERM and SHELL for 'test_pause' and 'debug'Philippe Blain via GitGitGadget, Sep 6, 2021
  36. 1/3 test-lib-functions: use 'TEST_SHELL_PATH' in 'test_pause'Philippe Blain via GitGitGadget, Sep 6, 2021
  37. 2/3 test-lib-functions: optionally keep HOME, TERM and SHELL in 'test_pause'Philippe Blain via GitGitGadget, Sep 6, 2021
  38. 3/3 test-lib-functions: keep user's debugger config files and TERM in 'debug'Philippe Blain via GitGitGadget, Sep 6, 2021
  39. Elijah NewrenSep 7, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.