t: fix &&-chaining issues around setup which might fail
authorJeff King <peff@peff.net>
Fri, 20 Mar 2015 10:10:21 +0000 (06:10 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Mar 2015 17:20:15 +0000 (10:20 -0700)
Many tests have an initial setup step that might fail based
on whether earlier tests in the script have succeeded or
not. Using a trick like "|| true" breaks the &&-chain,
missing earlier failures (and fooling --chain-lint).

We can use test_might_fail in some cases, which is correct
and makes the intent more obvious. We can also use
test_unconfig for unsetting config (and which is more
robust, as well).

The case in t9500 is an oddball. It wants to run cmd1 _or_
cmd2, and does it like:

cmd1 || cmd2 &&
other_stuff

It's not wrong in this case, but it's a bad habit to get
into, because it breaks the &&-chain if used anywhere except
at the beginning of the test (and we use the correct
solution here, putting it inside a block for precedence).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5503-tagfollow.sh
t/t6032-merge-large-rename.sh
t/t7201-co.sh
t/t7508-status.sh
t/t9500-gitweb-standalone-no-errors.sh
index f30c03885cda050f0bc704428ffa8a66932ff3fd..4ca48f02761d4379bf5e01cb862e47830ec0c5ac 100755 (executable)
@@ -139,8 +139,8 @@ EOF
 '
 
 test_expect_success 'new clone fetch master and tags' '
-       git branch -D cat
-       rm -f $U
+       test_might_fail git branch -D cat &&
+       rm -f $U &&
        (
                mkdir clone2 &&
                cd clone2 &&
index 15beecc3c6391fea89ffd5f0b6a091f19f9fce19..0f792689174efda55f041b1c6b2aa14f95860772 100755 (executable)
@@ -28,10 +28,10 @@ make_text() {
 
 test_rename() {
        test_expect_success "rename ($1, $2)" '
-       n='$1'
-       expect='$2'
+       n='$1' &&
+       expect='$2' &&
        git checkout -f master &&
-       git branch -D test$n || true &&
+       test_might_fail git branch -D test$n &&
        git reset --hard initial &&
        for i in $(count $n); do
                make_text $i initial initial >$i
index eae9e5a937150d60002620c8b29293f4d7ed122f..a7fe4e675713064e6cdfe8b15dce8507aef5ced4 100755 (executable)
@@ -591,7 +591,7 @@ test_expect_success 'checkout --conflict=merge, overriding config' '
 '
 
 test_expect_success 'checkout --conflict=diff3' '
-       git config --unset merge.conflictstyle
+       test_unconfig merge.conflictstyle &&
        setup_conflicting_index &&
        echo "none of the above" >sample &&
        echo ourside >expect &&
index 0f9ad4c7e223cfbd5df8552cf19d70e9a6a74296..c3ed7cb51c9a73b5bb6152b56824e6c6b8347d2c 100755 (executable)
@@ -538,7 +538,7 @@ A  dir2/added
 ?? untracked
 EOF
 test_expect_success 'status -s -uall' '
-       git config --unset status.showuntrackedfiles
+       test_unconfig status.showuntrackedfiles &&
        git status -s -uall >output &&
        test_cmp expect output
 '
index f9f078e7b705eda275f1a1ed8642b81aecf01a53..e94b2f147a72b216a1c97d278bb9c822aed7392a 100755 (executable)
@@ -779,7 +779,10 @@ test_expect_success \
 
 test_expect_success \
        'unborn HEAD: "summary" page (with "heads" subview)' \
-       'git checkout orphan_branch || git checkout --orphan orphan_branch &&
+       '{
+               git checkout orphan_branch ||
+               git checkout --orphan orphan_branch
+        } &&
         test_when_finished "git checkout master" &&
         gitweb_run "p=.git;a=summary"'