grep: add a test asserting that --perl-regexp dies when !PCRE
Add a test asserting that when --perl-regexp (and -P for grep) is given to git-grep & git-log that we die with an error. In developing the PCRE v2 series I introduced a regression where -P would (through control-flow fall-through) become synonymous with basic POSIX matching. I.e. 'git grep -P '[\d]' would match "d" instead of digits. The entire test suite would still pass with this serious regression, since everything that tested for --perl-regexp would be guarded by the PCRE prerequisite, fix that blind-spot by adding tests under !PCRE asserting that git must die when given --perl-regexp or -P. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
May 20, 2017 at 21:42 UTC
9001c1920c9b812efc671bdc0c313d0a3418d8ee
2 files changed
+15
-1
t/t4202-log.sh
+3
-1
@@ -418,7 +418,9 @@ test_expect_success 'log with various grep.patternType configurations & command-
418
git log --pretty=tformat:%s --perl-regexp \
419
--grep="[\d]\|" >actual.perl.long-arg &&
420
test_cmp expect.perl actual.perl.long-arg
421
-
421
+ else
422
+ test_must_fail git log --perl-regexp \
423
+ --grep="[\d]\|"
424
fi &&
425
test_cmp expect.fixed actual.fixed.long-arg &&
426
test_cmp expect.basic actual.basic.long-arg &&
t/t7810-grep.sh
+12
@@ -281,6 +281,10 @@ do
281
test_cmp expected actual
282
'
283
284
+ test_expect_success !PCRE "grep $L with grep.patterntype=perl errors without PCRE" '
285
+ test_must_fail git -c grep.patterntype=perl grep "foo.*bar"
286
+ '
287
+
288
test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" '
289
echo "${HC}ab:abc" >expected &&
290
git \
@@ -1058,11 +1062,19 @@ test_expect_success PCRE 'grep --perl-regexp pattern' '
1062
test_cmp expected actual
1063
'
1064
1065
+test_expect_success !PCRE 'grep --perl-regexp pattern errors without PCRE' '
1066
+ test_must_fail git grep --perl-regexp "foo.*bar"
1067
+'
1068
+
1069
test_expect_success PCRE 'grep -P pattern' '
1070
git grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
1071
test_cmp expected actual
1072
'
1073
1074
+test_expect_success !PCRE 'grep -P pattern errors without PCRE' '
1075
+ test_must_fail git grep -P "foo.*bar"
1076
+'
1077
+
1078
test_expect_success 'grep pattern with grep.extendedRegexp=true' '
1079
>empty &&
1080
test_must_fail git -c grep.extendedregexp=true \