зеркало из https://github.com/microsoft/git.git
t7810: avoid assumption about invalid regex syntax
A few of the tests want to check that "git grep -P -E" will override -P with -E, and vice versa. To do so, we use a regex with "\x{..}", which is valid in PCRE but not defined by POSIX (for basic or extended regular expressions). However, POSIX declares quite a lot of syntax, including "\x", as "undefined". That leaves implementations free to extend the standard if they choose. At least one, musl libc, implements "\x" in the same way as PCRE. Our tests check that "-E" complains about "\x", which fails with musl. We can fix this by finding some construct which behaves reliably on both PCRE and POSIX, but differently in each system. One such construct is the use of backslash inside brackets. In PCRE, "[\d]" interprets "\d" as it would outside the brackets, matching a digit. Whereas in POSIX, the backslash must be treated literally, and we match either it or a literal "d". Moreover, implementations are not free to change this according to POSIX, so we should be able to rely on it. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
0b65a8dbdb
Коммит
7675c7bd01
|
@ -37,6 +37,10 @@ test_expect_success setup '
|
|||
echo "a+bc"
|
||||
echo "abc"
|
||||
} >ab &&
|
||||
{
|
||||
echo d &&
|
||||
echo 0
|
||||
} >d0 &&
|
||||
echo vvv >v &&
|
||||
echo ww w >w &&
|
||||
echo x x xx x >x &&
|
||||
|
@ -1092,36 +1096,36 @@ test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =extended
|
|||
'
|
||||
|
||||
test_expect_success 'grep -G -F -P -E pattern' '
|
||||
>empty &&
|
||||
test_must_fail git grep -G -F -P -E "a\x{2b}b\x{2a}c" ab >actual &&
|
||||
test_cmp empty actual
|
||||
echo "d0:d" >expected &&
|
||||
git grep -G -F -P -E "[\d]" d0 >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =perl, =extended' '
|
||||
>empty &&
|
||||
test_must_fail git \
|
||||
echo "d0:d" >expected &&
|
||||
git \
|
||||
-c grep.patterntype=fixed \
|
||||
-c grep.patterntype=basic \
|
||||
-c grep.patterntype=perl \
|
||||
-c grep.patterntype=extended \
|
||||
grep "a\x{2b}b\x{2a}c" ab >actual &&
|
||||
test_cmp empty actual
|
||||
grep "[\d]" d0 >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success LIBPCRE 'grep -G -F -E -P pattern' '
|
||||
echo "ab:a+b*c" >expected &&
|
||||
git grep -G -F -E -P "a\x{2b}b\x{2a}c" ab >actual &&
|
||||
echo "d0:0" >expected &&
|
||||
git grep -G -F -E -P "[\d]" d0 >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success LIBPCRE 'grep pattern with grep.patternType=fixed, =basic, =extended, =perl' '
|
||||
echo "ab:a+b*c" >expected &&
|
||||
echo "d0:0" >expected &&
|
||||
git \
|
||||
-c grep.patterntype=fixed \
|
||||
-c grep.patterntype=basic \
|
||||
-c grep.patterntype=extended \
|
||||
-c grep.patterntype=perl \
|
||||
grep "a\x{2b}b\x{2a}c" ab >actual &&
|
||||
grep "[\d]" d0 >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче