Merge branch 'dl/test-must-fail-fixes-5'

The effort to avoid using test_must_fail on non-git command continues.

* dl/test-must-fail-fixes-5:
  lib-submodule-update: pass 'test_must_fail' as an argument
  lib-submodule-update: prepend "git" to $command
  lib-submodule-update: consolidate --recurse-submodules
  lib-submodule-update: add space after function name
This commit is contained in:
Junio C Hamano 2020-07-06 22:09:18 -07:00
commit efafdca421
13 changed files with 121 additions and 59 deletions

View File

@ -183,7 +183,7 @@ test_git_directory_is_unchanged () {
)
}
test_git_directory_exists() {
test_git_directory_exists () {
test -e ".git/modules/$1" &&
if test -f sub1/.git
then
@ -303,13 +303,17 @@ test_submodule_content () {
# update" is run. And even then that command doesn't delete the work tree of
# a removed submodule.
#
# The first argument of the callback function will be the name of the submodule.
#
# Removing a submodule containing a .git directory must fail even when forced
# to protect the history!
# to protect the history! If we are testing this case, the second argument of
# the callback function will be 'test_must_fail', else it will be the empty
# string.
#
# Internal function; use test_submodule_switch() or
# test_submodule_forced_switch() instead.
test_submodule_switch_common() {
# Internal function; use test_submodule_switch_func(), test_submodule_switch(),
# or test_submodule_forced_switch() instead.
test_submodule_switch_common () {
command="$1"
######################### Appearing submodule #########################
# Switching to a commit letting a submodule appear creates empty dir ...
@ -443,7 +447,7 @@ test_submodule_switch_common() {
(
cd submodule_update &&
git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&
test_must_fail $command replace_sub1_with_directory &&
$command replace_sub1_with_directory test_must_fail &&
test_superproject_content origin/add_sub1 &&
test_submodule_content sub1 origin/add_sub1
)
@ -456,7 +460,7 @@ test_submodule_switch_common() {
cd submodule_update &&
git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&
replace_gitfile_with_git_dir sub1 &&
test_must_fail $command replace_sub1_with_directory &&
$command replace_sub1_with_directory test_must_fail &&
test_superproject_content origin/add_sub1 &&
test_git_directory_is_unchanged sub1 &&
test_submodule_content sub1 origin/add_sub1
@ -470,7 +474,7 @@ test_submodule_switch_common() {
(
cd submodule_update &&
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
test_must_fail $command replace_sub1_with_file &&
$command replace_sub1_with_file test_must_fail &&
test_superproject_content origin/add_sub1 &&
test_submodule_content sub1 origin/add_sub1
)
@ -484,7 +488,7 @@ test_submodule_switch_common() {
cd submodule_update &&
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
replace_gitfile_with_git_dir sub1 &&
test_must_fail $command replace_sub1_with_file &&
$command replace_sub1_with_file test_must_fail &&
test_superproject_content origin/add_sub1 &&
test_git_directory_is_unchanged sub1 &&
test_submodule_content sub1 origin/add_sub1
@ -559,15 +563,28 @@ test_submodule_switch_common() {
# conditions, set the appropriate KNOWN_FAILURE_* variable used in the tests
# below to 1.
#
# Use as follows:
# The first argument of the callback function will be the name of the submodule.
#
# Removing a submodule containing a .git directory must fail even when forced
# to protect the history! If we are testing this case, the second argument of
# the callback function will be 'test_must_fail', else it will be the empty
# string.
#
# The following example uses `git some-command` as an example command to be
# tested. It updates the worktree and index to match a target, but not any
# submodule directories.
#
# my_func () {
# target=$1
# # Do something here that updates the worktree and index to match target,
# # but not any submodule directories.
# ...prepare for `git some-command` to be run...
# $2 git some-command "$1" &&
# if test -n "$2"
# then
# return
# fi &&
# ...check the state after git some-command is run...
# }
# test_submodule_switch "my_func"
test_submodule_switch () {
# test_submodule_switch_func "my_func"
test_submodule_switch_func () {
command="$1"
test_submodule_switch_common "$command"
@ -580,17 +597,33 @@ test_submodule_switch () {
cd submodule_update &&
git branch -t add_sub1 origin/add_sub1 &&
>sub1 &&
test_must_fail $command add_sub1 &&
$command add_sub1 test_must_fail &&
test_superproject_content origin/no_submodule &&
test_must_be_empty sub1
)
'
}
# Ensures that the that the arg either contains "test_must_fail" or is empty.
may_only_be_test_must_fail () {
test -z "$1" || test "$1" = test_must_fail || die
}
git_test_func () {
may_only_be_test_must_fail "$2" &&
$2 git $gitcmd "$1"
}
test_submodule_switch () {
gitcmd="$1"
test_submodule_switch_func "git_test_func"
}
# Same as test_submodule_switch(), except that throwing away local changes in
# the superproject is allowed.
test_submodule_forced_switch () {
command="$1"
gitcmd="$1"
command="git_test_func"
KNOWN_FAILURE_FORCED_SWITCH_TESTS=1
test_submodule_switch_common "$command"
@ -631,8 +664,8 @@ test_submodule_forced_switch () {
# Internal function; use test_submodule_switch_recursing_with_args() or
# test_submodule_forced_switch_recursing_with_args() instead.
test_submodule_recursing_with_args_common() {
command="$1"
test_submodule_recursing_with_args_common () {
command="$1 --recurse-submodules"
######################### Appearing submodule #########################
# Switching to a commit letting a submodule appear checks it out ...
@ -840,7 +873,7 @@ test_submodule_recursing_with_args_common() {
# test_submodule_switch_recursing_with_args "$GIT_COMMAND"
test_submodule_switch_recursing_with_args () {
cmd_args="$1"
command="git $cmd_args --recurse-submodules"
command="git $cmd_args"
test_submodule_recursing_with_args_common "$command"
RESULTDS=success
@ -957,7 +990,7 @@ test_submodule_switch_recursing_with_args () {
# away local changes in the superproject is allowed.
test_submodule_forced_switch_recursing_with_args () {
cmd_args="$1"
command="git $cmd_args --recurse-submodules"
command="git $cmd_args"
test_submodule_recursing_with_args_common "$command"
RESULT=success

View File

@ -12,8 +12,8 @@ test_submodule_switch_recursing_with_args "read-tree -u -m"
test_submodule_forced_switch_recursing_with_args "read-tree -u --reset"
test_submodule_switch "git read-tree -u -m"
test_submodule_switch "read-tree -u -m"
test_submodule_forced_switch "git read-tree -u --reset"
test_submodule_forced_switch "read-tree -u --reset"
test_done

View File

@ -68,8 +68,8 @@ test_submodule_switch_recursing_with_args "checkout"
test_submodule_forced_switch_recursing_with_args "checkout -f"
test_submodule_switch "git checkout"
test_submodule_switch "checkout"
test_submodule_forced_switch "git checkout -f"
test_submodule_forced_switch "checkout -f"
test_done

View File

@ -17,10 +17,11 @@ git_rebase () {
git status -su >actual &&
ls -1pR * >>actual &&
test_cmp expect actual &&
git rebase "$1"
may_only_be_test_must_fail "$2" &&
$2 git rebase "$1"
}
test_submodule_switch "git_rebase"
test_submodule_switch_func "git_rebase"
git_rebase_interactive () {
git status -su >expect &&
@ -35,10 +36,11 @@ git_rebase_interactive () {
test_cmp expect actual &&
set_fake_editor &&
echo "fake-editor.sh" >.git/info/exclude &&
git rebase -i "$1"
may_only_be_test_must_fail "$2" &&
$2 git rebase -i "$1"
}
test_submodule_switch "git_rebase_interactive"
test_submodule_switch_func "git_rebase_interactive"
test_expect_success 'rebase interactive ignores modified submodules' '
test_when_finished "rm -rf super sub" &&

View File

@ -7,7 +7,7 @@ test_description='cherry-pick can handle submodules'
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
test_submodule_switch "git cherry-pick"
test_submodule_switch "cherry-pick"
test_expect_success 'unrelated submodule/file conflict is ignored' '
test_create_repo sub &&

View File

@ -15,7 +15,12 @@ git_revert () {
git status -su >expect &&
ls -1pR * >>expect &&
tar cf "$TRASH_DIRECTORY/tmp.tar" * &&
git checkout "$1" &&
may_only_be_test_must_fail "$2" &&
$2 git checkout "$1" &&
if test -n "$2"
then
return
fi &&
git revert HEAD &&
rm -rf * &&
tar xf "$TRASH_DIRECTORY/tmp.tar" &&
@ -26,6 +31,6 @@ git_revert () {
}
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
test_submodule_switch "git_revert"
test_submodule_switch_func "git_revert"
test_done

View File

@ -8,7 +8,12 @@ test_description='stash can handle submodules'
git_stash () {
git status -su >expect &&
ls -1pR * >>expect &&
git read-tree -u -m "$1" &&
may_only_be_test_must_fail "$2" &&
$2 git read-tree -u -m "$1" &&
if test -n "$2"
then
return
fi &&
git stash &&
git status -su >actual &&
ls -1pR * >>actual &&
@ -19,7 +24,7 @@ git_stash () {
KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES=1
KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
test_submodule_switch "git_stash"
test_submodule_switch_func "git_stash"
setup_basic () {
test_when_finished "rm -rf main sub" &&

View File

@ -6,15 +6,19 @@ test_description='git apply handling submodules'
. "$TEST_DIRECTORY"/lib-submodule-update.sh
apply_index () {
git diff --ignore-submodules=dirty "..$1" | git apply --index -
git diff --ignore-submodules=dirty "..$1" >diff &&
may_only_be_test_must_fail "$2" &&
$2 git apply --index diff
}
test_submodule_switch "apply_index"
test_submodule_switch_func "apply_index"
apply_3way () {
git diff --ignore-submodules=dirty "..$1" | git apply --3way -
git diff --ignore-submodules=dirty "..$1" >diff &&
may_only_be_test_must_fail "$2" &&
$2 git apply --3way diff
}
test_submodule_switch "apply_3way"
test_submodule_switch_func "apply_3way"
test_done

View File

@ -6,17 +6,21 @@ test_description='git am handling submodules'
. "$TEST_DIRECTORY"/lib-submodule-update.sh
am () {
git format-patch --stdout --ignore-submodules=dirty "..$1" | git am -
git format-patch --stdout --ignore-submodules=dirty "..$1" >patch &&
may_only_be_test_must_fail "$2" &&
$2 git am patch
}
test_submodule_switch "am"
test_submodule_switch_func "am"
am_3way () {
git format-patch --stdout --ignore-submodules=dirty "..$1" | git am --3way -
git format-patch --stdout --ignore-submodules=dirty "..$1" >patch &&
may_only_be_test_must_fail "$2" &&
$2 git am --3way patch
}
KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
test_submodule_switch "am_3way"
test_submodule_switch_func "am_3way"
test_expect_success 'setup diff.submodule' '
test_commit one &&

View File

@ -13,34 +13,38 @@ reset_branch_to_HEAD () {
git_pull () {
reset_branch_to_HEAD "$1" &&
git pull
may_only_be_test_must_fail "$2" &&
$2 git pull
}
# pulls without conflicts
test_submodule_switch "git_pull"
test_submodule_switch_func "git_pull"
git_pull_ff () {
reset_branch_to_HEAD "$1" &&
git pull --ff
may_only_be_test_must_fail "$2" &&
$2 git pull --ff
}
test_submodule_switch "git_pull_ff"
test_submodule_switch_func "git_pull_ff"
git_pull_ff_only () {
reset_branch_to_HEAD "$1" &&
git pull --ff-only
may_only_be_test_must_fail "$2" &&
$2 git pull --ff-only
}
test_submodule_switch "git_pull_ff_only"
test_submodule_switch_func "git_pull_ff_only"
git_pull_noff () {
reset_branch_to_HEAD "$1" &&
git pull --no-ff
may_only_be_test_must_fail "$2" &&
$2 git pull --no-ff
}
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
test_submodule_switch "git_pull_noff"
test_submodule_switch_func "git_pull_noff"
test_expect_success 'pull --recurse-submodule setup' '
test_create_repo child &&

View File

@ -10,7 +10,12 @@ git_bisect () {
ls -1pR * >>expect &&
tar cf "$TRASH_DIRECTORY/tmp.tar" * &&
GOOD=$(git rev-parse --verify HEAD) &&
git checkout "$1" &&
may_only_be_test_must_fail "$2" &&
$2 git checkout "$1" &&
if test -n "$2"
then
return
fi &&
echo "foo" >bar &&
git add bar &&
git commit -m "bisect bad" &&
@ -27,6 +32,6 @@ git_bisect () {
git bisect bad $BAD
}
test_submodule_switch "git_bisect"
test_submodule_switch_func "git_bisect"
test_done

View File

@ -12,10 +12,10 @@ test_submodule_switch_recursing_with_args "reset --keep"
test_submodule_forced_switch_recursing_with_args "reset --hard"
test_submodule_switch "git reset --keep"
test_submodule_switch "reset --keep"
test_submodule_switch "git reset --merge"
test_submodule_switch "reset --merge"
test_submodule_forced_switch "git reset --hard"
test_submodule_forced_switch "reset --hard"
test_done

View File

@ -6,14 +6,14 @@ test_description='merge can handle submodules'
. "$TEST_DIRECTORY"/lib-submodule-update.sh
# merges without conflicts
test_submodule_switch "git merge"
test_submodule_switch "merge"
test_submodule_switch "git merge --ff"
test_submodule_switch "merge --ff"
test_submodule_switch "git merge --ff-only"
test_submodule_switch "merge --ff-only"
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
test_submodule_switch "git merge --no-ff"
test_submodule_switch "merge --no-ff"
test_done