summaryrefslogtreecommitdiff
path: root/t/t2018-checkout-branch.sh
diff options
context:
space:
mode:
authorDenton Liu <liu.denton@gmail.com>2020-01-07 04:53:02 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-01-27 20:56:02 (GMT)
commit30c0367668ab919cc1bca3cff73820f77b573765 (patch)
tree9977dec4944c1818493a1cacb2ca28432d02675b /t/t2018-checkout-branch.sh
parent40caa5366a84fba6e64ea32bf98d9c1aba0c537b (diff)
downloadgit-30c0367668ab919cc1bca3cff73820f77b573765.zip
git-30c0367668ab919cc1bca3cff73820f77b573765.tar.gz
git-30c0367668ab919cc1bca3cff73820f77b573765.tar.bz2
t2018: teach do_checkout() to accept `!` arg
We are running `test_must_fail do_checkout`. However, `test_must_fail` should only be used on git commands. Teach do_checkout() to accept `!` as a potential first argument which will cause the function to expect the "git checkout" to fail. This increases the granularity of the test as, instead of blindly checking that do_checkout() failed, we check that only the specific expected invocation of git fails. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t2018-checkout-branch.sh')
-rwxr-xr-xt/t2018-checkout-branch.sh29
1 files changed, 21 insertions, 8 deletions
diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh
index 7ca55ef..687ab67 100755
--- a/t/t2018-checkout-branch.sh
+++ b/t/t2018-checkout-branch.sh
@@ -4,7 +4,7 @@ test_description='checkout'
. ./test-lib.sh
-# Arguments: <branch> <sha> [<checkout options>]
+# Arguments: [!] <branch> <sha> [<checkout options>]
#
# Runs "git checkout" to switch to <branch>, testing that
#
@@ -12,7 +12,16 @@ test_description='checkout'
# 2) HEAD is <sha>; if <sha> is not specified, the old HEAD is used.
#
# If <checkout options> is not specified, "git checkout" is run with -b.
+#
+# If the first argument is `!`, "git checkout" is expected to fail when
+# it is run.
do_checkout () {
+ should_fail= &&
+ if test "x$1" = "x!"
+ then
+ should_fail=yes &&
+ shift
+ fi &&
exp_branch=$1 &&
exp_ref="refs/heads/$exp_branch" &&
@@ -27,10 +36,14 @@ do_checkout () {
opts="$3"
fi
- git checkout $opts $exp_branch $exp_sha &&
-
- test $exp_ref = $(git rev-parse --symbolic-full-name HEAD) &&
- test $exp_sha = $(git rev-parse --verify HEAD)
+ if test -n "$should_fail"
+ then
+ test_must_fail git checkout $opts $exp_branch $exp_sha
+ else
+ git checkout $opts $exp_branch $exp_sha &&
+ test $exp_ref = $(git rev-parse --symbolic-full-name HEAD) &&
+ test $exp_sha = $(git rev-parse --verify HEAD)
+ fi
}
test_dirty_unmergeable () {
@@ -91,7 +104,7 @@ test_expect_success 'checkout -b to a new branch, set to an explicit ref' '
test_expect_success 'checkout -b to a new branch with unmergeable changes fails' '
setup_dirty_unmergeable &&
- test_must_fail do_checkout branch2 $HEAD1 &&
+ do_checkout ! branch2 $HEAD1 &&
test_dirty_unmergeable
'
@@ -125,7 +138,7 @@ test_expect_success 'checkout -f -b to a new branch with mergeable changes disca
test_expect_success 'checkout -b to an existing branch fails' '
test_when_finished git reset --hard HEAD &&
- test_must_fail do_checkout branch2 $HEAD2
+ do_checkout ! branch2 $HEAD2
'
test_expect_success 'checkout -b to @{-1} fails with the right branch name' '
@@ -164,7 +177,7 @@ test_expect_success 'checkout -B to an existing branch with unmergeable changes
git checkout branch1 &&
setup_dirty_unmergeable &&
- test_must_fail do_checkout branch2 $HEAD1 -B &&
+ do_checkout ! branch2 $HEAD1 -B &&
test_dirty_unmergeable
'