diff mbox series

[06/16] test-lib functions: add an --annotated-tag option to "test_commit"

Message ID patch-06.16-8d43fdd5865-20210412T110456Z-avarab@gmail.com (mailing list archive)
State Superseded
Headers show
Series test-lib.sh: new test_commit args, simplification & fixes | expand

Commit Message

Ævar Arnfjörð Bjarmason April 12, 2021, 11:08 a.m. UTC
Add an --annotated-tag option to test_commit. The tag will share the
same message as the commit, and we'll call test_tick before creating
it (unless --notick) is provided.

There's quite a few tests that could be simplified with this
construct. I've picked one to convert in this change as a
demonstration.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1403-show-ref.sh     |  6 ++----
 t/test-lib-functions.sh | 27 ++++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 9 deletions(-)

Comments

Đoàn Trần Công Danh April 15, 2021, 3:33 p.m. UTC | #1
On 2021-04-12 13:08:55+0200, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>  	git branch B A^0
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index fa3e3e975fd..a0fcc383d0b 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -180,6 +180,10 @@ debug () {
>  #   --no-tag
>  #	Do not tag the resulting commit, if supplied giving the
>  #	optional "<tag>" argument is an error.

This comment applied to previous patch, but I think we need this patch
to justify for optional "<tag>" argument is an error for "--no-tag"

----8<----
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index a0fcc383d0..ed0a4e5e5d 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -253,6 +253,10 @@ test_commit () {
 	    $signoff -m "$1" &&
 	case "$tag" in
 	none)
+		if test -z "$4"
+		then
+			BUG "<tag> given to test_commit --no-tag"
+		fi
 		;;
 	light)
 		git ${indir:+ -C "$indir"} tag "${4:-$1}"
----8<----
> +#   --annotate
> +#	Create an annotated tag with "--annotate -m <message>". Calls
> +#	test_tick between making the commit and tag unless --notick is
> +#	given.
>  #
>  # This will commit a file with the given contents and the given commit
>  # message, and tag the resulting commit with the given tag name.
> @@ -192,7 +196,7 @@ test_commit () {
>  	author= &&
>  	signoff= &&
>  	indir= &&
> -	no_tag= &&
> +	tag=light &&
>  	while test $# != 0
>  	do
>  		case "$1" in
> @@ -220,7 +224,10 @@ test_commit () {
>  			shift
>  			;;
>  		--no-tag)
> -			no_tag=yes
> +			tag=none
> +			;;
> +		--annotate)
> +			tag=annotate
>  			;;
>  		*)
>  			break
> @@ -244,10 +251,20 @@ test_commit () {
>  	git ${indir:+ -C "$indir"} commit \
>  	    ${author:+ --author "$author"} \
>  	    $signoff -m "$1" &&
> -	if test -z "$no_tag"
> -	then
> +	case "$tag" in
> +	none)
> +		;;
> +	light)
>  		git ${indir:+ -C "$indir"} tag "${4:-$1}"
> -	fi
> +		;;
> +	annotate)
> +		if test "$tag$notick" = "annotate"

Perhap I'm missing something, however, I couldn't get the reason for
inserting "$tag" here. I wonder what wrong with:

	if test -z "$notick"
	then
		test_tick
	fi &&

> +		then
> +			test_tick
> +		fi &&
> +		git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
> +		;;
> +	esac
>  }
>  
>  # Call test_merge with the arguments "<message> <commit>", where <commit>
> -- 
> 2.31.1.634.gb41287a30b0
>
diff mbox series

Patch

diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh
index 6ce62f878c3..17d3cc14050 100755
--- a/t/t1403-show-ref.sh
+++ b/t/t1403-show-ref.sh
@@ -7,11 +7,9 @@  export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 . ./test-lib.sh
 
 test_expect_success setup '
-	test_commit A &&
-	git tag -f -a -m "annotated A" A &&
+	test_commit --annotate A &&
 	git checkout -b side &&
-	test_commit B &&
-	git tag -f -a -m "annotated B" B &&
+	test_commit --annotate B &&
 	git checkout main &&
 	test_commit C &&
 	git branch B A^0
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index fa3e3e975fd..a0fcc383d0b 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -180,6 +180,10 @@  debug () {
 #   --no-tag
 #	Do not tag the resulting commit, if supplied giving the
 #	optional "<tag>" argument is an error.
+#   --annotate
+#	Create an annotated tag with "--annotate -m <message>". Calls
+#	test_tick between making the commit and tag unless --notick is
+#	given.
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
@@ -192,7 +196,7 @@  test_commit () {
 	author= &&
 	signoff= &&
 	indir= &&
-	no_tag= &&
+	tag=light &&
 	while test $# != 0
 	do
 		case "$1" in
@@ -220,7 +224,10 @@  test_commit () {
 			shift
 			;;
 		--no-tag)
-			no_tag=yes
+			tag=none
+			;;
+		--annotate)
+			tag=annotate
 			;;
 		*)
 			break
@@ -244,10 +251,20 @@  test_commit () {
 	git ${indir:+ -C "$indir"} commit \
 	    ${author:+ --author "$author"} \
 	    $signoff -m "$1" &&
-	if test -z "$no_tag"
-	then
+	case "$tag" in
+	none)
+		;;
+	light)
 		git ${indir:+ -C "$indir"} tag "${4:-$1}"
-	fi
+		;;
+	annotate)
+		if test "$tag$notick" = "annotate"
+		then
+			test_tick
+		fi &&
+		git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
+		;;
+	esac
 }
 
 # Call test_merge with the arguments "<message> <commit>", where <commit>