test: facilitate debugging Git executables in tests with gdb
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 30 Oct 2015 19:02:56 +0000 (12:02 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 30 Oct 2015 21:02:38 +0000 (14:02 -0700)
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>
t/README
t/test-lib-functions.sh
wrap-for-bin.sh
index 35438bca487337e73fcb3c4fd490072793d21900..1dc908e43a993502bed611023448aa76fc9da6ad 100644 (file)
--- a/t/README
+++ b/t/README
@@ -563,6 +563,11 @@ library for your script to use.
    argument.  This is primarily meant for use during the
    development of a new test script.
 
+ - debug <git-command>
+
+   Run a git command inside a debugger. This is primarily meant for
+   use when debugging a failing test script.
+
  - test_done
 
    Your test script must have test_done at the end.  Its purpose
index 6dffb8bcde83b82fa40b05dd8ee815f4e6a3cdd3..73e37a1f6c23d00371dbd3f10aee1648e8b947bc 100644 (file)
@@ -145,6 +145,14 @@ test_pause () {
        fi
 }
 
+# Wrap git in gdb. Adding this to a command can make it easier to
+# understand what is going on in a failing test.
+#
+# Example: "debug git checkout master".
+debug () {
+        GIT_TEST_GDB=1 "$@"
+}
+
 # Call test_commit with the arguments "<message> [<file> [<contents> [<tag>]]]"
 #
 # This will commit a file with the given contents and the given commit
index 701d2339b9f5014d78ff1d5c88cfd21a1accd0c2..db0ec6a7370fd56e4e11c49a4b9e5e15f461e1f9 100644 (file)
@@ -19,4 +19,10 @@ GIT_TEXTDOMAINDIR='@@BUILD_DIR@@/po/build/locale'
 PATH='@@BUILD_DIR@@/bin-wrappers:'"$PATH"
 export GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR
 
-exec "${GIT_EXEC_PATH}/@@PROG@@" "$@"
+if test -n "$GIT_TEST_GDB"
+then
+       unset GIT_TEST_GDB
+       exec gdb --args "${GIT_EXEC_PATH}/@@PROG@@" "$@"
+else
+       exec "${GIT_EXEC_PATH}/@@PROG@@" "$@"
+fi