t: simplify loop exit-code status variables
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>
Jeff King committed
Mar 25, 2015 at 01:30 UTC
c6587bddc4e8a3ee2eef98a0a5cf15542a9cc849
2 files changed
+6
-16
t/t3060-ls-files-with-tree.sh
+4
-10
@@ -18,22 +18,16 @@ test_expect_success setup '
18
19
echo file >expected &&
20
mkdir sub &&
21
- bad= &&
21
for n in 0 1 2 3 4 5
22
do
23
for m in 0 1 2 3 4 5 6 7 8 9
24
do
25
num=00$n$m &&
26
>sub/file-$num &&
28
- echo file-$num >>expected || {
29
- bad=t
30
- break
31
- }
32
- done && test -z "$bad" || {
33
- bad=t
34
- break
35
- }
36
- done && test -z "$bad" &&
27
+ echo file-$num >>expected ||
28
+ return 1
29
+ done
30
+ done &&
31
git add . &&
32
git commit -m "add a bunch of files" &&
33
t/t3901-i18n-patch.sh
+2
-6
@@ -9,7 +9,7 @@ test_description='i18n settings and format-patch | am pipe'
9
10
check_encoding () {
11
# Make sure characters are not corrupted
12
- cnt="$1" header="$2" i=1 j=0 bad=0
12
+ cnt="$1" header="$2" i=1 j=0
13
while test "$i" -le $cnt
14
do
15
git format-patch --encoding=UTF-8 --stdout HEAD~$i..HEAD~$j |
@@ -20,14 +20,10 @@ check_encoding () {
20
grep "^encoding ISO8859-1" ;;
21
*)
22
grep "^encoding ISO8859-1"; test "$?" != 0 ;;
23
- esac || {
24
- bad=1
25
- break
26
- }
23
+ esac || return 1
24
j=$i
25
i=$(($i+1))
26
done
30
- (exit $bad)
27
}
28
29
test_expect_success setup '