summaryrefslogtreecommitdiff
path: root/t/t7810-grep.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t7810-grep.sh')
-rwxr-xr-xt/t7810-grep.sh222
1 files changed, 190 insertions, 32 deletions
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 1797f632a3..991d5bd9c0 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -72,6 +72,11 @@ test_expect_success setup '
# Still a no-op.
function dummy() {}
EOF
+ if test_have_prereq FUNNYNAMES
+ then
+ echo unusual >"\"unusual\" pathname" &&
+ echo unusual >"t/nested \"unusual\" pathname"
+ fi &&
git add . &&
test_tick &&
git commit -m initial
@@ -99,6 +104,101 @@ do
test_cmp expected actual
'
+ test_expect_success "grep -w $L (with --column)" '
+ {
+ echo ${HC}file:5:foo mmap bar
+ echo ${HC}file:14:foo_mmap bar mmap
+ echo ${HC}file:5:foo mmap bar_mmap
+ echo ${HC}file:14:foo_mmap bar mmap baz
+ } >expected &&
+ git grep --column -w -e mmap $H >actual &&
+ test_cmp expected actual
+ '
+
+ test_expect_success "grep -w $L (with --column, extended OR)" '
+ {
+ echo ${HC}file:14:foo_mmap bar mmap
+ echo ${HC}file:19:foo_mmap bar mmap baz
+ } >expected &&
+ git grep --column -w -e mmap$ --or -e baz $H >actual &&
+ test_cmp expected actual
+ '
+
+ test_expect_success "grep -w $L (with --column, --invert-match)" '
+ {
+ echo ${HC}file:1:foo mmap bar
+ echo ${HC}file:1:foo_mmap bar
+ echo ${HC}file:1:foo_mmap bar mmap
+ echo ${HC}file:1:foo mmap bar_mmap
+ } >expected &&
+ git grep --column --invert-match -w -e baz $H -- file >actual &&
+ test_cmp expected actual
+ '
+
+ test_expect_success "grep $L (with --column, --invert-match, extended OR)" '
+ {
+ echo ${HC}hello_world:6:HeLLo_world
+ } >expected &&
+ git grep --column --invert-match -e ll --or --not -e _ $H -- hello_world \
+ >actual &&
+ test_cmp expected actual
+ '
+
+ test_expect_success "grep $L (with --column, --invert-match, extended AND)" '
+ {
+ echo ${HC}hello_world:3:Hello world
+ echo ${HC}hello_world:3:Hello_world
+ echo ${HC}hello_world:6:HeLLo_world
+ } >expected &&
+ git grep --column --invert-match --not -e _ --and --not -e ll $H -- hello_world \
+ >actual &&
+ test_cmp expected actual
+ '
+
+ test_expect_success "grep $L (with --column, double-negation)" '
+ {
+ echo ${HC}file:1:foo_mmap bar mmap baz
+ } >expected &&
+ git grep --column --not \( --not -e foo --or --not -e baz \) $H -- file \
+ >actual &&
+ test_cmp expected actual
+ '
+
+ test_expect_success "grep -w $L (with --column, -C)" '
+ {
+ echo ${HC}file:5:foo mmap bar
+ echo ${HC}file-foo_mmap bar
+ echo ${HC}file:14:foo_mmap bar mmap
+ echo ${HC}file:5:foo mmap bar_mmap
+ echo ${HC}file:14:foo_mmap bar mmap baz
+ } >expected &&
+ git grep --column -w -C1 -e mmap $H >actual &&
+ test_cmp expected actual
+ '
+
+ test_expect_success "grep -w $L (with --line-number, --column)" '
+ {
+ echo ${HC}file:1:5:foo mmap bar
+ echo ${HC}file:3:14:foo_mmap bar mmap
+ echo ${HC}file:4:5:foo mmap bar_mmap
+ echo ${HC}file:5:14:foo_mmap bar mmap baz
+ } >expected &&
+ git grep -n --column -w -e mmap $H >actual &&
+ test_cmp expected actual
+ '
+
+ test_expect_success "grep -w $L (with non-extended patterns, --column)" '
+ {
+ echo ${HC}file:5:foo mmap bar
+ echo ${HC}file:10:foo_mmap bar
+ echo ${HC}file:10:foo_mmap bar mmap
+ echo ${HC}file:5:foo mmap bar_mmap
+ echo ${HC}file:10:foo_mmap bar mmap baz
+ } >expected &&
+ git grep --column -w -e bar -e mmap $H >actual &&
+ test_cmp expected actual
+ '
+
test_expect_success "grep -w $L" '
{
echo ${HC}file:1:foo mmap bar
@@ -122,9 +222,8 @@ do
'
test_expect_success "grep -w $L (w)" '
- : >expected &&
test_must_fail git grep -n -w -e "^w" $H >actual &&
- test_cmp expected actual
+ test_must_be_empty actual
'
test_expect_success "grep -w $L (x)" '
@@ -144,29 +243,42 @@ do
'
test_expect_success "grep -w $L (y-2)" '
- : >expected &&
if git grep -n -w -e "^y y" $H >actual
then
echo should not have matched
cat actual
false
else
- test_cmp expected actual
+ test_must_be_empty actual
fi
'
test_expect_success "grep -w $L (z)" '
- : >expected &&
if git grep -n -w -e "^z" $H >actual
then
echo should not have matched
cat actual
false
else
- test_cmp expected actual
+ test_must_be_empty actual
fi
'
+ test_expect_success "grep $L (with --column, --only-matching)" '
+ {
+ echo ${HC}file:1:5:mmap
+ echo ${HC}file:2:5:mmap
+ echo ${HC}file:3:5:mmap
+ echo ${HC}file:3:13:mmap
+ echo ${HC}file:4:5:mmap
+ echo ${HC}file:4:13:mmap
+ echo ${HC}file:5:5:mmap
+ echo ${HC}file:5:13:mmap
+ } >expected &&
+ git grep --column -n -o -e mmap $H >actual &&
+ test_cmp expected actual
+ '
+
test_expect_success "grep $L (t-1)" '
echo "${HC}t/t:1:test" >expected &&
git grep -n -e test $H >actual &&
@@ -202,6 +314,8 @@ do
echo ${HC}v:1:vvv
} >expected &&
git grep --max-depth -1 -n -e vvv $H >actual &&
+ test_cmp expected actual &&
+ git grep --recursive -n -e vvv $H >actual &&
test_cmp expected actual
'
@@ -210,6 +324,8 @@ do
echo ${HC}v:1:vvv
} >expected &&
git grep --max-depth 0 -n -e vvv $H >actual &&
+ test_cmp expected actual &&
+ git grep --no-recursive -n -e vvv $H >actual &&
test_cmp expected actual
'
@@ -220,6 +336,8 @@ do
echo ${HC}v:1:vvv
} >expected &&
git grep --max-depth 0 -n -e vvv $H -- "*" >actual &&
+ test_cmp expected actual &&
+ git grep --no-recursive -n -e vvv $H -- "*" >actual &&
test_cmp expected actual
'
@@ -237,6 +355,8 @@ do
echo ${HC}t/v:1:vvv
} >expected &&
git grep --max-depth 0 -n -e vvv $H -- t >actual &&
+ test_cmp expected actual &&
+ git grep --no-recursive -n -e vvv $H -- t >actual &&
test_cmp expected actual
'
@@ -246,6 +366,8 @@ do
echo ${HC}v:1:vvv
} >expected &&
git grep --max-depth 0 -n -e vvv $H -- . t >actual &&
+ test_cmp expected actual &&
+ git grep --no-recursive -n -e vvv $H -- . t >actual &&
test_cmp expected actual
'
@@ -255,6 +377,8 @@ do
echo ${HC}v:1:vvv
} >expected &&
git grep --max-depth 0 -n -e vvv $H -- t . >actual &&
+ test_cmp expected actual &&
+ git grep --no-recursive -n -e vvv $H -- t . >actual &&
test_cmp expected actual
'
test_expect_success "grep $L with grep.extendedRegexp=false" '
@@ -293,7 +417,7 @@ do
test_cmp expected actual
'
- test_expect_success !PCRE "grep $L with grep.patterntype=perl errors without PCRE" '
+ test_expect_success !FAIL_PREREQS,!PCRE "grep $L with grep.patterntype=perl errors without PCRE" '
test_must_fail git -c grep.patterntype=perl grep "foo.*bar"
'
@@ -362,6 +486,48 @@ do
git grep --count -h -e b $H -- ab >actual &&
test_cmp expected actual
'
+
+ test_expect_success FUNNYNAMES "grep $L should quote unusual pathnames" '
+ cat >expected <<-EOF &&
+ ${HC}"\"unusual\" pathname":unusual
+ ${HC}"t/nested \"unusual\" pathname":unusual
+ EOF
+ git grep unusual $H >actual &&
+ test_cmp expected actual
+ '
+
+ test_expect_success FUNNYNAMES "grep $L in subdir should quote unusual relative pathnames" '
+ cat >expected <<-EOF &&
+ ${HC}"nested \"unusual\" pathname":unusual
+ EOF
+ (
+ cd t &&
+ git grep unusual $H
+ ) >actual &&
+ test_cmp expected actual
+ '
+
+ test_expect_success FUNNYNAMES "grep -z $L with unusual pathnames" '
+ cat >expected <<-EOF &&
+ ${HC}"unusual" pathname:unusual
+ ${HC}t/nested "unusual" pathname:unusual
+ EOF
+ git grep -z unusual $H >actual &&
+ tr "\0" ":" <actual >actual-replace-null &&
+ test_cmp expected actual-replace-null
+ '
+
+ test_expect_success FUNNYNAMES "grep -z $L in subdir with unusual relative pathnames" '
+ cat >expected <<-EOF &&
+ ${HC}nested "unusual" pathname:unusual
+ EOF
+ (
+ cd t &&
+ git grep -z unusual $H
+ ) >actual &&
+ tr "\0" ":" <actual >actual-replace-null &&
+ test_cmp expected actual-replace-null
+ '
done
cat >expected <<EOF
@@ -388,7 +554,7 @@ test_expect_success 'grep -L -C' '
test_expect_success 'grep --files-without-match --quiet' '
git grep --files-without-match --quiet nonexistent_string >actual &&
- test_cmp /dev/null actual
+ test_must_be_empty actual
'
cat >expected <<EOF
@@ -509,11 +675,10 @@ z:zzz
EOF
test_expect_success 'grep -q, silently report matches' '
- >empty &&
git grep -q mmap >actual &&
- test_cmp empty actual &&
+ test_must_be_empty actual &&
test_must_fail git grep -q qfwfq >actual &&
- test_cmp empty actual
+ test_must_be_empty actual
'
test_expect_success 'grep -C1 hunk mark between files' '
@@ -581,8 +746,7 @@ test_expect_success 'log grep (5)' '
test_expect_success 'log grep (6)' '
git log --author=-0700 --pretty=tformat:%s >actual &&
- >expect &&
- test_cmp expect actual
+ test_must_be_empty actual
'
test_expect_success 'log grep (7)' '
@@ -607,8 +771,7 @@ test_expect_success 'log grep (9)' '
test_expect_success 'log grep (9)' '
git log -g --grep-reflog="commit: third" --author="non-existent" --pretty=tformat:%s >actual &&
- : >expect &&
- test_cmp expect actual
+ test_must_be_empty actual
'
test_expect_success 'log --grep-reflog can only be used under -g' '
@@ -698,15 +861,13 @@ test_expect_success 'log --all-match --grep --grep --author takes intersection'
'
test_expect_success 'log --author does not search in timestamp' '
- : >expect &&
git log --author="$GIT_AUTHOR_DATE" >actual &&
- test_cmp expect actual
+ test_must_be_empty actual
'
test_expect_success 'log --committer does not search in timestamp' '
- : >expect &&
git log --committer="$GIT_COMMITTER_DATE" >actual &&
- test_cmp expect actual
+ test_must_be_empty actual
'
test_expect_success 'grep with CE_VALID file' '
@@ -845,10 +1006,9 @@ test_expect_success 'grep from a subdirectory to search wider area (1)' '
test_expect_success 'grep from a subdirectory to search wider area (2)' '
mkdir -p s &&
(
- cd s || exit 1
- ( git grep xxyyzz .. >out ; echo $? >status )
- ! test -s out &&
- test 1 = $(cat status)
+ cd s &&
+ test_expect_code 1 git grep xxyyzz .. >out &&
+ test_must_be_empty out
)
'
@@ -897,7 +1057,7 @@ test_expect_success 'outside of git repository' '
echo ".gitignore:.*o*" &&
cat ../expect.full
} >../expect.with.ignored &&
- git grep --no-index --no-exclude o >../actual.full &&
+ git grep --no-index --no-exclude-standard o >../actual.full &&
test_cmp ../expect.with.ignored ../actual.full
)
'
@@ -938,7 +1098,7 @@ test_expect_success 'outside of git repository with fallbackToNoIndex' '
echo ".gitignore:.*o*" &&
cat ../expect.full
} >../expect.with.ignored &&
- git -c grep.fallbackToNoIndex grep --no-exclude o >../actual.full &&
+ git -c grep.fallbackToNoIndex grep --no-exclude-standard o >../actual.full &&
test_cmp ../expect.with.ignored ../actual.full
)
'
@@ -957,13 +1117,12 @@ test_expect_success 'inside git repository but with --no-index' '
echo ".gitignore:.*o*" &&
cat is/expect.unignored
} >is/expect.full &&
- : >is/expect.empty &&
echo file2:world >is/expect.sub &&
(
cd is/git &&
git init &&
test_must_fail git grep o >../actual.full &&
- test_cmp ../expect.empty ../actual.full &&
+ test_must_be_empty ../actual.full &&
git grep --untracked o >../actual.unignored &&
test_cmp ../expect.unignored ../actual.unignored &&
@@ -976,7 +1135,7 @@ test_expect_success 'inside git repository but with --no-index' '
cd sub &&
test_must_fail git grep o >../../actual.sub &&
- test_cmp ../../expect.empty ../../actual.sub &&
+ test_must_be_empty ../../actual.sub &&
git grep --no-index o >../../actual.sub &&
test_cmp ../../expect.sub ../../actual.sub &&
@@ -1122,7 +1281,7 @@ test_expect_success PCRE 'grep --perl-regexp pattern' '
test_cmp expected actual
'
-test_expect_success !PCRE 'grep --perl-regexp pattern errors without PCRE' '
+test_expect_success !FAIL_PREREQS,!PCRE 'grep --perl-regexp pattern errors without PCRE' '
test_must_fail git grep --perl-regexp "foo.*bar"
'
@@ -1137,15 +1296,14 @@ test_expect_success LIBPCRE2 "grep -P with (*NO_JIT) doesn't error out" '
'
-test_expect_success !PCRE 'grep -P pattern errors without PCRE' '
+test_expect_success !FAIL_PREREQS,!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 \
grep "\p{Ps}.*?\p{Pe}" hello.c >actual &&
- test_cmp empty actual
+ test_must_be_empty actual
'
test_expect_success PCRE 'grep -P pattern with grep.extendedRegexp=true' '