Skip to content

Commit 80d99d9

Browse files
committed
Merge branch 'dk/t7005-editor-updates'
Test clean-up. * dk/t7005-editor-updates: t7005: sanitize test environment for subsequent tests t7005: stop abusing --exec-path t7005: use modern test style
2 parents 0d8f4cc + a60203a commit 80d99d9

File tree

1 file changed

+58
-87
lines changed

1 file changed

+58
-87
lines changed

t/t7005-editor.sh

Lines changed: 58 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -7,125 +7,96 @@ test_description='GIT_EDITOR, core.editor, and stuff'
77
unset EDITOR VISUAL GIT_EDITOR
88

99
test_expect_success 'determine default editor' '
10-
1110
vi=$(TERM=vt100 git var GIT_EDITOR) &&
1211
test -n "$vi"
13-
1412
'
1513

16-
if ! expr "$vi" : '[a-z]*$' >/dev/null
17-
then
18-
vi=
19-
fi
20-
21-
for i in GIT_EDITOR core_editor EDITOR VISUAL $vi
22-
do
23-
cat >e-$i.sh <<-EOF
24-
#!$SHELL_PATH
25-
echo "Edited by $i" >"\$1"
26-
EOF
27-
chmod +x e-$i.sh
28-
done
14+
test_expect_success setup '
15+
if ! expr "$vi" : "[a-z]*$" >/dev/null
16+
then
17+
vi=
18+
fi &&
2919
30-
if ! test -z "$vi"
31-
then
32-
mv e-$vi.sh $vi
33-
fi
20+
for i in GIT_EDITOR core_editor EDITOR VISUAL $vi
21+
do
22+
write_script e-$i.sh <<-EOF || return 1
23+
echo "Edited by $i" >"\$1"
24+
EOF
25+
done &&
3426
35-
test_expect_success setup '
27+
if ! test -z "$vi"
28+
then
29+
mv e-$vi.sh $vi
30+
fi &&
3631
3732
msg="Hand-edited" &&
3833
test_commit "$msg" &&
39-
echo "$msg" >expect &&
40-
git show -s --format=%s > actual &&
41-
test_cmp expect actual
42-
34+
test_commit_message HEAD -m "$msg"
4335
'
4436

45-
TERM=dumb
46-
export TERM
4737
test_expect_success 'dumb should error out when falling back on vi' '
48-
49-
if git commit --amend
50-
then
51-
echo "Oops?"
52-
false
53-
else
54-
: happy
55-
fi
38+
test_must_fail env TERM=dumb git commit --amend
5639
'
5740

5841
test_expect_success 'dumb should prefer EDITOR to VISUAL' '
59-
60-
EDITOR=./e-EDITOR.sh &&
61-
VISUAL=./e-VISUAL.sh &&
62-
export EDITOR VISUAL &&
63-
git commit --amend &&
64-
test "$(git show -s --format=%s)" = "Edited by EDITOR"
65-
42+
TERM=dumb EDITOR=./e-EDITOR.sh VISUAL=./e-VISUAL.sh \
43+
git commit --amend &&
44+
test_commit_message HEAD -m "Edited by EDITOR"
6645
'
6746

68-
TERM=vt100
69-
export TERM
7047
for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
7148
do
72-
echo "Edited by $i" >expect
73-
unset EDITOR VISUAL GIT_EDITOR
74-
git config --unset-all core.editor
75-
case "$i" in
76-
core_editor)
77-
git config core.editor ./e-core_editor.sh
78-
;;
79-
[A-Z]*)
80-
eval "$i=./e-$i.sh"
81-
export $i
82-
;;
83-
esac
8449
test_expect_success "Using $i" '
85-
git --exec-path=. commit --amend &&
86-
git show -s --pretty=oneline |
87-
sed -e "s/^[0-9a-f]* //" >actual &&
88-
test_cmp expect actual
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"
8964
'
9065
done
9166

92-
unset EDITOR VISUAL GIT_EDITOR
93-
git config --unset-all core.editor
94-
for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
95-
do
96-
echo "Edited by $i" >expect
97-
case "$i" in
98-
core_editor)
99-
git config core.editor ./e-core_editor.sh
100-
;;
101-
[A-Z]*)
102-
eval "$i=./e-$i.sh"
103-
export $i
104-
;;
105-
esac
106-
test_expect_success "Using $i (override)" '
107-
git --exec-path=. commit --amend &&
108-
git show -s --pretty=oneline |
109-
sed -e "s/^[0-9a-f]* //" >actual &&
110-
test_cmp expect actual
111-
'
112-
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+
'
11388

11489
test_expect_success 'editor with a space' '
11590
echo "echo space >\"\$1\"" >"e space.sh" &&
11691
chmod a+x "e space.sh" &&
11792
GIT_EDITOR="./e\ space.sh" git commit --amend &&
118-
test space = "$(git show -s --pretty=format:%s)"
119-
93+
test_commit_message HEAD -m space
12094
'
12195

122-
unset GIT_EDITOR
12396
test_expect_success 'core.editor with a space' '
124-
125-
git config core.editor \"./e\ space.sh\" &&
97+
test_config core.editor \"./e\ space.sh\" &&
12698
git commit --amend &&
127-
test space = "$(git show -s --pretty=format:%s)"
128-
99+
test_commit_message HEAD -m space
129100
'
130101

131102
test_done

0 commit comments

Comments
 (0)