diff mbox series

[v7,2/4] worktree add: refactor opt exclusion tests

Message ID 20230107045757.30037-3-jacobabel@nullpo.dev (mailing list archive)
State Superseded
Headers show
Series worktree: Support `--orphan` when creating new worktrees | expand

Commit Message

Jacob Abel Jan. 7, 2023, 4:59 a.m. UTC
Pull duplicate test code into a function so that additional opt
combinations can be tested succinctly.

Signed-off-by: Jacob Abel <jacobabel@nullpo.dev>
---
 t/t2400-worktree-add.sh | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

--
2.38.2

Comments

Junio C Hamano Jan. 8, 2023, 7:13 a.m. UTC | #1
Jacob Abel <jacobabel@nullpo.dev> writes:

> +test_wt_add_excl () {
> +	local opts="$*" &&
> +	test_expect_success "'worktree add' with '$opts' has mutually exclusive options" '
> +		test_must_fail git worktree add $opts 2>actual &&
> +		grep -P "fatal:( options)? .* cannot be used together" actual
> +	'
> +}

Of course, "grep -P" is non-portable and CI jobs are easily broken.
Isn't -E (ERE) sufficient here?
Jacob Abel Jan. 8, 2023, 3:08 p.m. UTC | #2
On 23/01/08 04:13PM, Junio C Hamano wrote:
> Jacob Abel <jacobabel@nullpo.dev> writes:
>
> > +test_wt_add_excl () {
> > +	local opts="$*" &&
> > +	test_expect_success "'worktree add' with '$opts' has mutually exclusive options" '
> > +		test_must_fail git worktree add $opts 2>actual &&
> > +		grep -P "fatal:( options)? .* cannot be used together" actual
> > +	'
> > +}
>
> Of course, "grep -P" is non-portable and CI jobs are easily broken.
> Isn't -E (ERE) sufficient here?
>
Sorry. Changed. I can push out a new revision with this applied right away if
that's acceptable.
diff mbox series

Patch

diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
index d587e0b20d..f1ae0cb268 100755
--- a/t/t2400-worktree-add.sh
+++ b/t/t2400-worktree-add.sh
@@ -298,17 +298,20 @@  test_expect_success '"add" no auto-vivify with --detach and <branch> omitted' '
 	test_must_fail git -C mish/mash symbolic-ref HEAD
 '

-test_expect_success '"add" -b/-B mutually exclusive' '
-	test_must_fail git worktree add -b poodle -B poodle bamboo main
-'
-
-test_expect_success '"add" -b/--detach mutually exclusive' '
-	test_must_fail git worktree add -b poodle --detach bamboo main
-'
+# Helper function to test mutually exclusive options.
+#
+# Note: Quoted arguments containing spaces are not supported.
+test_wt_add_excl () {
+	local opts="$*" &&
+	test_expect_success "'worktree add' with '$opts' has mutually exclusive options" '
+		test_must_fail git worktree add $opts 2>actual &&
+		grep -P "fatal:( options)? .* cannot be used together" actual
+	'
+}

-test_expect_success '"add" -B/--detach mutually exclusive' '
-	test_must_fail git worktree add -B poodle --detach bamboo main
-'
+test_wt_add_excl -b poodle -B poodle bamboo main
+test_wt_add_excl -b poodle --detach bamboo main
+test_wt_add_excl -B poodle --detach bamboo main

 test_expect_success '"add -B" fails if the branch is checked out' '
 	git rev-parse newmain >before &&