git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
	Vegard Nossum <vegard.nossum@oracle.com>
Subject: [PATCH 4/6] t7810: improve check of -W with user-defined function lines
Date: Sat, 18 Nov 2017 19:06:16 +0100	[thread overview]
Message-ID: <c89b1e5f-0145-ec93-c7fa-53fac1d429da@web.de> (raw)
In-Reply-To: <790c2344-a71e-7089-9000-f9b37a4a5cd9@web.de>

The check for function context (-W) together with user-defined function
line patterns reuses hello.c and pretends it's written in a language in
which function lines contain either "printf" or a trailing curly brace.
That's a bit obscure.

Make the test easier to read by adding a small PowerShell script, using
a simple, but meaningful expression, and separating out checks for
different aspects into dedicated tests instead of simply matching the
whole output byte for byte.

Also include a test for showing comments before function lines like git
diff -W does, which is currently failing because that functionality is
not implemented for git grep, yet.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 t/t7810-grep.sh | 41 +++++++++++++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 2a6679c2f5..632b905611 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -60,6 +60,18 @@ test_expect_success setup '
 		echo " line with leading space3"
 		echo "line without leading space2"
 	} >space &&
+	cat >hello.ps1 <<-\EOF &&
+	# No-op.
+	function dummy() {}
+
+	# Say hello.
+	function hello() {
+	  echo "Hello world."
+	} # hello
+
+	# Still a no-op.
+	function dummy() {}
+	EOF
 	git add . &&
 	test_tick &&
 	git commit -m initial
@@ -766,18 +778,27 @@ test_expect_success 'grep -W shows no trailing empty lines' '
 	test_cmp expected actual
 '
 
-cat >expected <<EOF
-hello.c=	printf("Hello world.\n");
-hello.c:	return 0;
-hello.c-	/* char ?? */
-EOF
-
 test_expect_success 'grep -W with userdiff' '
 	test_when_finished "rm -f .gitattributes" &&
-	git config diff.custom.xfuncname "(printf.*|})$" &&
-	echo "hello.c diff=custom" >.gitattributes &&
-	git grep -W return >actual &&
-	test_cmp expected actual
+	git config diff.custom.xfuncname "^function .*$" &&
+	echo "hello.ps1 diff=custom" >.gitattributes &&
+	git grep -W echo >function-context-userdiff-actual
+'
+
+test_expect_failure ' includes preceding comment' '
+	grep "# Say hello" function-context-userdiff-actual
+'
+
+test_expect_success ' includes function line' '
+	grep "=function hello" function-context-userdiff-actual
+'
+
+test_expect_success ' includes matching line' '
+	grep ":  echo" function-context-userdiff-actual
+'
+
+test_expect_success ' includes last line of the function' '
+	grep "} # hello" function-context-userdiff-actual
 '
 
 for threads in $(test_seq 0 10)
-- 
2.15.0

  parent reply	other threads:[~2017-11-18 18:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-18 18:01 [PATCH 0/6] show non-empty lines before functions with diff/grep -W René Scharfe
2017-11-18 18:04 ` [PATCH 1/6] t4051: add test for comments preceding function lines René Scharfe
2017-11-19  1:18   ` Eric Sunshine
2017-11-19 10:02     ` René Scharfe
2017-11-20  0:36       ` Junio C Hamano
2017-11-20 17:28         ` René Scharfe
2017-11-21  0:37           ` Junio C Hamano
2017-11-18 18:04 ` [PATCH 2/6] xdiff: factor out is_func_rec() René Scharfe
2017-11-18 18:05 ` [PATCH 3/6] xdiff: show non-empty lines before functions with -W René Scharfe
2017-11-18 18:06 ` René Scharfe [this message]
2017-11-18 18:07 ` [PATCH 5/6] grep: update boundary variable for pre-context René Scharfe
2017-11-18 18:08 ` [PATCH 6/6] grep: show non-empty lines before functions with -W René Scharfe
2017-11-20 20:39   ` Stefan Beller
2017-11-20 22:07     ` René Scharfe
2017-11-21 23:35       ` Stefan Beller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c89b1e5f-0145-ec93-c7fa-53fac1d429da@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=vegard.nossum@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).