Skip to content

Commit 36fc7d8

Browse files
szedergitster
authored andcommitted
t6050-replace: make failing editor test more robust
'git replace --edit' should error out when the invoked editor fails, but the test checking this behavior would not notice if this weren't the case. The test in question, ever since it was added in 85f98fc (replace: add tests for --edit, 2014-05-17), has simulated a failing editor in an unconventional way: test_must_fail env GIT_EDITOR='./fakeeditor;false' git replace --edit I presume the reason for this unconventional editor was the fact that 'git replace --edit' requires the edited object to be different from the original, but a mere 'false' as editor would leave the object unchanged and 'git replace --edit' would error out anyway complaining about the new and the original object files being the same. Running 'fakeeditor' before 'false' was supposed to ensure that the object file is modified and thus 'git replace --edit' errors out because of the failed editor. However, this editor doesn't actually modify the edited object, because start_command() turns this editor into: /bin/sh -c './fakeeditor;false "$@"' './fakeeditor;false' \ '.../.git/REPLACE_EDITOBJ' This means that the test's fakeeditor script doesn't even get the path of the object to be edited as argument, triggering error messages from the commands executed inside the script ('sed' and 'mv'), and ultimately leaving the object file unchanged. If a patch were to remove the die() from the error path after launch_editor(), the test would not catch it, because 'git replace' would continue execution past launch_editor() and would error out a bit later due to the unchanged edited object. Though 'git replace' would error out for the wrong reason, this would satisfy 'test_must_fail' just as well, and the test would succeed leaving the undesired change unnoticed. Create a proper failing fake editor script for this test to ensure that the edited object is in fact modified and 'git replace --edit' won't error out because the new and original object files are the same. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c84ac8 commit 36fc7d8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

t/t6050-replace.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,15 @@ test_expect_success 'test --format long' '
351351
test_cmp expected actual
352352
'
353353

354-
test_expect_success 'setup a fake editor' '
355-
write_script fakeeditor <<-\EOF
354+
test_expect_success 'setup fake editors' '
355+
write_script fakeeditor <<-\EOF &&
356356
sed -e "s/A U Thor/A fake Thor/" "$1" >"$1.new"
357357
mv "$1.new" "$1"
358358
EOF
359+
write_script failingfakeeditor <<-\EOF
360+
./fakeeditor "$@"
361+
false
362+
EOF
359363
'
360364

361365
test_expect_success '--edit with and without already replaced object' '
@@ -372,7 +376,7 @@ test_expect_success '--edit with and without already replaced object' '
372376
test_expect_success '--edit and change nothing or command failed' '
373377
git replace -d "$PARA3" &&
374378
test_must_fail env GIT_EDITOR=true git replace --edit "$PARA3" &&
375-
test_must_fail env GIT_EDITOR="./fakeeditor;false" git replace --edit "$PARA3" &&
379+
test_must_fail env GIT_EDITOR="./failingfakeeditor" git replace --edit "$PARA3" &&
376380
GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" &&
377381
git replace -l | grep "$PARA3" &&
378382
git cat-file commit "$PARA3" | grep "A fake Thor"

0 commit comments

Comments
 (0)