Skip to content

Commit 83d64df

Browse files
benknoblegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8d2709d commit 83d64df

File tree

1 file changed

+22
-46
lines changed

1 file changed

+22
-46
lines changed

t/t7005-editor.sh

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,45 @@ 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

4537
TERM=dumb
4638
export TERM
4739
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
5641
'
5742

5843
test_expect_success 'dumb should prefer EDITOR to VISUAL' '
59-
6044
EDITOR=./e-EDITOR.sh &&
6145
VISUAL=./e-VISUAL.sh &&
6246
export EDITOR VISUAL &&
6347
git commit --amend &&
64-
test "$(git show -s --format=%s)" = "Edited by EDITOR"
65-
48+
test_commit_message HEAD -m "Edited by EDITOR"
6649
'
6750

6851
TERM=vt100
@@ -83,9 +66,7 @@ do
8366
esac
8467
test_expect_success "Using $i" '
8568
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
8970
'
9071
done
9172

@@ -105,27 +86,22 @@ do
10586
esac
10687
test_expect_success "Using $i (override)" '
10788
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
11190
'
11291
done
11392

11493
test_expect_success 'editor with a space' '
11594
echo "echo space >\"\$1\"" >"e space.sh" &&
11695
chmod a+x "e space.sh" &&
11796
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
12098
'
12199

122100
unset GIT_EDITOR
123101
test_expect_success 'core.editor with a space' '
124-
125102
git config core.editor \"./e\ space.sh\" &&
126103
git commit --amend &&
127-
test space = "$(git show -s --pretty=format:%s)"
128-
104+
test_commit_message HEAD -m space
129105
'
130106

131107
test_done

0 commit comments

Comments
 (0)