diff mbox series

[v4,8/8] completion: add tests for git-bisect

Message ID 20240128223447.342493-9-britton.kerin@gmail.com (mailing list archive)
State Superseded
Headers show
Series completion: improvements for git-bisect | expand

Commit Message

Britton Kerin Jan. 28, 2024, 10:34 p.m. UTC
There aren't any tests for completion of git bisect and it's
subcommands.

Add tests.
---
 t/t9902-completion.sh | 135 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 135 insertions(+)

Comments

Junio C Hamano Jan. 30, 2024, 5:47 a.m. UTC | #1
Britton Leo Kerin <britton.kerin@gmail.com> writes:

> +test_expect_success 'git bisect - start subcommand arguments before double-dash are completed as revs' '
> +	(
> +		cd git-bisect &&
> +		test_completion "git bisect start " <<-\EOF
> +		HEAD Z
> +		final Z
> +		initial Z
> +		master Z
> +		EOF
> +	)
> +'

When GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set to 'main' (can be
seen as a failure in linux-gcc job in GitHub CI), this piece breaks
the test, because 'master' would not appear there in the list.

You could detect what the initial default branch name currently is
and use that branch name to dynamically generate the above list
during the test.  I do not think it is worth it, and forcing the
fixed name should be sufficient.

Perhaps like this (not tested):

diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 698e278450..26f616fcfe 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -5,6 +5,8 @@
 
 test_description='test bash completion'
 
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 . ./lib-bash.sh
 
 complete ()
Patrick Steinhardt Feb. 1, 2024, 9:55 a.m. UTC | #2
On Sun, Jan 28, 2024 at 01:34:47PM -0900, Britton Leo Kerin wrote:
> There aren't any tests for completion of git bisect and it's
> subcommands.
> 
> Add tests.

I think it would be nice if you added relevant tests directly in the
commits that introduce the new completions. E.g. add a test for the
bisect terms in the same commit where you introduce the completion for
it.

Like that you can easily add tests one by one, which decreases the
review load. Also, it serves to demonstrate both that the functionality
works and helps the reviewer to understand better what exactly you are
adding by having a nice example.

Patrick

> ---
>  t/t9902-completion.sh | 135 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 135 insertions(+)
> 
> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
> index aa9a614de3..698e278450 100755
> --- a/t/t9902-completion.sh
> +++ b/t/t9902-completion.sh
> @@ -1259,6 +1259,141 @@ test_expect_success 'git switch - with no options, complete local branches and u
>  	EOF
>  '
>  
> +test_expect_success 'git bisect - when not bisecting, complete only replay and start subcommands' '
> +	test_completion "git bisect " <<-\EOF
> +	replay Z
> +	start Z
> +	EOF
> +'
> +
> +test_expect_success 'git bisect - complete options to start subcommand' '
> +	test_completion "git bisect start --" <<-\EOF
> +	--term-new Z
> +	--term-bad Z
> +	--term-old Z
> +	--term-good Z
> +	--no-checkout Z
> +	--first-parent Z
> +	EOF
> +'
> +
> +test_expect_success 'setup for git-bisect tests requiring a repo' '
> +	git init git-bisect &&
> +	(
> +		cd git-bisect &&
> +		echo "initial contents" >file &&
> +		git add file &&
> +		git commit -am "Initial commit" &&
> +		git tag initial &&
> +		echo "new line" >>file &&
> +		git commit -am "First change" &&
> +		echo "another new line" >>file &&
> +		git commit -am "Second change" &&
> +		git tag final
> +	)
> +'
> +
> +test_expect_success 'git bisect - start subcommand arguments before double-dash are completed as revs' '
> +	(
> +		cd git-bisect &&
> +		test_completion "git bisect start " <<-\EOF
> +		HEAD Z
> +		final Z
> +		initial Z
> +		master Z
> +		EOF
> +	)
> +'
> +
> +# Note that these arguments are <pathspec>s, which in practice the fallback
> +# completion (not the git completion) later ends up completing as paths.
> +test_expect_success 'git bisect - start subcommand arguments after double-dash are not completed' '
> +	(
> +		cd git-bisect &&
> +		test_completion "git bisect start final initial -- " ""
> +	)
> +'
> +
> +test_expect_success 'setup for git-bisect tests requiring ongoing bisection' '
> +	(
> +		cd git-bisect &&
> +		git bisect start --term-new=custom_new --term-old=custom_old final initial
> +	)
> +'
> +
> +test_expect_success 'git-bisect - when bisecting all subcommands are candidates' '
> +	(
> +		cd git-bisect &&
> +		test_completion "git bisect " <<-\EOF
> +		start Z
> +		bad Z
> +		custom_new Z
> +		custom_old Z
> +		new Z
> +		good Z
> +		old Z
> +		terms Z
> +		skip Z
> +		reset Z
> +		visualize Z
> +		replay Z
> +		log Z
> +		run Z
> +		help Z
> +		EOF
> +	)
> +'
> +test_expect_success 'git-bisect - options to terms subcommand are candidates' '
> +	(
> +		cd git-bisect &&
> +		test_completion "git bisect terms --" <<-\EOF
> +		--term-bad Z
> +		--term-good Z
> +		--term-new Z
> +		--term-old Z
> +		EOF
> +	)
> +'
> +
> +test_expect_success 'git-bisect - git-log options to visualize subcommand are candidates' '
> +	(
> +		cd git-bisect &&
> +		# The completion used for git-log and here does not complete
> +		# every git-log option, so rather than hope to stay in sync
> +		# with exactly what it does we will just spot-test here.
> +		test_completion "git bisect visualize --sta" <<-\EOF &&
> +		--stat Z
> +		EOF
> +		test_completion "git bisect visualize --summar" <<-\EOF
> +		--summary Z
> +		EOF
> +	)
> +'
> +
> +test_expect_success 'git-bisect - view subcommand is not a candidate' '
> +	(
> +		cd git-bisect &&
> +		test_completion "git bisect vi" <<-\EOF
> +		visualize Z
> +		EOF
> +	)
> +'
> +
> +test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options' '
> +	(
> +		cd git-bisect &&
> +		# The completion used for git-log and here does not complete
> +		# every git-log option, so rather than hope to stay in sync
> +		# with exactly what it does we will just spot-test here.
> +		test_completion "git bisect view --sta" <<-\EOF &&
> +		--stat Z
> +		EOF
> +		test_completion "git bisect view --summar" <<-\EOF
> +		--summary Z
> +		EOF
> +	)
> +'
> +
>  test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
>  	test_completion "git checkout " <<-\EOF
>  	HEAD Z
> -- 
> 2.43.0
>
diff mbox series

