git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/2] t7810: add missing variables to tests in loop
@ 2014-03-11 21:07 René Scharfe
  2014-03-11 21:15 ` [PATCH 2/2] grep: support -h (no header) with --count René Scharfe
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2014-03-11 21:07 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

Some tests in t7810-grep.sh are in a loop that runs them against HEAD and
the work tree.  In order for that to work the test code should use the
variables $L (display name), $H (HEAD or empty string) and $HC (revision
prefix for result lines); otherwise tests are just repeated with the same
target.  Add the variables where they're missing and make sure the test
description is wrapped in double quotes (instead of single quotes) to
allow variables to be expanded.

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

diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index f698001..46aaebc 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -105,7 +105,7 @@ do
 
 	test_expect_success "grep -w $L (w)" '
 		: >expected &&
-		test_must_fail git grep -n -w -e "^w" >actual &&
+		test_must_fail git grep -n -w -e "^w" $H >actual &&
 		test_cmp expected actual
 	'
 
@@ -240,92 +240,92 @@ do
 		test_cmp expected actual
 	'
 	test_expect_success "grep $L with grep.extendedRegexp=false" '
-		echo "ab:a+bc" >expected &&
-		git -c grep.extendedRegexp=false grep "a+b*c" ab >actual &&
+		echo "${HC}ab:a+bc" >expected &&
+		git -c grep.extendedRegexp=false grep "a+b*c" $H ab >actual &&
 		test_cmp expected actual
 	'
 
 	test_expect_success "grep $L with grep.extendedRegexp=true" '
-		echo "ab:abc" >expected &&
-		git -c grep.extendedRegexp=true grep "a+b*c" ab >actual &&
+		echo "${HC}ab:abc" >expected &&
+		git -c grep.extendedRegexp=true grep "a+b*c" $H ab >actual &&
 		test_cmp expected actual
 	'
 
 	test_expect_success "grep $L with grep.patterntype=basic" '
-		echo "ab:a+bc" >expected &&
-		git -c grep.patterntype=basic grep "a+b*c" ab >actual &&
+		echo "${HC}ab:a+bc" >expected &&
+		git -c grep.patterntype=basic grep "a+b*c" $H ab >actual &&
 		test_cmp expected actual
 	'
 
 	test_expect_success "grep $L with grep.patterntype=extended" '
-		echo "ab:abc" >expected &&
-		git -c grep.patterntype=extended grep "a+b*c" ab >actual &&
+		echo "${HC}ab:abc" >expected &&
+		git -c grep.patterntype=extended grep "a+b*c" $H ab >actual &&
 		test_cmp expected actual
 	'
 
 	test_expect_success "grep $L with grep.patterntype=fixed" '
-		echo "ab:a+b*c" >expected &&
-		git -c grep.patterntype=fixed grep "a+b*c" ab >actual &&
+		echo "${HC}ab:a+b*c" >expected &&
+		git -c grep.patterntype=fixed grep "a+b*c" $H ab >actual &&
 		test_cmp expected actual
 	'
 
 	test_expect_success LIBPCRE "grep $L with grep.patterntype=perl" '
-		echo "ab:a+b*c" >expected &&
-		git -c grep.patterntype=perl grep "a\x{2b}b\x{2a}c" ab >actual &&
+		echo "${HC}ab:a+b*c" >expected &&
+		git -c grep.patterntype=perl grep "a\x{2b}b\x{2a}c" $H ab >actual &&
 		test_cmp expected actual
 	'
 
 	test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" '
-		echo "ab:abc" >expected &&
+		echo "${HC}ab:abc" >expected &&
 		git \
 			-c grep.patternType=default \
 			-c grep.extendedRegexp=true \
-			grep "a+b*c" ab >actual &&
+			grep "a+b*c" $H ab >actual &&
 		test_cmp expected actual
 	'
 
 	test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=default" '
-		echo "ab:abc" >expected &&
+		echo "${HC}ab:abc" >expected &&
 		git \
 			-c grep.extendedRegexp=true \
 			-c grep.patternType=default \
-			grep "a+b*c" ab >actual &&
+			grep "a+b*c" $H ab >actual &&
 		test_cmp expected actual
 	'
 
-	test_expect_success 'grep $L with grep.patternType=extended and grep.extendedRegexp=false' '
-		echo "ab:abc" >expected &&
+	test_expect_success "grep $L with grep.patternType=extended and grep.extendedRegexp=false" '
+		echo "${HC}ab:abc" >expected &&
 		git \
 			-c grep.patternType=extended \
 			-c grep.extendedRegexp=false \
-			grep "a+b*c" ab >actual &&
+			grep "a+b*c" $H ab >actual &&
 		test_cmp expected actual
 	'
 
-	test_expect_success 'grep $L with grep.patternType=basic and grep.extendedRegexp=true' '
-		echo "ab:a+bc" >expected &&
+	test_expect_success "grep $L with grep.patternType=basic and grep.extendedRegexp=true" '
+		echo "${HC}ab:a+bc" >expected &&
 		git \
 			-c grep.patternType=basic \
 			-c grep.extendedRegexp=true \
-			grep "a+b*c" ab >actual &&
+			grep "a+b*c" $H ab >actual &&
 		test_cmp expected actual
 	'
 
-	test_expect_success 'grep $L with grep.extendedRegexp=false and grep.patternType=extended' '
-		echo "ab:abc" >expected &&
+	test_expect_success "grep $L with grep.extendedRegexp=false and grep.patternType=extended" '
+		echo "${HC}ab:abc" >expected &&
 		git \
 			-c grep.extendedRegexp=false \
 			-c grep.patternType=extended \
-			grep "a+b*c" ab >actual &&
+			grep "a+b*c" $H ab >actual &&
 		test_cmp expected actual
 	'
 
-	test_expect_success 'grep $L with grep.extendedRegexp=true and grep.patternType=basic' '
-		echo "ab:a+bc" >expected &&
+	test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=basic" '
+		echo "${HC}ab:a+bc" >expected &&
 		git \
 			-c grep.extendedRegexp=true \
 			-c grep.patternType=basic \
-			grep "a+b*c" ab >actual &&
+			grep "a+b*c" $H ab >actual &&
 		test_cmp expected actual
 	'
 done
-- 
1.9.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] grep: support -h (no header) with --count
  2014-03-11 21:07 [PATCH 1/2] t7810: add missing variables to tests in loop René Scharfe
@ 2014-03-11 21:15 ` René Scharfe
  0 siblings, 0 replies; 2+ messages in thread
