Subject: [PATCH v2 2/8] grep: add tests for --threads=N and grep.threads

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Sun, 16 Apr 2017 22:20:56 +0000

Add tests for when --threads=N is supplied on the command-line or when
grep.threads is supplied in the configuration.

When the threading support was made run-time configurable in commit
89f09dd34e ("grep: add --threads=<num> option and grep.threads
configuration", 2015-12-15) no tests were added for it.

In developing a change to grep I was able to make '--threads=1 <pat>`
segfault, while the test suite still passed. This change fixes that
blind spot in the tests.

Signed-off-by: Ævar Arnfjörð Bjarmason <[email-masked]>
---
 t/t7810-grep.sh | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index cee42097b0..4523ca926b 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -771,6 +771,22 @@ test_expect_success 'grep -W with userdiff' '
 	test_cmp expected actual
 '
 
+for threads in $(test_seq 0 10)
+do
+	test_expect_success "grep --threads=$threads & -c grep.threads=$threads" "
+		git grep --threads=$threads . >actual.$threads &&
+		if test $threads -ge 1
+		then
+			test_cmp actual.\$(($threads - 1)) actual.$threads
+		fi &&
+		git -c grep.threads=$threads grep . >actual.$threads &&
+		if test $threads -ge 1
+		then
+			test_cmp actual.\$(($threads - 1)) actual.$threads
+		fi
+	"
+done
+
 test_expect_success 'grep from a subdirectory to search wider area (1)' '
 	mkdir -p s &&
 	(
-- 
2.11.0