[PATCH 15/22] test-lib functions: add an --append option to test_commit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <avarab@xxxxxxxxx>
---
 t/t4203-mailmap.sh      | 39 +++++++--------------------------------
 t/test-lib-functions.sh | 14 +++++++++++++-
 2 files changed, 20 insertions(+), 33 deletions(-)

diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh
index 2b342d7f7c..5d92880a5a 100755
--- a/t/t4203-mailmap.sh
+++ b/t/t4203-mailmap.sh
@@ -5,14 +5,8 @@ test_description='.mailmap configurations'
 . ./test-lib.sh
 
 test_expect_success 'setup commits and contacts file' '
-	echo one >one &&
-	git add one &&
-	test_tick &&
-	git commit -m initial &&
-	echo two >>one &&
-	git add one &&
-	test_tick &&
-	git commit --author "nick1 <bugs@xxxxxxxxxx>" -m second
+	test_commit initial one one &&
+	test_commit --author "nick1 <bugs@xxxxxxxxxx>" --append second one two
 '
 
 test_expect_success 'check-mailmap no arguments' '
@@ -436,30 +430,11 @@ test_expect_success 'Shortlog output (complex mapping)' '
 	Santa Claus <santa.claus@xxxxxxxxxxxx> <me@xxxxxxxxxx>
 	EOF
 
-	echo three >>one &&
-	git add one &&
-	test_tick &&
-	git commit --author "nick2 <bugs@xxxxxxxxxx>" -m third &&
-
-	echo four >>one &&
-	git add one &&
-	test_tick &&
-	git commit --author "nick2 <nick2@xxxxxxxxxx>" -m fourth &&
-
-	echo five >>one &&
-	git add one &&
-	test_tick &&
-	git commit --author "santa <me@xxxxxxxxxx>" -m fifth &&
-
-	echo six >>one &&
-	git add one &&
-	test_tick &&
-	git commit --author "claus <me@xxxxxxxxxx>" -m sixth &&
-
-	echo seven >>one &&
-	git add one &&
-	test_tick &&
-	git commit --author "CTO <cto@xxxxxxxxxxx>" -m seventh &&
+	test_commit --author "nick2 <bugs@xxxxxxxxxx>" --append third one three &&
+	test_commit --author "nick2 <nick2@xxxxxxxxxx>" --append fourth one four &&
+	test_commit --author "santa <me@xxxxxxxxxx>" --append fifth one five &&
+	test_commit --author "claus <me@xxxxxxxxxx>" --append sixth one six &&
+	test_commit --author "CTO <cto@xxxxxxxxxxx>" --append seventh one seven &&
 
 	cat >expect <<-EOF &&
 	$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 529f6264fe..b0a5d74dc7 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -183,6 +183,9 @@ debug () {
 #	Run all git commands in directory <dir>
 #   --notick
 #	Do not call test_tick before making a commit
+#   --append
+#	Use "echo >>" instead of "echo >" when writing "<contents>" to
+#	"<file>"
 #   --signoff
 #	Invoke "git commit" with --signoff
 #   --author=<author>
@@ -195,6 +198,7 @@ debug () {
 
 test_commit () {
 	notick= &&
+	append= &&
 	author= &&
 	signoff= &&
 	indir= &&
@@ -204,6 +208,9 @@ test_commit () {
 		--notick)
 			notick=yes
 			;;
+		--append)
+			append=yes
+			;;
 		--author)
 			author="$2"
 			shift
@@ -223,7 +230,12 @@ test_commit () {
 	done &&
 	indir=${indir:+"$indir"/} &&
 	file=${2:-"$1.t"} &&
-	echo "${3-$1}" > "$indir$file" &&
+	if test -n "$append"
+	then
+		echo "${3-$1}" >>"$indir$file"
+	else
+		echo "${3-$1}" >"$indir$file"
+	fi &&
 	git ${indir:+ -C "$indir"} add "$file" &&
 	if test -z "$notick"
 	then
-- 
2.29.2.222.g5d2a92d10f8




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux