Skip to content

Commit c6587bd

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6821d0 commit c6587bd

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

t/t3060-ls-files-with-tree.sh

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,16 @@ test_expect_success setup '
1818
1919
echo file >expected &&
2020
mkdir sub &&
21-
bad= &&
2221
for n in 0 1 2 3 4 5
2322
do
2423
for m in 0 1 2 3 4 5 6 7 8 9
2524
do
2625
num=00$n$m &&
2726
>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 &&
3731
git add . &&
3832
git commit -m "add a bunch of files" &&
3933

t/t3901-i18n-patch.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test_description='i18n settings and format-patch | am pipe'
99

1010
check_encoding () {
1111
# 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
1313
while test "$i" -le $cnt
1414
do
1515
git format-patch --encoding=UTF-8 --stdout HEAD~$i..HEAD~$j |
@@ -20,14 +20,10 @@ check_encoding () {
2020
grep "^encoding ISO8859-1" ;;
2121
*)
2222
grep "^encoding ISO8859-1"; test "$?" != 0 ;;
23-
esac || {
24-
bad=1
25-
break
26-
}
23+
esac || return 1
2724
j=$i
2825
i=$(($i+1))
2926
done
30-
(exit $bad)
3127
}
3228

3329
test_expect_success setup '

0 commit comments

Comments
 (0)