t7005: use modern test style
Tests in t7005 mask Git error codes and do not use our nice test helpers. Improve that, move some code into the setup test, and drop a few old-style blank lines while at it. Best-viewed-with: --ignore-all-space Signed-off-by: D. Ben Knoble <ben.knoble+github@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
D. Ben Knoble committed
Aug 13, 2025 at 13:50 UTC
83d64df8d574a7cdfa96fa7a18194373b223fafe
1 file changed
+22
-46
t/t7005-editor.sh
+22
-46
@@ -7,62 +7,45 @@ test_description='GIT_EDITOR, core.editor, and stuff'
7
unset EDITOR VISUAL GIT_EDITOR
8
9
test_expect_success 'determine default editor' '
10
-
10
vi=$(TERM=vt100 git var GIT_EDITOR) &&
11
test -n "$vi"
13
-
12
'
13
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 &&
19
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 &&
26
35
-test_expect_success setup '
27
+ if ! test -z "$vi"
28
+ then
29
+ mv e-$vi.sh $vi
30
+ fi &&
31
32
msg="Hand-edited" &&
33
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"
35
'
36
37
TERM=dumb
38
export TERM
39
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
40
+ test_must_fail git commit --amend
41
'
42
43
test_expect_success 'dumb should prefer EDITOR to VISUAL' '
59
-
44
EDITOR=./e-EDITOR.sh &&
45
VISUAL=./e-VISUAL.sh &&
46
export EDITOR VISUAL &&
47
git commit --amend &&
64
- test "$(git show -s --format=%s)" = "Edited by EDITOR"
65
-
48
+ test_commit_message HEAD -m "Edited by EDITOR"
49
'
50
51
TERM=vt100
@@ -83,9 +66,7 @@ do
66
esac
67
test_expect_success "Using $i" '
68
git --exec-path=. commit --amend &&
86
- git show -s --pretty=oneline |
87
- sed -e "s/^[0-9a-f]* //" >actual &&
88
- test_cmp expect actual
69
+ test_commit_message HEAD expect
70
'
71
done
72
@@ -105,9 +86,7 @@ do
86
esac
87
test_expect_success "Using $i (override)" '
88
git --exec-path=. commit --amend &&
108
- git show -s --pretty=oneline |
109
- sed -e "s/^[0-9a-f]* //" >actual &&
110
- test_cmp expect actual
89
+ test_commit_message HEAD expect
90
'
91
done
92
@@ -115,17 +94,14 @@ test_expect_success 'editor with a space' '
94
echo "echo space >\"\$1\"" >"e space.sh" &&
95
chmod a+x "e space.sh" &&
96
GIT_EDITOR="./e\ space.sh" git commit --amend &&
118
- test space = "$(git show -s --pretty=format:%s)"
119
-
97
+ test_commit_message HEAD -m space
98
'
99
100
unset GIT_EDITOR
101
test_expect_success 'core.editor with a space' '
124
-
102
git config core.editor \"./e\ space.sh\" &&
103
git commit --amend &&
127
- test space = "$(git show -s --pretty=format:%s)"
128
-
104
+ test_commit_message HEAD -m space
105
'
106
107
test_done