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:
Junio C Hamano 2021-09-15 13:15:26 -07:00
Родитель c76fcf3e46 01c381037c
Коммит 2b2af95908
3 изменённых файлов: 103 добавлений и 21 удалений

Просмотреть файл

@ -753,7 +753,8 @@ Test harness library
--------------------
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>
@ -799,10 +800,12 @@ library for your script to use.
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
@ -989,7 +992,7 @@ library for your script to use.
EOF
- test_pause
- test_pause [options]
This command is useful for writing and debugging tests and must be
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.
#
# 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 () {
"$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
# 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>]]]

Просмотреть файл

@ -585,8 +585,9 @@ else
}
fi
USER_TERM="$TERM"
TERM=dumb
export TERM
export TERM USER_TERM
error () {
say_color error "error: $*"
@ -1381,9 +1382,10 @@ then
fi
# Last-minute variable setup
USER_HOME="$HOME"
HOME="$TRASH_DIRECTORY"
GNUPGHOME="$HOME/gnupg-home-not-used"
export HOME GNUPGHOME
export HOME GNUPGHOME USER_HOME
# Test repository
rm -fr "$TRASH_DIRECTORY" || {