diff options
| author | Junio C Hamano <gitster@pobox.com> | 2015-10-05 12:30:17 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2015-10-05 12:30:17 -0700 |
| commit | 416e2b3d4bcc4ba4b6dc8fafa954fcfdec4fc72d (patch) | |
| tree | 57dd829a7e11c82fd121e5f67d2ec54483b3493f /t/test-lib-functions.sh | |
| parent | Merge branch 'jk/interpret-trailers-outside-a-repository' (diff) | |
| parent | test-lib-functions: detect test_when_finished in subshell (diff) | |
| download | git-416e2b3d4bcc4ba4b6dc8fafa954fcfdec4fc72d.tar.gz git-416e2b3d4bcc4ba4b6dc8fafa954fcfdec4fc72d.zip | |
Merge branch 'jk/test-lint-forbid-when-finished-in-subshell'
Because "test_when_finished" in our test framework queues the
clean-up tasks to be done in a shell variable, it should not be
used inside a subshell. Add a mechanism to allow 'bash' to catch
such uses, and fix the ones that were found.
* jk/test-lint-forbid-when-finished-in-subshell:
test-lib-functions: detect test_when_finished in subshell
t7800: don't use test_config in a subshell
test-lib-functions: support "test_config -C <dir> ..."
t5801: don't use test_when_finished in a subshell
t7610: don't use test_config in a subshell
Diffstat (limited to 't/test-lib-functions.sh')
| -rw-r--r-- | t/test-lib-functions.sh | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index e8d3c0fdbc..6dffb8bcde 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -201,7 +201,14 @@ test_chmod () { # Unset a configuration variable, but don't fail if it doesn't exist. test_unconfig () { - git config --unset-all "$@" + config_dir= + if test "$1" = -C + then + shift + config_dir=$1 + shift + fi + git ${config_dir:+-C "$config_dir"} config --unset-all "$@" config_status=$? case "$config_status" in 5) # ok, nothing to unset @@ -213,8 +220,15 @@ test_unconfig () { # Set git config, automatically unsetting it after the test is over. test_config () { - test_when_finished "test_unconfig '$1'" && - git config "$@" + config_dir= + if test "$1" = -C + then + shift + config_dir=$1 + shift + fi + test_when_finished "test_unconfig ${config_dir:+-C '$config_dir'} '$1'" && + git ${config_dir:+-C "$config_dir"} config "$@" } test_config_global () { @@ -722,6 +736,11 @@ test_seq () { # what went wrong. test_when_finished () { + # We cannot detect when we are in a subshell in general, but by + # doing so on Bash is better than nothing (the test will + # silently pass on other shells). + test "${BASH_SUBSHELL-0}" = 0 || + error "bug in test script: test_when_finished does nothing in a subshell" test_cleanup="{ $* } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup" } |
