Skip to content

Commit 657e0ce

Browse files
pks-tgitster
authored andcommitted
t6002: fix use of expr with set -e
In `test_bisection_diff ()` we use `expr` to perform some math. This command has some gotchas though in that it will only return success when the result is neither null nor zero. In some of our cases though it actually _is_ zero, and that will cause the expressions to fail once we enable `set -e`. Prepare for this change by instead using `$(( ))`, which doesn't have the same issue. While at it, modernize the function a tiny bit. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3776e2b commit 657e0ce

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

t/t6002-rev-list-bisect.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ test_bisection_diff()
2727
# Test if bisection size is close to half of list size within
2828
# tolerance.
2929
#
30-
_bisect_err=$(expr $_list_size - $_bisection_size \* 2)
31-
test "$_bisect_err" -lt 0 && _bisect_err=$(expr 0 - $_bisect_err)
32-
_bisect_err=$(expr $_bisect_err / 2) ; # floor
33-
34-
test_expect_success \
35-
"bisection diff $_bisect_option $_head $* <= $_max_diff" \
36-
'test $_bisect_err -le $_max_diff'
30+
_bisect_err=$(($_list_size - $_bisection_size * 2))
31+
if test "$_bisect_err" -lt 0
32+
then
33+
_bisect_err=$((0 - $_bisect_err))
34+
fi
35+
_bisect_err=$(($_bisect_err / 2)) ; # floor
36+
37+
test_expect_success "bisection diff $_bisect_option $_head $* <= $_max_diff" '
38+
test $_bisect_err -le $_max_diff
39+
'
3740
}
3841

3942
date >path0

0 commit comments

Comments
 (0)