Browse Source

Merge branch 'jk/test-lint-forbid-when-finished-in-subshell' into maint

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
maint
Junio C Hamano 9 years ago
parent
commit
4cb5488fa6
  1. 12
      t/t5801-remote-helpers.sh
  2. 2
      t/t7610-mergetool.sh
  3. 8
      t/t7800-difftool.sh
  4. 25
      t/test-lib-functions.sh

12
t/t5801-remote-helpers.sh

@ -242,13 +242,6 @@ clean_mark () { @@ -242,13 +242,6 @@ clean_mark () {
sort >$(basename "$1")
}

cmp_marks () {
test_when_finished "rm -rf git.marks testgit.marks" &&
clean_mark ".git/testgit/$1/git.marks" &&
clean_mark ".git/testgit/$1/testgit.marks" &&
test_cmp git.marks testgit.marks
}

test_expect_success 'proper failure checks for fetching' '
(cd local &&
test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
@ -258,12 +251,15 @@ test_expect_success 'proper failure checks for fetching' ' @@ -258,12 +251,15 @@ test_expect_success 'proper failure checks for fetching' '
'

test_expect_success 'proper failure checks for pushing' '
test_when_finished "rm -rf local/git.marks local/testgit.marks" &&
(cd local &&
git checkout -b crash master &&
echo crash >>file &&
git commit -a -m crash &&
test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all &&
cmp_marks origin
clean_mark ".git/testgit/origin/git.marks" &&
clean_mark ".git/testgit/origin/testgit.marks" &&
test_cmp git.marks testgit.marks
)
'


2
t/t7610-mergetool.sh

@ -174,9 +174,9 @@ test_expect_success 'mergetool skips autoresolved' ' @@ -174,9 +174,9 @@ test_expect_success 'mergetool skips autoresolved' '
'

test_expect_success 'mergetool merges all from subdir' '
test_config rerere.enabled false &&
(
cd subdir &&
test_config rerere.enabled false &&
test_must_fail git merge master &&
( yes "r" | git mergetool ../submod ) &&
( yes "d" "d" | git mergetool --no-prompt ) &&

8
t/t7800-difftool.sh

@ -492,12 +492,12 @@ test_expect_success PERL 'difftool --no-symlinks detects conflict ' ' @@ -492,12 +492,12 @@ test_expect_success PERL 'difftool --no-symlinks detects conflict ' '

test_expect_success PERL 'difftool properly honors gitlink and core.worktree' '
git submodule add ./. submod/ule &&
test_config -C submod/ule diff.tool checktrees &&
test_config -C submod/ule difftool.checktrees.cmd '\''
test -d "$LOCAL" && test -d "$REMOTE" && echo good
'\'' &&
(
cd submod/ule &&
test_config diff.tool checktrees &&
test_config difftool.checktrees.cmd '\''
test -d "$LOCAL" && test -d "$REMOTE" && echo good
'\'' &&
echo good >expect &&
git difftool --tool=checktrees --dir-diff HEAD~ >actual &&
test_cmp expect actual

25
t/test-lib-functions.sh

@ -201,7 +201,14 @@ test_chmod () { @@ -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 () { @@ -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 () { @@ -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"
}

Loading…
Cancel
Save