Merge branch 'pb/test-use-user-env'
Teach "test_pause" and "debug" helpers to allow using the HOME and TERM environment variables the user usually uses. * pb/test-use-user-env: test-lib-functions: keep user's debugger config files and TERM in 'debug' test-lib-functions: optionally keep HOME, TERM and SHELL in 'test_pause' test-lib-functions: use 'TEST_SHELL_PATH' in 'test_pause'
This commit is contained in:
11
t/README
11
t/README
@ -753,7 +753,8 @@ Test harness library
|
|||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
There are a handful helper functions defined in the test harness
|
There are a handful helper functions defined in the test harness
|
||||||
library for your script to use.
|
library for your script to use. Some of them are listed below;
|
||||||
|
see test-lib-functions.sh for the full list and their options.
|
||||||
|
|
||||||
- test_expect_success [<prereq>] <message> <script>
|
- test_expect_success [<prereq>] <message> <script>
|
||||||
|
|
||||||
@ -799,10 +800,12 @@ library for your script to use.
|
|||||||
argument. This is primarily meant for use during the
|
argument. This is primarily meant for use during the
|
||||||
development of a new test script.
|
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
|
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
|
- test_done
|
||||||
|
|
||||||
@ -989,7 +992,7 @@ library for your script to use.
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
||||||
- test_pause
|
- test_pause [options]
|
||||||
|
|
||||||
This command is useful for writing and debugging tests and must be
|
This command is useful for writing and debugging tests and must be
|
||||||
removed before submitting. It halts the execution of the test and
|
removed before submitting. It halts the execution of the test and
|
||||||
|
@ -137,33 +137,110 @@ test_tick () {
|
|||||||
# Stop execution and start a shell. This is useful for debugging tests.
|
# Stop execution and start a shell. This is useful for debugging tests.
|
||||||
#
|
#
|
||||||
# Be sure to remove all invocations of this command before submitting.
|
# Be sure to remove all invocations of this command before submitting.
|
||||||
|
# WARNING: the shell invoked by this helper does not have the same environment
|
||||||
|
# as the one running the tests (shell variables and functions are not
|
||||||
|
# available, and the options below further modify the environment). As such,
|
||||||
|
# commands copied from a test script might behave differently than when
|
||||||
|
# running the test.
|
||||||
|
#
|
||||||
|
# Usage: test_pause [options]
|
||||||
|
# -t
|
||||||
|
# Use your original TERM instead of test-lib.sh's "dumb".
|
||||||
|
# This usually restores color output in the invoked shell.
|
||||||
|
# -s
|
||||||
|
# Invoke $SHELL instead of $TEST_SHELL_PATH.
|
||||||
|
# -h
|
||||||
|
# Use your original HOME instead of test-lib.sh's "$TRASH_DIRECTORY".
|
||||||
|
# This allows you to use your regular shell environment and Git aliases.
|
||||||
|
# CAUTION: running commands copied from a test script into the paused shell
|
||||||
|
# might result in files in your HOME being overwritten.
|
||||||
|
# -a
|
||||||
|
# Shortcut for -t -s -h
|
||||||
|
|
||||||
test_pause () {
|
test_pause () {
|
||||||
"$SHELL_PATH" <&6 >&5 2>&7
|
PAUSE_TERM=$TERM &&
|
||||||
|
PAUSE_SHELL=$TEST_SHELL_PATH &&
|
||||||
|
PAUSE_HOME=$HOME &&
|
||||||
|
while test $# != 0
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
-t)
|
||||||
|
PAUSE_TERM="$USER_TERM"
|
||||||
|
;;
|
||||||
|
-s)
|
||||||
|
PAUSE_SHELL="$SHELL"
|
||||||
|
;;
|
||||||
|
-h)
|
||||||
|
PAUSE_HOME="$USER_HOME"
|
||||||
|
;;
|
||||||
|
-a)
|
||||||
|
PAUSE_TERM="$USER_TERM"
|
||||||
|
PAUSE_SHELL="$SHELL"
|
||||||
|
PAUSE_HOME="$USER_HOME"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done &&
|
||||||
|
TERM="$PAUSE_TERM" HOME="$PAUSE_HOME" "$PAUSE_SHELL" <&6 >&5 2>&7
|
||||||
}
|
}
|
||||||
|
|
||||||
# Wrap git with a debugger. Adding this to a command can make it easier
|
# Wrap git with a debugger. Adding this to a command can make it easier
|
||||||
# to understand what is going on in a failing test.
|
# 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:
|
# Examples:
|
||||||
# debug git checkout master
|
# debug git checkout master
|
||||||
# debug --debugger=nemiver git $ARGS
|
# debug --debugger=nemiver git $ARGS
|
||||||
# debug -d "valgrind --tool=memcheck --track-origins=yes" git $ARGS
|
# debug -d "valgrind --tool=memcheck --track-origins=yes" git $ARGS
|
||||||
debug () {
|
debug () {
|
||||||
case "$1" in
|
GIT_DEBUGGER=1 &&
|
||||||
-d)
|
DEBUG_TERM=$TERM &&
|
||||||
GIT_DEBUGGER="$2" &&
|
while test $# != 0
|
||||||
shift 2
|
do
|
||||||
;;
|
case "$1" in
|
||||||
--debugger=*)
|
-t)
|
||||||
GIT_DEBUGGER="${1#*=}" &&
|
DEBUG_TERM="$USER_TERM"
|
||||||
shift 1
|
;;
|
||||||
;;
|
-d)
|
||||||
*)
|
GIT_DEBUGGER="$2" &&
|
||||||
GIT_DEBUGGER=1
|
shift
|
||||||
;;
|
;;
|
||||||
esac &&
|
--debugger=*)
|
||||||
GIT_DEBUGGER="${GIT_DEBUGGER}" "$@" <&6 >&5 2>&7
|
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>]]]
|
# Usage: test_commit [options] <message> [<file> [<contents> [<tag>]]]
|
||||||
|
@ -585,8 +585,9 @@ else
|
|||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
USER_TERM="$TERM"
|
||||||
TERM=dumb
|
TERM=dumb
|
||||||
export TERM
|
export TERM USER_TERM
|
||||||
|
|
||||||
error () {
|
error () {
|
||||||
say_color error "error: $*"
|
say_color error "error: $*"
|
||||||
@ -1381,9 +1382,10 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Last-minute variable setup
|
# Last-minute variable setup
|
||||||
|
USER_HOME="$HOME"
|
||||||
HOME="$TRASH_DIRECTORY"
|
HOME="$TRASH_DIRECTORY"
|
||||||
GNUPGHOME="$HOME/gnupg-home-not-used"
|
GNUPGHOME="$HOME/gnupg-home-not-used"
|
||||||
export HOME GNUPGHOME
|
export HOME GNUPGHOME USER_HOME
|
||||||
|
|
||||||
# Test repository
|
# Test repository
|
||||||
rm -fr "$TRASH_DIRECTORY" || {
|
rm -fr "$TRASH_DIRECTORY" || {
|
||||||
|
Reference in New Issue
Block a user