diff mbox series

[14/22] test-lib functions: add --author support to test_commit

Message ID 20210112201806.13284-15-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series shortlog: remove unused(?) "repo-abbrev" feature | expand

Commit Message

Ævar Arnfjörð Bjarmason Jan. 12, 2021, 8:17 p.m. UTC
Add support for --author to "test_commit". This will simplify some
current and future tests, one of those is being changed here.

Let's also line-wrap the "git commit" command invocation to make diffs
that add subsequent options easier to add, as they'll only need to add
a new option line.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t7509-commit-authorship.sh |  7 ++-----
 t/test-lib-functions.sh      | 11 ++++++++++-
 2 files changed, 12 insertions(+), 6 deletions(-)

Comments

Junio C Hamano Jan. 12, 2021, 10:34 p.m. UTC | #1
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Add support for --author to "test_commit". This will simplify some
> current and future tests, one of those is being changed here.
>
> Let's also line-wrap the "git commit" command invocation to make diffs
> that add subsequent options easier to add, as they'll only need to add
> a new option line.

Makes sense.

> -	git commit -m "Initial Commit" --author Frigate\ \<flying@over.world\> &&
> -	git tag Initial &&
> +	test_commit --author Frigate\ \<flying@over.world\> \
> +		"Initial Commit" foo Initial Initial &&

Why not fix the value of the author while at it to be more readable?
E.g. --author "Frigate <flying@over.world>"
Denton Liu Jan. 14, 2021, 7:40 a.m. UTC | #2
Hi Ævar,

On Tue, Jan 12, 2021 at 09:17:58PM +0100, Ævar Arnfjörð Bjarmason wrote:
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 194b601bc0..529f6264fe 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -185,6 +185,8 @@ debug () {
>  #	Do not call test_tick before making a commit
>  #   --signoff
>  #	Invoke "git commit" with --signoff
> +#   --author=<author>

The usage shows that you have to specify the author argument with an
equal sign...

> +#	Invoke "git commit" with --author=<author>
>  #
>  # This will commit a file with the given contents and the given commit
>  # message, and tag the resulting commit with the given tag name.
> @@ -193,6 +195,7 @@ debug () {
>  
>  test_commit () {
>  	notick= &&
> +	author= &&
>  	signoff= &&
>  	indir= &&
>  	while test $# != 0
> @@ -201,6 +204,10 @@ test_commit () {
>  		--notick)
>  			notick=yes
>  			;;
> +		--author)
> +			author="$2"

but over here, it's only parsed if they're presented as two separate
tokens. We should correct the usage text accordingly.

Thanks,
Denton

> +			shift
> +			;;
>  		--signoff)
>  			signoff="$1"
>  			;;
diff mbox series

Patch

diff --git a/t/t7509-commit-authorship.sh b/t/t7509-commit-authorship.sh
index 500ab2fe72..ee6c47416e 100755
--- a/t/t7509-commit-authorship.sh
+++ b/t/t7509-commit-authorship.sh
@@ -18,11 +18,8 @@  message_body () {
 }
 
 test_expect_success '-C option copies authorship and message' '
-	echo "Initial" >foo &&
-	git add foo &&
-	test_tick &&
-	git commit -m "Initial Commit" --author Frigate\ \<flying@over.world\> &&
-	git tag Initial &&
+	test_commit --author Frigate\ \<flying@over.world\> \
+		"Initial Commit" foo Initial Initial &&
 	echo "Test 1" >>foo &&
 	test_tick &&
 	git commit -a -C Initial &&
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 194b601bc0..529f6264fe 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -185,6 +185,8 @@  debug () {
 #	Do not call test_tick before making a commit
 #   --signoff
 #	Invoke "git commit" with --signoff
+#   --author=<author>
+#	Invoke "git commit" with --author=<author>
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
@@ -193,6 +195,7 @@  debug () {
 
 test_commit () {
 	notick= &&
+	author= &&
 	signoff= &&
 	indir= &&
 	while test $# != 0
@@ -201,6 +204,10 @@  test_commit () {
 		--notick)
 			notick=yes
 			;;
+		--author)
+			author="$2"
+			shift
+			;;
 		--signoff)
 			signoff="$1"
 			;;
@@ -222,7 +229,9 @@  test_commit () {
 	then
 		test_tick
 	fi &&
-	git ${indir:+ -C "$indir"} commit $signoff -m "$1" &&
+	git ${indir:+ -C "$indir"} commit \
+	    ${author:+ --author "$author"} \
+	    $signoff -m "$1" &&
 	git ${indir:+ -C "$indir"} tag "${4:-$1}"
 }