diff options
Diffstat (limited to 't/t7002-grep.sh')
-rwxr-xr-x | t/t7002-grep.sh | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index 99142fd6bd..76c5e091b7 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -26,6 +26,7 @@ int main(int argc, const char **argv) { printf("Hello world.\n"); return 0; + /* char ?? */ } EOF @@ -225,6 +226,77 @@ test_expect_success 'grep -e A --and --not -e B' ' test_cmp expected actual ' +test_expect_success 'grep should ignore GREP_OPTIONS' ' + GREP_OPTIONS=-v git grep " mmap bar\$" >actual && + test_cmp expected actual +' + +test_expect_success 'grep -f, non-existent file' ' + test_must_fail git grep -f patterns +' + +cat >expected <<EOF +file:foo mmap bar +file:foo_mmap bar +file:foo_mmap bar mmap +file:foo mmap bar_mmap +file:foo_mmap bar mmap baz +EOF + +cat >pattern <<EOF +mmap +EOF + +test_expect_success 'grep -f, one pattern' ' + git grep -f pattern >actual && + test_cmp expected actual +' + +cat >expected <<EOF +file:foo mmap bar +file:foo_mmap bar +file:foo_mmap bar mmap +file:foo mmap bar_mmap +file:foo_mmap bar mmap baz +t/a/v:vvv +t/v:vvv +v:vvv +EOF + +cat >patterns <<EOF +mmap +vvv +EOF + +test_expect_success 'grep -f, multiple patterns' ' + git grep -f patterns >actual && + test_cmp expected actual +' + +cat >expected <<EOF +file:foo mmap bar +file:foo_mmap bar +file:foo_mmap bar mmap +file:foo mmap bar_mmap +file:foo_mmap bar mmap baz +t/a/v:vvv +t/v:vvv +v:vvv +EOF + +cat >patterns <<EOF + +mmap + +vvv + +EOF + +test_expect_success 'grep -f, ignore empty lines' ' + git grep -f patterns >actual && + test_cmp expected actual +' + cat >expected <<EOF y:y yy -- @@ -340,6 +412,32 @@ test_expect_success 'grep -p -B5' ' test_cmp expected actual ' +test_expect_success 'grep from a subdirectory to search wider area (1)' ' + mkdir -p s && + ( + cd s && git grep "x x x" .. + ) +' + +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) + ) +' + +cat >expected <<EOF +hello.c:int main(int argc, const char **argv) +EOF + +test_expect_success 'grep -Fi' ' + git grep -Fi "CHAR *" >actual && + test_cmp expected actual +' + test_expect_success EXTGREP 'external grep is called' ' GIT_TRACE=2 git grep foo >/dev/null 2>actual && grep "trace: grep:.*foo" actual >/dev/null |