Skip to content

Commit e200783

Browse files
drafnelgitster
authored andcommitted
t7502-commit.sh: test_must_fail doesn't work with inline environment variables
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'. A workaround is to set and export the variable in a normal way, not using one-shot notation. Because this would affect the remainder of the process, the test is done inside a subshell. Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 20827d9 commit e200783

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

t/t7502-commit.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ test_expect_success 'do not fire editor in the presence of conflicts' '
212212
# Must fail due to conflict
213213
test_must_fail git cherry-pick -n master &&
214214
echo "editor not started" >.git/result &&
215-
test_must_fail GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" git commit &&
215+
(
216+
GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" &&
217+
export GIT_EDITOR &&
218+
test_must_fail git commit
219+
) &&
216220
test "$(cat .git/result)" = "editor not started"
217221
'
218222

0 commit comments

Comments
 (0)