Patch

diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index aa9a614de3..698e278450 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1259,6 +1259,141 @@  test_expect_success 'git switch - with no options, complete local branches and u
 	EOF
 '
 
+test_expect_success 'git bisect - when not bisecting, complete only replay and start subcommands' '
+	test_completion "git bisect " <<-\EOF
+	replay Z
+	start Z
+	EOF
+'
+
+test_expect_success 'git bisect - complete options to start subcommand' '
+	test_completion "git bisect start --" <<-\EOF
+	--term-new Z
+	--term-bad Z
+	--term-old Z
+	--term-good Z
+	--no-checkout Z
+	--first-parent Z
+	EOF
+'
+
+test_expect_success 'setup for git-bisect tests requiring a repo' '
+	git init git-bisect &&
+	(
+		cd git-bisect &&
+		echo "initial contents" >file &&
+		git add file &&
+		git commit -am "Initial commit" &&
+		git tag initial &&
+		echo "new line" >>file &&
+		git commit -am "First change" &&
+		echo "another new line" >>file &&
+		git commit -am "Second change" &&
+		git tag final
+	)
+'
+
+test_expect_success 'git bisect - start subcommand arguments before double-dash are completed as revs' '
+	(
+		cd git-bisect &&
+		test_completion "git bisect start " <<-\EOF
+		HEAD Z
+		final Z
+		initial Z
+		master Z
+		EOF
+	)
+'
+
+# Note that these arguments are <pathspec>s, which in practice the fallback
+# completion (not the git completion) later ends up completing as paths.
+test_expect_success 'git bisect - start subcommand arguments after double-dash are not completed' '
+	(
+		cd git-bisect &&
+		test_completion "git bisect start final initial -- " ""
+	)
+'
+
+test_expect_success 'setup for git-bisect tests requiring ongoing bisection' '
+	(
+		cd git-bisect &&
+		git bisect start --term-new=custom_new --term-old=custom_old final initial
+	)
+'
+
+test_expect_success 'git-bisect - when bisecting all subcommands are candidates' '
+	(
+		cd git-bisect &&
+		test_completion "git bisect " <<-\EOF
+		start Z
+		bad Z
+		custom_new Z
+		custom_old Z
+		new Z
+		good Z
+		old Z
+		terms Z
+		skip Z
+		reset Z
+		visualize Z
+		replay Z
+		log Z
+		run Z
+		help Z
+		EOF
+	)
+'
+test_expect_success 'git-bisect - options to terms subcommand are candidates' '
+	(
+		cd git-bisect &&
+		test_completion "git bisect terms --" <<-\EOF
+		--term-bad Z
+		--term-good Z
+		--term-new Z
+		--term-old Z
+		EOF
+	)
+'
+
+test_expect_success 'git-bisect - git-log options to visualize subcommand are candidates' '
+	(
+		cd git-bisect &&
+		# The completion used for git-log and here does not complete
+		# every git-log option, so rather than hope to stay in sync
+		# with exactly what it does we will just spot-test here.
+		test_completion "git bisect visualize --sta" <<-\EOF &&
+		--stat Z
+		EOF
+		test_completion "git bisect visualize --summar" <<-\EOF
+		--summary Z
+		EOF
+	)
+'
+
+test_expect_success 'git-bisect - view subcommand is not a candidate' '
+	(
+		cd git-bisect &&
+		test_completion "git bisect vi" <<-\EOF
+		visualize Z
+		EOF
+	)
+'
+
+test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options' '
+	(
+		cd git-bisect &&
+		# The completion used for git-log and here does not complete
+		# every git-log option, so rather than hope to stay in sync
+		# with exactly what it does we will just spot-test here.
+		test_completion "git bisect view --sta" <<-\EOF &&
+		--stat Z
+		EOF
+		test_completion "git bisect view --summar" <<-\EOF
+		--summary Z
+		EOF
+	)
+'
+
 test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
 	test_completion "git checkout " <<-\EOF
 	HEAD Z