summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hansen <rhansen@bbn.com>2014-06-04 17:01:26 -0400
committerJunio C Hamano <gitster@pobox.com>2014-06-05 14:03:00 -0700
commit1250b516461d86c828ab2f6e51c67fe636de3e9d (patch)
tree600dec5080b7d8b6f634d62173c31e2e548151e8
parentbf59d6281a95a7be900782ab6d5075b5e897808d (diff)
downloadgit-1250b516461d86c828ab2f6e51c67fe636de3e9d.tar.gz
test-lib: make it possible to override how test code is eval'd
If a command named 'test_eval_override' exists, use it instead of 'eval' to run the test code. This is needed to support zsh test cases: test-lib.sh must be sourced in sh emulation mode due to fundamental incompatibilities between the POSIX sh language and the zsh language. When a function is defined while zsh is emulating some shell, zsh notes the shell that is being emulated and records it along with the function definition. This enables zsh to temporarily re-enable the shell emulation mode whenever the function is called, allowing zsh scripts to mix and match code written for different shell languages. (This description of zsh shell emulation is not completely accurate, but it's close enough.) Because test_eval_ is defined while zsh is in sh emulation mode, the shell code passed as an argument to test_expect_success would normally be evaluated in sh emulation mode. However, with this change, it is now possible to evaluate the test code in zsh mode by adding the following line to a zsh-based test script: emulate -R zsh -c 'test_eval_override () { eval "$*"; }' With test_eval_override defined in zsh emulation mode, the call to test_eval_override from test_eval_ will temporarily cause zsh to switch from sh emulation mode to zsh emulation mode. Signed-off-by: Richard Hansen <rhansen@bbn.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--t/test-lib.sh7
1 files changed, 6 insertions, 1 deletions
diff --git a/t/test-lib.sh b/t/test-lib.sh
index c081668dfe..3779634a9e 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -414,7 +414,12 @@ maybe_setup_valgrind () {
test_eval_ () {
# This is a separate function because some tests use
# "return" to end a test_expect_success block early.
- eval </dev/null >&3 2>&4 "$*"
+ if command -v test_eval_override >/dev/null 2>&1
+ then
+ test_eval_override "$*"
+ else
+ eval "$*"
+ fi </dev/null >&3 2>&4
}
test_run_ () {