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

[PATCH] t7502-commit.sh: test_must_fail doesn't work with inline environment variables

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
Jun 19, 2008, 17:32 UTC
Message-ID
<JvISWq5uUteLVQOl-3QkroLV8SsQufGuWrfseMUjpYY@cipher.nrlssc.navy.mil>

When the arguments to test_must_fail() begin with a variable assignment, test_must_fail() attempts to execute the variable assignment as a command. This fails, and so test_must_fail returns with a successful status value without running the command it was intended to test.

For example, the following script:
	#!/bin/sh
	test_must_fail () {
		"$@"
		test $? -gt 0 -a $? -le 129
	}
	foo='wo adrian'
	test_must_fail foo='yo adrian' sh -c 'echo foo: $foo'
always exits zero and prints the message:
	test.sh: line 3: foo=yo adrian: command not found

Test 16 calls test_must_fail in such a way and therefore has not been testing whether git 'do[es] not fire editor in the presence of conflicts'. Fix this by reverting to the traditional negation operator '!' and accept the caveat that segfault will not be detected.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
Unless you have a better work around...
-brandon
 t/t7502-commit.sh |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index ed871a6..e3469e0 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -212,7 +212,9 @@ test_expect_success 'do not fire editor in the presence of conflicts' '
 	# Must fail due to conflict
 	test_must_fail git cherry-pick -n master &&
 	echo "editor not started" >.git/result &&
-	test_must_fail GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" git commit &&
+	# We intentionally do not use test_must_fail on the next line since the
+	# mechanism does not work when setting environment variables inline
+	! GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" git commit &&
 	test "$(cat .git/result)" = "editor not started"
 '
 
-- 
1.5.5.3
Next: Mike Hommey
Message 1 of 8 in “t7502-commit.sh: test_must_fail doesn't work with inline environment variables”
  1. t7502-commit.sh: test_must_fail doesn't work with inline environment variablesBrandon Casey, Jun 19, 2008
  2. Mike HommeyJun 19, 2008
  3. Brandon CaseyJun 19, 2008
  4. Mike HommeyJun 19, 2008
  5. Brandon CaseyJun 19, 2008
  6. Brandon CaseyJun 19, 2008
  7. Junio C HamanoJun 19, 2008
  8. Brandon CaseyJun 19, 2008

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.