diff mbox series

[v3,10/30] subtree: t7900: add a test for the -h flag

Message ID 20210427211748.2607474-11-lukeshu@lukeshu.com (mailing list archive)
State Accepted
Commit b2699769792cfd56f77dfd6819d6654628176634
Headers show
Series subtree: clean up, improve UX | expand

Commit Message

Luke Shumaker April 27, 2021, 9:17 p.m. UTC
From: Luke Shumaker <lukeshu@datawire.io>

It's a dumb test, but it's surprisingly easy to break.

Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
---
 contrib/subtree/t/t7900-subtree.sh | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Ævar Arnfjörð Bjarmason April 30, 2021, 10:01 a.m. UTC | #1
On Tue, Apr 27 2021, Luke Shumaker wrote:

> From: Luke Shumaker <lukeshu@datawire.io>
>
> It's a dumb test, but it's surprisingly easy to break.
>
> Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
> ---
>  contrib/subtree/t/t7900-subtree.sh | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
> index 5c2510f1f5..9afba2f282 100755
> --- a/contrib/subtree/t/t7900-subtree.sh
> +++ b/contrib/subtree/t/t7900-subtree.sh
> @@ -37,6 +37,13 @@ last_commit_subject () {
>  	git log --pretty=format:%s -1
>  }
>  
> +test_expect_success 'shows short help text for -h' '
> +	test_expect_code 129 git subtree -h >out 2>err &&
> +	test_must_be_empty err &&
> +	grep -e "^ *or: git subtree pull" out &&
> +	grep -e --annotate out

I wonder if "grep -e --could-be-an-option-if-not-for-e" is portable,
probably....
Bagas Sanjaya April 30, 2021, 12:22 p.m. UTC | #2
On 28/04/21 04.17, Luke Shumaker wrote:
> It's a dumb test, but it's surprisingly easy to break.

Why did you say that? Very sensitive?
Luke Shumaker April 30, 2021, 4:40 p.m. UTC | #3
On Fri, 30 Apr 2021 04:01:50 -0600,
Ævar Arnfjörð Bjarmason wrote:
> 
> 
> On Tue, Apr 27 2021, Luke Shumaker wrote:
> 
> > From: Luke Shumaker <lukeshu@datawire.io>
> >
> > It's a dumb test, but it's surprisingly easy to break.
> >
> > Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
> > ---
> >  contrib/subtree/t/t7900-subtree.sh | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
> > index 5c2510f1f5..9afba2f282 100755
> > --- a/contrib/subtree/t/t7900-subtree.sh
> > +++ b/contrib/subtree/t/t7900-subtree.sh
> > @@ -37,6 +37,13 @@ last_commit_subject () {
> >  	git log --pretty=format:%s -1
> >  }
> >  
> > +test_expect_success 'shows short help text for -h' '
> > +	test_expect_code 129 git subtree -h >out 2>err &&
> > +	test_must_be_empty err &&
> > +	grep -e "^ *or: git subtree pull" out &&
> > +	grep -e --annotate out
> 
> I wonder if "grep -e --could-be-an-option-if-not-for-e" is portable,
> probably....

It's POSIX, and at least works on GNU, busybox, and macOS
(based-on-FreeBSD) grep.  If it turns out there's somewhere it doesn't
work, I'd be happy to change it, but my baseline assumption is that
it's portable.
Luke Shumaker April 30, 2021, 4:48 p.m. UTC | #4
On Fri, 30 Apr 2021 06:22:50 -0600,
Bagas Sanjaya wrote:
> 
> On 28/04/21 04.17, Luke Shumaker wrote:
> > It's a dumb test, but it's surprisingly easy to break.
> 
> Why did you say that? Very sensitive?

Because I very nearly sent v1 of this patchset with a broken '-h' flag
:)

I don't recall for certain, but I think the mistake I made was
allowing the ordering of `eval "$(echo "$OPTS_SPEC" | git rev-parse
--parseopt -- "$@")"` and `. git-sh-setup` to get flipped.  That
certainly will break '-h', anyway.
diff mbox series

Patch

diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 5c2510f1f5..9afba2f282 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -37,6 +37,13 @@  last_commit_subject () {
 	git log --pretty=format:%s -1
 }
 
+test_expect_success 'shows short help text for -h' '
+	test_expect_code 129 git subtree -h >out 2>err &&
+	test_must_be_empty err &&
+	grep -e "^ *or: git subtree pull" out &&
+	grep -e --annotate out
+'
+
 #
 # Tests for 'git subtree add'
 #