t: fix &&-chaining issues around setup which might fail

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>
This commit is contained in:
Jeff King 2015-03-20 06:10:21 -04:00 committed by Junio C Hamano
parent 0a5e3c50de
commit a6a4a88af0
5 changed files with 11 additions and 8 deletions

View file

@ -139,8 +139,8 @@ EOF
' '
test_expect_success 'new clone fetch master and tags' ' test_expect_success 'new clone fetch master and tags' '
git branch -D cat test_might_fail git branch -D cat &&
rm -f $U rm -f $U &&
( (
mkdir clone2 && mkdir clone2 &&
cd clone2 && cd clone2 &&

View file

@ -28,10 +28,10 @@ make_text() {
test_rename() { test_rename() {
test_expect_success "rename ($1, $2)" ' test_expect_success "rename ($1, $2)" '
n='$1' n='$1' &&
expect='$2' expect='$2' &&
git checkout -f master && git checkout -f master &&
git branch -D test$n || true && test_might_fail git branch -D test$n &&
git reset --hard initial && git reset --hard initial &&
for i in $(count $n); do for i in $(count $n); do
make_text $i initial initial >$i make_text $i initial initial >$i

View file

@ -591,7 +591,7 @@ test_expect_success 'checkout --conflict=merge, overriding config' '
' '
test_expect_success 'checkout --conflict=diff3' ' test_expect_success 'checkout --conflict=diff3' '
git config --unset merge.conflictstyle test_unconfig merge.conflictstyle &&
setup_conflicting_index && setup_conflicting_index &&
echo "none of the above" >sample && echo "none of the above" >sample &&
echo ourside >expect && echo ourside >expect &&

View file

@ -538,7 +538,7 @@ A dir2/added
?? untracked ?? untracked
EOF EOF
test_expect_success 'status -s -uall' ' test_expect_success 'status -s -uall' '
git config --unset status.showuntrackedfiles test_unconfig status.showuntrackedfiles &&
git status -s -uall >output && git status -s -uall >output &&
test_cmp expect output test_cmp expect output
' '

View file

@ -779,7 +779,10 @@ test_expect_success \
test_expect_success \ test_expect_success \
'unborn HEAD: "summary" page (with "heads" subview)' \ '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" && test_when_finished "git checkout master" &&
gitweb_run "p=.git;a=summary"' gitweb_run "p=.git;a=summary"'