]> git.ipfire.org Git - thirdparty/git.git/commitdiff
grep: add a test asserting that --perl-regexp dies when !PCRE
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Sat, 20 May 2017 21:42:09 +0000 (21:42 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 20 May 2017 23:25:37 +0000 (08:25 +0900)
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>
t/t4202-log.sh
t/t7810-grep.sh

index 547f4c19a71511933ef308c2378283dc1b4114e0..dbed3efeeeeee6ecb4c6cbe7848c18bd684bb2e1 100755 (executable)
@@ -418,7 +418,9 @@ test_expect_success 'log with various grep.patternType configurations & command-
                        git log --pretty=tformat:%s --perl-regexp \
                                --grep="[\d]\|" >actual.perl.long-arg &&
                        test_cmp expect.perl actual.perl.long-arg
-
+               else
+                       test_must_fail git log --perl-regexp \
+                               --grep="[\d]\|"
                fi &&
                test_cmp expect.fixed actual.fixed.long-arg &&
                test_cmp expect.basic actual.basic.long-arg &&
index c84c4d99f90aa9822c6cd65549d5eb7f907f2c95..8d69113695ef600057c92144633cf00cb6bb94ef 100755 (executable)
@@ -281,6 +281,10 @@ do
                test_cmp expected actual
        '
 
+       test_expect_success !PCRE "grep $L with grep.patterntype=perl errors without PCRE" '
+               test_must_fail git -c grep.patterntype=perl grep "foo.*bar"
+       '
+
        test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" '
                echo "${HC}ab:abc" >expected &&
                git \
@@ -1058,11 +1062,19 @@ test_expect_success PCRE 'grep --perl-regexp pattern' '
        test_cmp expected actual
 '
 
+test_expect_success !PCRE 'grep --perl-regexp pattern errors without PCRE' '
+       test_must_fail git grep --perl-regexp "foo.*bar"
+'
+
 test_expect_success PCRE 'grep -P pattern' '
        git grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
        test_cmp expected actual
 '
 
+test_expect_success !PCRE 'grep -P pattern errors without PCRE' '
+       test_must_fail git grep -P "foo.*bar"
+'
+
 test_expect_success 'grep pattern with grep.extendedRegexp=true' '
        >empty &&
        test_must_fail git -c grep.extendedregexp=true \