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

[PATCH v3 0/5] modernize t1500

From
Eric Sunshine <sunshine@sunshineco.com>
Date
May 18, 2016, 20:15 UTC
Message-ID
<20160518201545.9113-1-sunshine@sunshineco.com>

This is a re-roll of [1] which modernizes t1500 by updating tests to set up their own needed state rather than relying upon manipulation of global state.

Changes since v2[1]:

Avoid POSIX ${dir:+-C "$dir"} since some older broken shells incorrectly expand this to a single argument ("-C <dir>") rather than the expected two (-C and "<dir>"). Thanks to Peff and SZEDER for providing links to previous reports of this problem[2][3].

Include the leading dashes in option names iterated over by the for-loop in test_rev_parse() to potentially make it easier for some future change to specify multiple options at once to git-rev-parse (SZEDER's example[4] was "git rev-parse --absolute-path --git-dir").

A v2 to v3 interdiff is included below.

[1]: http://thread.gmane.org/gmane.comp.version-control.git/294902 [2]: http://thread.gmane.org/gmane.comp.version-control.git/294902/focus=294916 [3]: http://thread.gmane.org/gmane.comp.version-control.git/294902/focus=294923 [4]: http://thread.gmane.org/gmane.comp.version-control.git/294902/focus=294971

Eric Sunshine (5):
  t1500: be considerate to future potential tests
  t1500: test_rev_parse: facilitate future test enhancements
  t1500: avoid changing working directory outside of tests
  t1500: avoid setting configuration options outside of tests
  t1500: avoid setting environment variables outside of tests
 t/t1500-rev-parse.sh | 123 ++++++++++++++++++++++++++-------------------------
 1 file changed, 63 insertions(+), 60 deletions(-)
--- >8 ---
diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 39af565..038e24c 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -5,13 +5,13 @@ test_description='test git rev-parse'
 
 # usage: [options] label is-bare is-inside-git is-inside-work prefix git-dir
 test_rev_parse () {
-	dir=
+	d=
 	bare=
 	gitdir=
 	while :
 	do
 		case "$1" in
-		-C) dir="$2"; shift; shift ;;
+		-C) d="$2"; shift; shift ;;
 		-b) case "$2" in
 		    [tfu]*) bare="$2"; shift; shift ;;
 		    *) error "test_rev_parse: bogus core.bare value '$2'" ;;
@@ -25,11 +25,11 @@ test_rev_parse () {
 	name=$1
 	shift
 
-	for o in is-bare-repository \
-		 is-inside-git-dir \
-		 is-inside-work-tree \
-		 show-prefix \
-		 git-dir
+	for o in --is-bare-repository \
+		 --is-inside-git-dir \
+		 --is-inside-work-tree \
+		 --show-prefix \
+		 --git-dir
 	do
 		test $# -eq 0 && break
 		expect="$1"
@@ -42,13 +42,13 @@ test_rev_parse () {
 			fi &&
 
 			case "$bare" in
-			t*) test_config ${dir:+-C "$dir"} core.bare true ;;
-			f*) test_config ${dir:+-C "$dir"} core.bare false ;;
-			u*) test_unconfig ${dir:+-C "$dir"} core.bare ;;
+			t*) test_config ${d:+-C} ${d:+"$d"} core.bare true ;;
+			f*) test_config ${d:+-C} ${d:+"$d"} core.bare false ;;
+			u*) test_unconfig ${d:+-C} ${d:+"$d"} core.bare ;;
 			esac &&
 
 			echo "$expect" >expect &&
-			git ${dir:+-C "$dir"} rev-parse --$o >actual &&
+			git ${d:+-C} ${d:+"$d"} rev-parse $o >actual &&
 			test_cmp expect actual
 		'
 		shift
--- >8 ---
-- 
2.8.2.748.g927f425
Next: Eric Sunshine
Message 1 of 6 in “modernize t1500”
  1. 0/5 modernize t1500Eric Sunshine, May 18, 2016
  2. 1/5 t1500: be considerate to future potential testsEric Sunshine, May 18, 2016
  3. 2/5 t1500: test_rev_parse: facilitate future test enhancementsEric Sunshine, May 18, 2016
  4. 3/5 t1500: avoid changing working directory outside of testsEric Sunshine, May 18, 2016
  5. 4/5 t1500: avoid setting configuration options outside of testsEric Sunshine, May 18, 2016
  6. 5/5 t1500: avoid setting environment variables outside of testsEric Sunshine, May 18, 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.