Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-07-07 08:09:18 +0300
committerJunio C Hamano <gitster@pobox.com>2020-07-07 08:09:18 +0300
commitefafdca42162843e90cefdeefd8e6c244cee91f5 (patch)
tree7cdfdc1a5604687c08b0a606af013d616877b028 /t/lib-submodule-update.sh
parent0a23331aa6bac1447d7983111d9c3efbea970cb3 (diff)
parent5b0ac09fb17656553d85c7e3fbe0583ba3023e5e (diff)
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
Diffstat (limited to 't/lib-submodule-update.sh')
-rw-r--r--t/lib-submodule-update.sh75
1 files changed, 54 insertions, 21 deletions
diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 64fc6487dd..07c822c8ff 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -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