Skip to content

Commit 3373518

Browse files
avargitster
authored andcommitted
test-lib functions: add an --append option to test_commit
Add an --append option to test_commit to append <contents> to the <file> we're writing to. This simplifies a lot of test setup, as shown in some of the tests being changed here. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 999cfc4 commit 3373518

File tree

2 files changed

+20
-33
lines changed

2 files changed

+20
-33
lines changed

t/t4203-mailmap.sh

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@ test_description='.mailmap configurations'
55
. ./test-lib.sh
66

77
test_expect_success 'setup commits and contacts file' '
8-
echo one >one &&
9-
git add one &&
10-
test_tick &&
11-
git commit -m initial &&
12-
echo two >>one &&
13-
git add one &&
14-
test_tick &&
15-
git commit --author "nick1 <[email protected]>" -m second
8+
test_commit initial one one &&
9+
test_commit --author "nick1 <[email protected]>" --append second one two
1610
'
1711

1812
test_expect_success 'check-mailmap no arguments' '
@@ -436,30 +430,11 @@ test_expect_success 'Shortlog output (complex mapping)' '
436430
437431
EOF
438432
439-
echo three >>one &&
440-
git add one &&
441-
test_tick &&
442-
git commit --author "nick2 <[email protected]>" -m third &&
443-
444-
echo four >>one &&
445-
git add one &&
446-
test_tick &&
447-
git commit --author "nick2 <[email protected]>" -m fourth &&
448-
449-
echo five >>one &&
450-
git add one &&
451-
test_tick &&
452-
git commit --author "santa <[email protected]>" -m fifth &&
453-
454-
echo six >>one &&
455-
git add one &&
456-
test_tick &&
457-
git commit --author "claus <[email protected]>" -m sixth &&
458-
459-
echo seven >>one &&
460-
git add one &&
461-
test_tick &&
462-
git commit --author "CTO <[email protected]>" -m seventh &&
433+
test_commit --author "nick2 <[email protected]>" --append third one three &&
434+
test_commit --author "nick2 <[email protected]>" --append fourth one four &&
435+
test_commit --author "santa <[email protected]>" --append fifth one five &&
436+
test_commit --author "claus <[email protected]>" --append sixth one six &&
437+
test_commit --author "CTO <[email protected]>" --append seventh one seven &&
463438
464439
cat >expect <<-EOF &&
465440
$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):

t/test-lib-functions.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ debug () {
183183
# Run all git commands in directory <dir>
184184
# --notick
185185
# Do not call test_tick before making a commit
186+
# --append
187+
# Use "echo >>" instead of "echo >" when writing "<contents>" to
188+
# "<file>"
186189
# --signoff
187190
# Invoke "git commit" with --signoff
188191
# --author=<author>
@@ -195,6 +198,7 @@ debug () {
195198

196199
test_commit () {
197200
notick= &&
201+
append= &&
198202
author= &&
199203
signoff= &&
200204
indir= &&
@@ -204,6 +208,9 @@ test_commit () {
204208
--notick)
205209
notick=yes
206210
;;
211+
--append)
212+
append=yes
213+
;;
207214
--author)
208215
author="$2"
209216
shift
@@ -223,7 +230,12 @@ test_commit () {
223230
done &&
224231
indir=${indir:+"$indir"/} &&
225232
file=${2:-"$1.t"} &&
226-
echo "${3-$1}" > "$indir$file" &&
233+
if test -n "$append"
234+
then
235+
echo "${3-$1}" >>"$indir$file"
236+
else
237+
echo "${3-$1}" >"$indir$file"
238+
fi &&
227239
git ${indir:+ -C "$indir"} add "$file" &&
228240
if test -z "$notick"
229241
then

0 commit comments

Comments
 (0)