Skip to content

Commit a60203a

Browse files
benknoblegitster
authored andcommitted
t7005: sanitize test environment for subsequent tests
Some of the editor tests manipulate the environment or config in ways that affect future tests, but those modifications are visible to future tests and create a footgun for them. Use test_config, subshells, single-command environment overrides, and test helpers to automatically undo environment and config modifications once finished. Best-viewed-with: --ignore-all-space Signed-off-by: D. Ben Knoble <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a9c4141 commit a60203a

File tree

1 file changed

+39
-44
lines changed

1 file changed

+39
-44
lines changed

t/t7005-editor.sh

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -34,61 +34,57 @@ test_expect_success setup '
3434
test_commit_message HEAD -m "$msg"
3535
'
3636

37-
TERM=dumb
38-
export TERM
3937
test_expect_success 'dumb should error out when falling back on vi' '
40-
test_must_fail git commit --amend
38+
test_must_fail env TERM=dumb git commit --amend
4139
'
4240

4341
test_expect_success 'dumb should prefer EDITOR to VISUAL' '
44-
EDITOR=./e-EDITOR.sh &&
45-
VISUAL=./e-VISUAL.sh &&
46-
export EDITOR VISUAL &&
47-
git commit --amend &&
42+
TERM=dumb EDITOR=./e-EDITOR.sh VISUAL=./e-VISUAL.sh \
43+
git commit --amend &&
4844
test_commit_message HEAD -m "Edited by EDITOR"
4945
'
5046

51-
TERM=vt100
52-
export TERM
5347
for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
5448
do
55-
echo "Edited by $i" >expect
56-
unset EDITOR VISUAL GIT_EDITOR
57-
git config --unset-all core.editor
58-
case "$i" in
59-
core_editor)
60-
git config core.editor ./e-core_editor.sh
61-
;;
62-
[A-Z]*)
63-
eval "$i=./e-$i.sh"
64-
export $i
65-
;;
66-
esac
6749
test_expect_success "Using $i" '
68-
PATH="$PWD:$PATH" git commit --amend &&
69-
test_commit_message HEAD expect
50+
if test "$i" = core_editor
51+
then
52+
test_config core.editor ./e-core_editor.sh
53+
fi &&
54+
(
55+
case "$i" in
56+
[A-Z]*)
57+
eval "$i=./e-$i.sh" &&
58+
export $i
59+
;;
60+
esac &&
61+
PATH="$PWD:$PATH" TERM=vt100 git commit --amend
62+
) &&
63+
test_commit_message HEAD -m "Edited by $i"
7064
'
7165
done
7266

73-
unset EDITOR VISUAL GIT_EDITOR
74-
git config --unset-all core.editor
75-
for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
76-
do
77-
echo "Edited by $i" >expect
78-
case "$i" in
79-
core_editor)
80-
git config core.editor ./e-core_editor.sh
81-
;;
82-
[A-Z]*)
83-
eval "$i=./e-$i.sh"
84-
export $i
85-
;;
86-
esac
87-
test_expect_success "Using $i (override)" '
88-
PATH="$PWD:$PATH" git commit --amend &&
89-
test_commit_message HEAD expect
90-
'
91-
done
67+
test_expect_success 'Using editors with overrides' '
68+
(
69+
TERM=vt100 &&
70+
export TERM &&
71+
for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
72+
do
73+
echo "Edited by $i" >expect &&
74+
case "$i" in
75+
core_editor)
76+
git config core.editor ./e-core_editor.sh
77+
;;
78+
[A-Z]*)
79+
eval "$i=./e-$i.sh" &&
80+
export $i
81+
;;
82+
esac &&
83+
PATH="$PWD:$PATH" git commit --amend &&
84+
test_commit_message HEAD expect || exit 1
85+
done
86+
)
87+
'
9288

9389
test_expect_success 'editor with a space' '
9490
echo "echo space >\"\$1\"" >"e space.sh" &&
@@ -97,9 +93,8 @@ test_expect_success 'editor with a space' '
9793
test_commit_message HEAD -m space
9894
'
9995

100-
unset GIT_EDITOR
10196
test_expect_success 'core.editor with a space' '
102-
git config core.editor \"./e\ space.sh\" &&
97+
test_config core.editor \"./e\ space.sh\" &&
10398
git commit --amend &&
10499
test_commit_message HEAD -m space
105100
'

0 commit comments

Comments
 (0)