@matheusbsbs / matheus-bagliano / commits / d5d9de1b10
Fork 0

test-lib: Replace uses of $(expr ...) by POSIX shell features.

In particular: - Test case counting can be achieved by arithmetic expansion. - The name of the test, e.g. t1234, can be computed with ${0%%} and ${0##}. Signed-off-by: Johannes Sixt <j6t@kdbg.org>

Johannes Sixt committed Feb 5, 2009 at 20:59 UTC d5d9de1b10f478b57803f5f2868ed2334c84e09b
1 file changed +11 -12
t/test-lib.sh
+11 -12
@@ -242,14 +242,14 @@ test_merge () {
242 # the text_expect_* functions instead.
243
244 test_ok_ () {
245 - test_count=$(expr "$test_count" + 1)
246 - test_success=$(expr "$test_success" + 1)
245 + test_count=$(($test_count + 1))
246 + test_success=$(($test_success + 1))
247 say_color "" " ok $test_count: $@"
248 }
249
250 test_failure_ () {
251 - test_count=$(expr "$test_count" + 1)
252 - test_failure=$(expr "$test_failure" + 1);
251 + test_count=$(($test_count + 1))
252 + test_failure=$(($test_failure + 1))
253 say_color error "FAIL $test_count: $1"
254 shift
255 echo "$@" | sed -e 's/^/ /'
@@ -257,13 +257,13 @@ test_failure_ () {
257 }
258
259 test_known_broken_ok_ () {
260 - test_count=$(expr "$test_count" + 1)
260 + test_count=$(($test_count+1))
261 test_fixed=$(($test_fixed+1))
262 say_color "" " FIXED $test_count: $@"
263 }
264
265 test_known_broken_failure_ () {
266 - test_count=$(expr "$test_count" + 1)
266 + test_count=$(($test_count+1))
267 test_broken=$(($test_broken+1))
268 say_color skip " still broken $test_count: $@"
269 }
@@ -279,12 +279,10 @@ test_run_ () {
279 }
280
281 test_skip () {
282 - this_test=$(expr "./$0" : '.*/\(t[0-9]*\)-[^/]*$')
283 - this_test="$this_test.$(expr "$test_count" + 1)"
282 to_skip=
283 for skp in $GIT_SKIP_TESTS
284 do
287 - case "$this_test" in
285 + case $this_test.$(($test_count+1)) in
286 $skp)
287 to_skip=t
288 esac
@@ -292,7 +290,7 @@ test_skip () {
290 case "$to_skip" in
291 t)
292 say_color skip >&3 "skipping test: $@"
295 - test_count=$(expr "$test_count" + 1)
293 + test_count=$(($test_count+1))
294 say_color skip "skip $test_count: $1"
295 : true
296 ;;
@@ -370,7 +368,7 @@ test_external () {
368 then
369 # Announce the script to reduce confusion about the
370 # test output that follows.
373 - say_color "" " run $(expr "$test_count" + 1): $descr ($*)"
371 + say_color "" " run $(($test_count+1)): $descr ($*)"
372 # Run command; redirect its stderr to &4 as in
373 # test_run_, but keep its stdout on our stdout even in
374 # non-verbose mode.
@@ -613,7 +611,8 @@ test_create_repo "$test"
611 # in subprocesses like git equals our $PWD (for pathname comparisons).
612 cd -P "$test" || exit 1
613
616 -this_test=$(expr "./$0" : '.*/\(t[0-9]*\)-[^/]*$')
614 +this_test=${0##*/}
615 +this_test=${this_test%%-*}
616 for skp in $GIT_SKIP_TESTS
617 do
618 to_skip=