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

[PATCH 1/4] t6046/t9833: fix use of "VAR=VAL cmd" with a shell function

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jul 13, 2018, 05:52 UTC
Message-ID
<20180713055205.32351-2-sunshine@sunshineco.com>
In-Reply-To
<20180713055205.32351-1-sunshine@sunshineco.com>

Unlike "FOO=bar cmd" one-shot environment variable assignments which exist only for the invocation of 'cmd', those assigned by "FOO=bar shell_func" exist within the running shell and continue to do so until the process exits (or are explicitly unset). It is unlikely that this behavior was intended by the test author.

In these particular tests, the "FOO=bar shell_func" invocations are already in subshells, so the assignments don't last too long, don't appear to harm subsequent commands in the same subshells, and don't affect other tests in the same scripts, however, the usage is nevertheless misleading and poor practice, so fix the tests to assign and export the environment variables in the usual fashion.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 t/t6046-merge-skip-unneeded-updates.sh | 4 +++-
 t/t9833-errors.sh                      | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/t/t6046-merge-skip-unneeded-updates.sh b/t/t6046-merge-skip-unneeded-updates.sh
index fcefffcaec..38e24f787c 100755
--- a/t/t6046-merge-skip-unneeded-updates.sh
+++ b/t/t6046-merge-skip-unneeded-updates.sh
@@ -366,7 +366,9 @@ test_expect_success '2c-check: Modify b & add c VS rename b->c' '
 
 		git checkout A^0 &&
 
-		GIT_MERGE_VERBOSITY=3 test_must_fail git merge -s recursive B^0 >out 2>err &&
+		GIT_MERGE_VERBOSITY=3 &&
+		export GIT_MERGE_VERBOSITY &&
+		test_must_fail git merge -s recursive B^0 >out 2>err &&
 
 		test_i18ngrep "CONFLICT (rename/add): Rename b->c" out &&
 		test_i18ngrep ! "Skipped c" out &&
diff --git a/t/t9833-errors.sh b/t/t9833-errors.sh
index 9ba892de7a..277d347012 100755
--- a/t/t9833-errors.sh
+++ b/t/t9833-errors.sh
@@ -26,7 +26,9 @@ test_expect_success 'error handling' '
 	) &&
 	p4 passwd -P newpassword &&
 	(
-		P4PASSWD=badpassword test_must_fail git p4 clone //depot/foo 2>errmsg &&
+		P4PASSWD=badpassword &&
+		export P4PASSWD &&
+		test_must_fail git p4 clone //depot/foo 2>errmsg &&
 		grep -q "failure accessing depot.*P4PASSWD" errmsg
 	)
 '
-- 
2.18.0.233.g985f88cf7e
Previous: Eric SunshineNext: Eric Sunshine
Message 2 of 5 in “test-lint: detect one-shot "FOO=bar shell_func"”
  1. 0/4 test-lint: detect one-shot "FOO=bar shell_func"Eric Sunshine, Jul 13, 2018
  2. 1/4 t6046/t9833: fix use of "VAR=VAL cmd" with a shell functionEric Sunshine, Jul 13, 2018
  3. 2/4 t/check-non-portable-shell: stop being so politeEric Sunshine, Jul 13, 2018
  4. 3/4 t/check-non-portable-shell: make error messages more compactEric Sunshine, Jul 13, 2018
  5. 4/4 t/check-non-portable-shell: detect "FOO=bar shell_func"Eric Sunshine, Jul 13, 2018

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.