From: René Scharfe @ 2014-03-11 21:15 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

Suppress printing the header (filename) with -h even if in -c/--count
mode.  GNU grep and OpenBSD's grep do the same.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 grep.c          |  7 +++++--
 t/t7810-grep.sh | 12 ++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/grep.c b/grep.c
index c668034..94f7290 100644
--- a/grep.c
+++ b/grep.c
@@ -1562,8 +1562,11 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
 	 */
 	if (opt->count && count) {
 		char buf[32];
-		output_color(opt, gs->name, strlen(gs->name), opt->color_filename);
-		output_sep(opt, ':');
+		if (opt->pathname) {
+			output_color(opt, gs->name, strlen(gs->name),
+				     opt->color_filename);
+			output_sep(opt, ':');
+		}
 		snprintf(buf, sizeof(buf), "%u\n", count);
 		opt->output(opt, buf, strlen(buf));
 		return 1;
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 46aaebc..63b3039 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -328,6 +328,18 @@ do
 			grep "a+b*c" $H ab >actual &&
 		test_cmp expected actual
 	'
+
+	test_expect_success "grep --count $L" '
+		echo ${HC}ab:3 >expected &&
+		git grep --count -e b $H -- ab >actual &&
+		test_cmp expected actual
+	'
+
+	test_expect_success "grep --count -h $L" '
+		echo 3 >expected &&
+		git grep --count -h -e b $H -- ab >actual &&
+		test_cmp expected actual
+	'
 done
 
 cat >expected <<EOF
-- 
1.9.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-03-11 21:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-11 21:07 [PATCH 1/2] t7810: add missing variables to tests in loop René Scharfe
2014-03-11 21:15 ` [PATCH 2/2] grep: support -h (no header) with --count René Scharfe

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).