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

[PATCH v2] test-lib: simplify '--option=value' parsing

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Apr 22, 2016, 20:32 UTC
Message-ID
<1461357141-12417-1-git-send-email-szeder@ira.uka.de>
In-Reply-To
<20160422183703.GA7595@sigill.intra.peff.net>

To get the 'value' from '--option=value', test-lib.sh parses said option running 'expr' with a regexp. This involves a subshell, an external process, and a lot of non-alphanumeric characters in the regexp.

Use a much simpler POSIX-defined shell parameter expansion instead to do the same.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> I count 5 cases in my copy of test-lib.sh. I think you are missing
> "--run".

Oh, indeed, '--run' managed to hide between these -l|--l|--lo|--lon|--long patterns.

 t/test-lib.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 0b47eb6bb299..79afa8748eec 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -202,13 +202,13 @@ do
 		}
 		run_list=$1; shift ;;
 	--run=*)
-		run_list=$(expr "z$1" : 'z[^=]*=\(.*\)'); shift ;;
+		run_list=${1#--*=}; shift ;;
 	-h|--h|--he|--hel|--help)
 		help=t; shift ;;
 	-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
 		verbose=t; shift ;;
 	--verbose-only=*)
-		verbose_only=$(expr "z$1" : 'z[^=]*=\(.*\)')
+		verbose_only=${1#--*=}
 		shift ;;
 	-q|--q|--qu|--qui|--quie|--quiet)
 		# Ignore --quiet under a TAP::Harness. Saying how many tests
@@ -222,15 +222,15 @@ do
 		valgrind=memcheck
 		shift ;;
 	--valgrind=*)
-		valgrind=$(expr "z$1" : 'z[^=]*=\(.*\)')
+		valgrind=${1#--*=}
 		shift ;;
 	--valgrind-only=*)
-		valgrind_only=$(expr "z$1" : 'z[^=]*=\(.*\)')
+		valgrind_only=${1#--*=}
 		shift ;;
 	--tee)
 		shift ;; # was handled already
 	--root=*)
-		root=$(expr "z$1" : 'z[^=]*=\(.*\)')
+		root=${1#--*=}
 		shift ;;
 	--chain-lint)
 		GIT_TEST_CHAIN_LINT=1
-- 
2.8.1.99.g5d5236f
Previous: Jeff KingNext: Junio C Hamano
Message 3 of 4 in “test-lib: simplify '--option=value' parsing”
  1. test-lib: simplify '--option=value' parsingSZEDER Gábor, Apr 22, 2016
  2. Jeff KingApr 22, 2016
  3. test-lib: simplify '--option=value' parsingSZEDER Gábor, Apr 22, 2016
  4. Junio C HamanoApr 22, 2016

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.