summaryrefslogtreecommitdiff
path: root/t/t7810-grep.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t7810-grep.sh')
-rwxr-xr-xt/t7810-grep.sh133
1 files changed, 109 insertions, 24 deletions
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index cee42097b0..1797f632a3 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -60,6 +60,18 @@ test_expect_success setup '
echo " line with leading space3"
echo "line without leading space2"
} >space &&
+ cat >hello.ps1 <<-\EOF &&
+ # No-op.
+ function dummy() {}
+
+ # Say hello.
+ function hello() {
+ echo "Hello world."
+ } # hello
+
+ # Still a no-op.
+ function dummy() {}
+ EOF
git add . &&
test_tick &&
git commit -m initial
@@ -275,12 +287,16 @@ do
test_cmp expected actual
'
- test_expect_success LIBPCRE "grep $L with grep.patterntype=perl" '
+ test_expect_success PCRE "grep $L with grep.patterntype=perl" '
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 !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 \
@@ -370,6 +386,11 @@ test_expect_success 'grep -L -C' '
test_cmp expected actual
'
+test_expect_success 'grep --files-without-match --quiet' '
+ git grep --files-without-match --quiet nonexistent_string >actual &&
+ test_cmp /dev/null actual
+'
+
cat >expected <<EOF
file:foo mmap bar_mmap
EOF
@@ -757,18 +778,61 @@ test_expect_success 'grep -W shows no trailing empty lines' '
test_cmp expected actual
'
-cat >expected <<EOF
-hello.c= printf("Hello world.\n");
-hello.c: return 0;
-hello.c- /* char ?? */
-EOF
-
test_expect_success 'grep -W with userdiff' '
test_when_finished "rm -f .gitattributes" &&
- git config diff.custom.xfuncname "(printf.*|})$" &&
- echo "hello.c diff=custom" >.gitattributes &&
- git grep -W return >actual &&
- test_cmp expected actual
+ git config diff.custom.xfuncname "^function .*$" &&
+ echo "hello.ps1 diff=custom" >.gitattributes &&
+ git grep -W echo >function-context-userdiff-actual
+'
+
+test_expect_success ' includes preceding comment' '
+ grep "# Say hello" function-context-userdiff-actual
+'
+
+test_expect_success ' includes function line' '
+ grep "=function hello" function-context-userdiff-actual
+'
+
+test_expect_success ' includes matching line' '
+ grep ": echo" function-context-userdiff-actual
+'
+
+test_expect_success ' includes last line of the function' '
+ grep "} # hello" function-context-userdiff-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 !PTHREADS,C_LOCALE_OUTPUT 'grep --threads=N or pack.threads=N warns when no pthreads' '
+ git grep --threads=2 Hello hello_world 2>err &&
+ grep ^warning: err >warnings &&
+ test_line_count = 1 warnings &&
+ grep -F "no threads support, ignoring --threads" err &&
+ git -c grep.threads=2 grep Hello hello_world 2>err &&
+ grep ^warning: err >warnings &&
+ test_line_count = 1 warnings &&
+ grep -F "no threads support, ignoring grep.threads" err &&
+ git -c grep.threads=2 grep --threads=4 Hello hello_world 2>err &&
+ grep ^warning: err >warnings &&
+ test_line_count = 2 warnings &&
+ grep -F "no threads support, ignoring --threads" err &&
+ grep -F "no threads support, ignoring grep.threads" err &&
+ git -c grep.threads=0 grep --threads=0 Hello hello_world 2>err &&
+ test_line_count = 0 err
'
test_expect_success 'grep from a subdirectory to search wider area (1)' '
@@ -1053,16 +1117,30 @@ hello.c:int main(int argc, const char **argv)
hello.c: printf("Hello world.\n");
EOF
-test_expect_success LIBPCRE 'grep --perl-regexp pattern' '
+test_expect_success PCRE 'grep --perl-regexp pattern' '
git grep --perl-regexp "\p{Ps}.*?\p{Pe}" hello.c >actual &&
test_cmp expected actual
'
-test_expect_success LIBPCRE 'grep -P pattern' '
+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 LIBPCRE2 "grep -P with (*NO_JIT) doesn't error out" '
+ git grep -P "(*NO_JIT)\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 \
@@ -1070,13 +1148,13 @@ test_expect_success 'grep pattern with grep.extendedRegexp=true' '
test_cmp empty actual
'
-test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=true' '
+test_expect_success PCRE 'grep -P pattern with grep.extendedRegexp=true' '
git -c grep.extendedregexp=true \
grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
test_cmp expected actual
'
-test_expect_success LIBPCRE 'grep -P -v pattern' '
+test_expect_success PCRE 'grep -P -v pattern' '
{
echo "ab:a+b*c"
echo "ab:a+bc"
@@ -1085,7 +1163,7 @@ test_expect_success LIBPCRE 'grep -P -v pattern' '
test_cmp expected actual
'
-test_expect_success LIBPCRE 'grep -P -i pattern' '
+test_expect_success PCRE 'grep -P -i pattern' '
cat >expected <<-EOF &&
hello.c: printf("Hello world.\n");
EOF
@@ -1093,7 +1171,7 @@ test_expect_success LIBPCRE 'grep -P -i pattern' '
test_cmp expected actual
'
-test_expect_success LIBPCRE 'grep -P -w pattern' '
+test_expect_success PCRE 'grep -P -w pattern' '
{
echo "hello_world:Hello world"
echo "hello_world:HeLLo world"
@@ -1102,6 +1180,13 @@ test_expect_success LIBPCRE 'grep -P -w pattern' '
test_cmp expected actual
'
+test_expect_success PCRE 'grep -P backreferences work (the PCRE NO_AUTO_CAPTURE flag is not set)' '
+ git grep -P -h "(?P<one>.)(?P=one)" hello_world >actual &&
+ test_cmp hello_world actual &&
+ git grep -P -h "(.)\1" hello_world >actual &&
+ test_cmp hello_world actual
+'
+
test_expect_success 'grep -G invalidpattern properly dies ' '
test_must_fail git grep -G "a["
'
@@ -1118,11 +1203,11 @@ test_expect_success 'grep invalidpattern properly dies with grep.patternType=ext
test_must_fail git -c grep.patterntype=extended grep "a["
'
-test_expect_success LIBPCRE 'grep -P invalidpattern properly dies ' '
+test_expect_success PCRE 'grep -P invalidpattern properly dies ' '
test_must_fail git grep -P "a["
'
-test_expect_success LIBPCRE 'grep invalidpattern properly dies with grep.patternType=perl' '
+test_expect_success PCRE 'grep invalidpattern properly dies with grep.patternType=perl' '
test_must_fail git -c grep.patterntype=perl grep "a["
'
@@ -1191,13 +1276,13 @@ test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =perl, =e
test_cmp expected actual
'
-test_expect_success LIBPCRE 'grep -G -F -E -P pattern' '
+test_expect_success PCRE 'grep -G -F -E -P pattern' '
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' '
+test_expect_success PCRE 'grep pattern with grep.patternType=fixed, =basic, =extended, =perl' '
echo "d0:0" >expected &&
git \
-c grep.patterntype=fixed \
@@ -1208,7 +1293,7 @@ test_expect_success LIBPCRE 'grep pattern with grep.patternType=fixed, =basic, =
test_cmp expected actual
'
-test_expect_success LIBPCRE 'grep -P pattern with grep.patternType=fixed' '
+test_expect_success PCRE 'grep -P pattern with grep.patternType=fixed' '
echo "ab:a+b*c" >expected &&
git \
-c grep.patterntype=fixed \
@@ -1343,12 +1428,12 @@ space: line with leading space2
space: line with leading space3
EOF
-test_expect_success LIBPCRE 'grep -E "^ "' '
+test_expect_success PCRE 'grep -E "^ "' '
git grep -E "^ " space >actual &&
test_cmp expected actual
'
-test_expect_success LIBPCRE 'grep -P "^ "' '
+test_expect_success PCRE 'grep -P "^ "' '
git grep -P "^ " space >actual &&
test_cmp expected actual
'