git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jan 12, 2021, 20:17 UTC
Message-ID
<20210112201806.13284-16-avarab@gmail.com>
In-Reply-To
<20210105130359.21139-1-avarab@gmail.com>

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@gmail.com>
---
 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@company.xx>" -m second
+	test_commit initial one one &&
+	test_commit --author "nick1 <bugs@company.xx>" --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@northpole.xx> <me@company.xx>
 	EOF
 
-	echo three >>one &&
-	git add one &&
-	test_tick &&
-	git commit --author "nick2 <bugs@company.xx>" -m third &&
-
-	echo four >>one &&
-	git add one &&
-	test_tick &&
-	git commit --author "nick2 <nick2@company.xx>" -m fourth &&
-
-	echo five >>one &&
-	git add one &&
-	test_tick &&
-	git commit --author "santa <me@company.xx>" -m fifth &&
-
-	echo six >>one &&
-	git add one &&
-	test_tick &&
-	git commit --author "claus <me@company.xx>" -m sixth &&
-
-	echo seven >>one &&
-	git add one &&
-	test_tick &&
-	git commit --author "CTO <cto@coompany.xx>" -m seventh &&
+	test_commit --author "nick2 <bugs@company.xx>" --append third one three &&
+	test_commit --author "nick2 <nick2@company.xx>" --append fourth one four &&
+	test_commit --author "santa <me@company.xx>" --append fifth one five &&
+	test_commit --author "claus <me@company.xx>" --append sixth one six &&
+	test_commit --author "CTO <cto@coompany.xx>" --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
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 11 of 50 in “git-shortlog: make common repository prefix configurable with .mailmap”
  1. 2/2 git-shortlog: make common repository prefix configurable with .mailmapJunio C Hamano, Nov 25, 2006
  2. shortlog: remove unused(?) "repo-abbrev" featureÆvar Arnfjörð Bjarmason, Jan 5, 2021
  3. Linus TorvaldsJan 5, 2021
  4. Martin ÅgrenJan 5, 2021
  5. Junio C HamanoJan 5, 2021
  6. 20/22 mailmap tests: add tests for empty "<>" syntaxÆvar Arnfjörð Bjarmason, Jan 12, 2021
  7. 19/22 mailmap tests: add tests for whitespace syntaxÆvar Arnfjörð Bjarmason, Jan 12, 2021
  8. 21/22 mailmap doc + tests: document and test for case-insensitivityÆvar Arnfjörð Bjarmason, Jan 12, 2021
  9. 22/22 shortlog: remove unused(?) "repo-abbrev" featureÆvar Arnfjörð Bjarmason, Jan 12, 2021
  10. 16/22 tests: refactor a few tests to use "test_commit --append"Ævar Arnfjörð Bjarmason, Jan 12, 2021
  11. 15/22 test-lib functions: add an --append option to test_commitÆvar Arnfjörð Bjarmason, Jan 12, 2021
  12. 09/22 mailmap tests: add a test for "not a blob" errorÆvar Arnfjörð Bjarmason, Jan 12, 2021
  13. Junio C HamanoJan 12, 2021
  14. 12/22 test-lib functions: expand "test_commit" comment templateÆvar Arnfjörð Bjarmason, Jan 12, 2021
  15. 11/22 mailmap: test for silent exiting on missing file/blobÆvar Arnfjörð Bjarmason, Jan 12, 2021
  16. 14/22 test-lib functions: add --author support to test_commitÆvar Arnfjörð Bjarmason, Jan 12, 2021
  17. Junio C HamanoJan 12, 2021
  18. Denton LiuJan 14, 2021
  19. 13/22 test-lib functions: document arguments to test_commitÆvar Arnfjörð Bjarmason, Jan 12, 2021
  20. 10/22 mailmap tests: get rid of overly complex blame fuzzingÆvar Arnfjörð Bjarmason, Jan 12, 2021
  21. Junio C HamanoJan 12, 2021
  22. Junio C HamanoJan 14, 2021
  23. 08/22 mailmap tests: remove redundant entry in testÆvar Arnfjörð Bjarmason, Jan 12, 2021
  24. 07/22 mailmap tests: improve --stdin testsÆvar Arnfjörð Bjarmason, Jan 12, 2021
  25. 17/22 mailmap doc + tests: add better examples & test themÆvar Arnfjörð Bjarmason, Jan 12, 2021
  26. 18/22 mailmap tests: add a test for comment syntaxÆvar Arnfjörð Bjarmason, Jan 12, 2021
  27. 06/22 mailmap tests: modernize syntax & test idiomsÆvar Arnfjörð Bjarmason, Jan 12, 2021
  28. Denton LiuJan 14, 2021
  29. Junio C HamanoJan 14, 2021
  30. 05/22 mailmap tests: use our preferred whitespace syntaxÆvar Arnfjörð Bjarmason, Jan 12, 2021
  31. 04/22 mailmap doc: start by mentioning the comment syntaxÆvar Arnfjörð Bjarmason, Jan 12, 2021
  32. 03/22 check-mailmap doc: note config optionsÆvar Arnfjörð Bjarmason, Jan 12, 2021
  33. 01/22 mailmap doc: create a new "gitmailmap(5)" man pageÆvar Arnfjörð Bjarmason, Jan 12, 2021
  34. Philippe BlainJan 14, 2021
  35. Junio C HamanoJan 14, 2021
  36. Philippe BlainJan 15, 2021
  37. Junio C HamanoJan 15, 2021
  38. Philippe BlainJan 15, 2021
  39. Junio C HamanoJan 15, 2021
  40. fixup! mailmap doc: create a new "gitmailmap(5)" man pagePhilippe Blain, Jan 15, 2021
  41. mailmap doc: use correct environment variable 'GIT_WORK_TREE'Philippe Blain, Jan 15, 2021
  42. 00/22 mailmap: doc + test fixesÆvar Arnfjörð Bjarmason, Jan 12, 2021
  43. Junio C HamanoJan 12, 2021
  44. Ævar Arnfjörð BjarmasonJan 14, 2021
  45. 0/2 mailmap: test cleanupDenton Liu, Jan 14, 2021
  46. 1/2 test-lib-functions.sh: fix usage for test_commit()Denton Liu, Jan 14, 2021
  47. Ævar Arnfjörð BjarmasonJan 15, 2021
  48. 2/2 t4203: stop losing return codes of git commandsDenton Liu, Jan 14, 2021
  49. Ævar Arnfjörð BjarmasonJan 15, 2021
  50. 02/22 mailmap doc: quote config variables `like.this`Ævar Arnfjörð Bjarmason, Jan 12, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.