git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 04/10] test-lib: Replace uses of $(expr ...) by POSIX shell features.

From
Johannes Sixt <j6t@kdbg.org>
Date
Mar 18, 2009, 21:27 UTC
Message-ID
<680eb7fed78dc2ae0268f9b3adcd5978aed3ebcf.1237410682.git.j6t@kdbg.org>
In-Reply-To
<cover.1237410682.git.j6t@kdbg.org>
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>
---
 t/t4013-diff-various.sh      |    2 +-
 t/t5515-fetch-merge-logic.sh |    2 +-
 t/test-lib.sh                |   23 +++++++++++------------
 3 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 9cd5a6e..9c30b29 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -101,7 +101,7 @@ do
 	'' | '#'*) continue ;;
 	esac
 	test=`echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g'`
-	cnt=`expr $test_count + 1`
+	cnt=$(($test_count+1))
 	pfx=`printf "%04d" $cnt`
 	expect="$TEST_DIRECTORY/t4013/diff.$test"
 	actual="$pfx-diff.$test"
diff --git a/t/t5515-fetch-merge-logic.sh b/t/t5515-fetch-merge-logic.sh
index 1f4608d..0b39503 100755
--- a/t/t5515-fetch-merge-logic.sh
+++ b/t/t5515-fetch-merge-logic.sh
@@ -129,7 +129,7 @@ do
 	'' | '#'*) continue ;;
 	esac
 	test=`echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g'`
-	cnt=`expr $test_count + 1`
+	cnt=$(($test_count+1))
 	pfx=`printf "%04d" $cnt`
 	expect_f="$TEST_DIRECTORY/t5515/fetch.$test"
 	actual_f="$pfx-fetch.$test"
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 1e01a91..bd8cba1 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -242,14 +242,14 @@ test_merge () {
 # the text_expect_* functions instead.
 
 test_ok_ () {
-	test_count=$(expr "$test_count" + 1)
-	test_success=$(expr "$test_success" + 1)
+	test_count=$(($test_count + 1))
+	test_success=$(($test_success + 1))
 	say_color "" "  ok $test_count: $@"
 }
 
 test_failure_ () {
-	test_count=$(expr "$test_count" + 1)
-	test_failure=$(expr "$test_failure" + 1);
+	test_count=$(($test_count + 1))
+	test_failure=$(($test_failure + 1))
 	say_color error "FAIL $test_count: $1"
 	shift
 	echo "$@" | sed -e 's/^/	/'
@@ -257,13 +257,13 @@ test_failure_ () {
 }
 
 test_known_broken_ok_ () {
-	test_count=$(expr "$test_count" + 1)
+	test_count=$(($test_count+1))
 	test_fixed=$(($test_fixed+1))
 	say_color "" "  FIXED $test_count: $@"
 }
 
 test_known_broken_failure_ () {
-	test_count=$(expr "$test_count" + 1)
+	test_count=$(($test_count+1))
 	test_broken=$(($test_broken+1))
 	say_color skip "  still broken $test_count: $@"
 }
@@ -279,12 +279,10 @@ test_run_ () {
 }
 
 test_skip () {
-	this_test=$(expr "./$0" : '.*/\(t[0-9]*\)-[^/]*$')
-	this_test="$this_test.$(expr "$test_count" + 1)"
 	to_skip=
 	for skp in $GIT_SKIP_TESTS
 	do
-		case "$this_test" in
+		case $this_test.$(($test_count+1)) in
 		$skp)
 			to_skip=t
 		esac
@@ -292,7 +290,7 @@ test_skip () {
 	case "$to_skip" in
 	t)
 		say_color skip >&3 "skipping test: $@"
-		test_count=$(expr "$test_count" + 1)
+		test_count=$(($test_count+1))
 		say_color skip "skip $test_count: $1"
 		: true
 		;;
@@ -370,7 +368,7 @@ test_external () {
 	then
 		# Announce the script to reduce confusion about the
 		# test output that follows.
-		say_color "" " run $(expr "$test_count" + 1): $descr ($*)"
+		say_color "" " run $(($test_count+1)): $descr ($*)"
 		# Run command; redirect its stderr to &4 as in
 		# test_run_, but keep its stdout on our stdout even in
 		# non-verbose mode.
@@ -613,7 +611,8 @@ test_create_repo "$test"
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$test" || exit 1
 
-this_test=$(expr "./$0" : '.*/\(t[0-9]*\)-[^/]*$')
+this_test=${0##*/}
+this_test=${this_test%%-*}
 for skp in $GIT_SKIP_TESTS
 do
 	to_skip=
-- 
1.6.2.1.224.g2225f
Previous: Johannes SixtNext: Johannes Schindelin
Message 9 of 27 in “Test on Windows - prequel”
  1. 00/11 Test on Windows - prequelJohannes Sixt, Mar 18, 2009
  2. 01/10 t9400, t9401: Do not force hard-linked cloneJohannes Sixt, Mar 18, 2009
  3. 02/10 test suite: Use 'say' to say something instead of 'test_expect_success'Johannes Sixt, Mar 18, 2009
  4. Johannes SchindelinMar 18, 2009
  5. Johannes SixtMar 19, 2009
  6. Johannes SchindelinMar 19, 2009
  7. Junio C HamanoMar 19, 2009
  8. 03/10 Call 'say' outside test_expect_successJohannes Sixt, Mar 18, 2009
  9. 04/10 test-lib: Replace uses of $(expr ...) by POSIX shell features.Johannes Sixt, Mar 18, 2009
  10. Johannes SchindelinMar 18, 2009
  11. Johannes SixtMar 19, 2009
  12. Johannes SchindelinMar 19, 2009
  13. 05/10 test-lib: Simplify test counting.Johannes Sixt, Mar 18, 2009
  14. Johannes SchindelinMar 18, 2009
  15. Johannes SixtMar 19, 2009
  16. 06/10 test-lib: Introduce test_chmod and use it instead of update-index --chmodJohannes Sixt, Mar 18, 2009
  17. 07/10 t7300: fix clean up on WindowsJohannes Sixt, Mar 18, 2009
  18. 08/10 t2200, t7004: Avoid glob pattern that also matches filesJohannes Sixt, Mar 18, 2009
  19. Junio C HamanoMar 19, 2009
  20. Johannes SixtMar 19, 2009
  21. Junio C HamanoMar 19, 2009
  22. 09/10 t5300, t5302, t5303: Do not use /dev/zeroJohannes Sixt, Mar 18, 2009
  23. 10/10 t5602: Work around path mangling on MSYSJohannes Sixt, Mar 18, 2009
  24. Junio C HamanoMar 18, 2009
  25. Johannes SixtMar 19, 2009
  26. Johannes SixtMar 19, 2009
  27. Junio C HamanoMar 19, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.