Skip to content

Commit

Permalink
t: simplify loop exit-code status variables
Browse files Browse the repository at this point in the history
Since shell loops may drop the exit code of failed commands
inside the loop, some tests try to keep track of the status
by setting a variable. This can end up cumbersome and hard
to read; it is much simpler to just exit directly from the
loop using "return 1" (since each case is either in a helper
function or inside a test snippet).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Mar 25, 2015
1 parent e6821d0 commit c6587bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
14 changes: 4 additions & 10 deletions t/t3060-ls-files-with-tree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,16 @@ test_expect_success setup '
echo file >expected &&
mkdir sub &&
bad= &&
for n in 0 1 2 3 4 5
do
for m in 0 1 2 3 4 5 6 7 8 9
do
num=00$n$m &&
>sub/file-$num &&
echo file-$num >>expected || {
bad=t
break
}
done && test -z "$bad" || {
bad=t
break
}
done && test -z "$bad" &&
echo file-$num >>expected ||
return 1
done
done &&
git add . &&
git commit -m "add a bunch of files" &&
Expand Down
8 changes: 2 additions & 6 deletions t/t3901-i18n-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test_description='i18n settings and format-patch | am pipe'

check_encoding () {
# Make sure characters are not corrupted
cnt="$1" header="$2" i=1 j=0 bad=0
cnt="$1" header="$2" i=1 j=0
while test "$i" -le $cnt
do
git format-patch --encoding=UTF-8 --stdout HEAD~$i..HEAD~$j |
Expand All @@ -20,14 +20,10 @@ check_encoding () {
grep "^encoding ISO8859-1" ;;
*)
grep "^encoding ISO8859-1"; test "$?" != 0 ;;
esac || {
bad=1
break
}
esac || return 1
j=$i
i=$(($i+1))
done
(exit $bad)
}

test_expect_success setup '
Expand Down

0 comments on commit c6587bd

Please sign in to comment.