t7810-grep: test multiple --grep with and without --all-match
[git.git] / t / t7810-grep.sh
blobb841909315e5604ac51558c07cb5f71155401463
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='git grep various.
9 . ./test-lib.sh
11 cat >hello.c <<EOF
12 #include <stdio.h>
13 int main(int argc, const char **argv)
15 printf("Hello world.\n");
16 return 0;
17 /* char ?? */
19 EOF
21 test_expect_success setup '
23 echo foo mmap bar
24 echo foo_mmap bar
25 echo foo_mmap bar mmap
26 echo foo mmap bar_mmap
27 echo foo_mmap bar mmap baz
28 } >file &&
30 echo Hello world
31 echo HeLLo world
32 echo Hello_world
33 echo HeLLo_world
34 } >hello_world &&
36 echo "a+b*c"
37 echo "a+bc"
38 echo "abc"
39 } >ab &&
40 echo vvv >v &&
41 echo ww w >w &&
42 echo x x xx x >x &&
43 echo y yy >y &&
44 echo zzz > z &&
45 mkdir t &&
46 echo test >t/t &&
47 echo vvv >t/v &&
48 mkdir t/a &&
49 echo vvv >t/a/v &&
51 echo "line without leading space1"
52 echo " line with leading space1"
53 echo " line with leading space2"
54 echo " line with leading space3"
55 echo "line without leading space2"
56 } >space &&
57 git add . &&
58 test_tick &&
59 git commit -m initial
62 test_expect_success 'grep should not segfault with a bad input' '
63 test_must_fail git grep "("
66 for H in HEAD ''
68 case "$H" in
69 HEAD) HC='HEAD:' L='HEAD' ;;
70 '') HC= L='in working tree' ;;
71 esac
73 test_expect_success "grep -w $L" '
75 echo ${HC}file:1:foo mmap bar
76 echo ${HC}file:3:foo_mmap bar mmap
77 echo ${HC}file:4:foo mmap bar_mmap
78 echo ${HC}file:5:foo_mmap bar mmap baz
79 } >expected &&
80 git -c grep.linenumber=false grep -n -w -e mmap $H >actual &&
81 test_cmp expected actual
84 test_expect_success "grep -w $L" '
86 echo ${HC}file:1:foo mmap bar
87 echo ${HC}file:3:foo_mmap bar mmap
88 echo ${HC}file:4:foo mmap bar_mmap
89 echo ${HC}file:5:foo_mmap bar mmap baz
90 } >expected &&
91 git -c grep.linenumber=true grep -w -e mmap $H >actual &&
92 test_cmp expected actual
95 test_expect_success "grep -w $L" '
97 echo ${HC}file:foo mmap bar
98 echo ${HC}file:foo_mmap bar mmap
99 echo ${HC}file:foo mmap bar_mmap
100 echo ${HC}file:foo_mmap bar mmap baz
101 } >expected &&
102 git -c grep.linenumber=true grep --no-line-number -w -e mmap $H >actual &&
103 test_cmp expected actual
106 test_expect_success "grep -w $L (w)" '
107 : >expected &&
108 test_must_fail git grep -n -w -e "^w" >actual &&
109 test_cmp expected actual
112 test_expect_success "grep -w $L (x)" '
114 echo ${HC}x:1:x x xx x
115 } >expected &&
116 git grep -n -w -e "x xx* x" $H >actual &&
117 test_cmp expected actual
120 test_expect_success "grep -w $L (y-1)" '
122 echo ${HC}y:1:y yy
123 } >expected &&
124 git grep -n -w -e "^y" $H >actual &&
125 test_cmp expected actual
128 test_expect_success "grep -w $L (y-2)" '
129 : >expected &&
130 if git grep -n -w -e "^y y" $H >actual
131 then
132 echo should not have matched
133 cat actual
134 false
135 else
136 test_cmp expected actual
140 test_expect_success "grep -w $L (z)" '
141 : >expected &&
142 if git grep -n -w -e "^z" $H >actual
143 then
144 echo should not have matched
145 cat actual
146 false
147 else
148 test_cmp expected actual
152 test_expect_success "grep $L (t-1)" '
153 echo "${HC}t/t:1:test" >expected &&
154 git grep -n -e test $H >actual &&
155 test_cmp expected actual
158 test_expect_success "grep $L (t-2)" '
159 echo "${HC}t:1:test" >expected &&
161 cd t &&
162 git grep -n -e test $H
163 ) >actual &&
164 test_cmp expected actual
167 test_expect_success "grep $L (t-3)" '
168 echo "${HC}t/t:1:test" >expected &&
170 cd t &&
171 git grep --full-name -n -e test $H
172 ) >actual &&
173 test_cmp expected actual
176 test_expect_success "grep -c $L (no /dev/null)" '
177 ! git grep -c test $H | grep /dev/null
180 test_expect_success "grep --max-depth -1 $L" '
182 echo ${HC}t/a/v:1:vvv
183 echo ${HC}t/v:1:vvv
184 echo ${HC}v:1:vvv
185 } >expected &&
186 git grep --max-depth -1 -n -e vvv $H >actual &&
187 test_cmp expected actual
190 test_expect_success "grep --max-depth 0 $L" '
192 echo ${HC}v:1:vvv
193 } >expected &&
194 git grep --max-depth 0 -n -e vvv $H >actual &&
195 test_cmp expected actual
198 test_expect_success "grep --max-depth 0 -- '*' $L" '
200 echo ${HC}t/a/v:1:vvv
201 echo ${HC}t/v:1:vvv
202 echo ${HC}v:1:vvv
203 } >expected &&
204 git grep --max-depth 0 -n -e vvv $H -- "*" >actual &&
205 test_cmp expected actual
208 test_expect_success "grep --max-depth 1 $L" '
210 echo ${HC}t/v:1:vvv
211 echo ${HC}v:1:vvv
212 } >expected &&
213 git grep --max-depth 1 -n -e vvv $H >actual &&
214 test_cmp expected actual
217 test_expect_success "grep --max-depth 0 -- t $L" '
219 echo ${HC}t/v:1:vvv
220 } >expected &&
221 git grep --max-depth 0 -n -e vvv $H -- t >actual &&
222 test_cmp expected actual
225 test_expect_success "grep --max-depth 0 -- . t $L" '
227 echo ${HC}t/v:1:vvv
228 echo ${HC}v:1:vvv
229 } >expected &&
230 git grep --max-depth 0 -n -e vvv $H -- . t >actual &&
231 test_cmp expected actual
234 test_expect_success "grep --max-depth 0 -- t . $L" '
236 echo ${HC}t/v:1:vvv
237 echo ${HC}v:1:vvv
238 } >expected &&
239 git grep --max-depth 0 -n -e vvv $H -- t . >actual &&
240 test_cmp expected actual
242 test_expect_success "grep $L with grep.extendedRegexp=false" '
243 echo "ab:a+bc" >expected &&
244 git -c grep.extendedRegexp=false grep "a+b*c" ab >actual &&
245 test_cmp expected actual
248 test_expect_success "grep $L with grep.extendedRegexp=true" '
249 echo "ab:abc" >expected &&
250 git -c grep.extendedRegexp=true grep "a+b*c" ab >actual &&
251 test_cmp expected actual
253 done
255 cat >expected <<EOF
256 file
258 test_expect_success 'grep -l -C' '
259 git grep -l -C1 foo >actual &&
260 test_cmp expected actual
263 cat >expected <<EOF
264 file:5
266 test_expect_success 'grep -l -C' '
267 git grep -c -C1 foo >actual &&
268 test_cmp expected actual
271 test_expect_success 'grep -L -C' '
272 git ls-files >expected &&
273 git grep -L -C1 nonexistent_string >actual &&
274 test_cmp expected actual
277 cat >expected <<EOF
278 file:foo mmap bar_mmap
281 test_expect_success 'grep -e A --and -e B' '
282 git grep -e "foo mmap" --and -e bar_mmap >actual &&
283 test_cmp expected actual
286 cat >expected <<EOF
287 file:foo_mmap bar mmap
288 file:foo_mmap bar mmap baz
292 test_expect_success 'grep ( -e A --or -e B ) --and -e B' '
293 git grep \( -e foo_ --or -e baz \) \
294 --and -e " mmap" >actual &&
295 test_cmp expected actual
298 cat >expected <<EOF
299 file:foo mmap bar
302 test_expect_success 'grep -e A --and --not -e B' '
303 git grep -e "foo mmap" --and --not -e bar_mmap >actual &&
304 test_cmp expected actual
307 test_expect_success 'grep should ignore GREP_OPTIONS' '
308 GREP_OPTIONS=-v git grep " mmap bar\$" >actual &&
309 test_cmp expected actual
312 test_expect_success 'grep -f, non-existent file' '
313 test_must_fail git grep -f patterns
316 cat >expected <<EOF
317 file:foo mmap bar
318 file:foo_mmap bar
319 file:foo_mmap bar mmap
320 file:foo mmap bar_mmap
321 file:foo_mmap bar mmap baz
324 cat >pattern <<EOF
325 mmap
328 test_expect_success 'grep -f, one pattern' '
329 git grep -f pattern >actual &&
330 test_cmp expected actual
333 cat >expected <<EOF
334 file:foo mmap bar
335 file:foo_mmap bar
336 file:foo_mmap bar mmap
337 file:foo mmap bar_mmap
338 file:foo_mmap bar mmap baz
339 t/a/v:vvv
340 t/v:vvv
341 v:vvv
344 cat >patterns <<EOF
345 mmap
349 test_expect_success 'grep -f, multiple patterns' '
350 git grep -f patterns >actual &&
351 test_cmp expected actual
354 test_expect_success 'grep, multiple patterns' '
355 git grep "$(cat patterns)" >actual &&
356 test_cmp expected actual
359 cat >expected <<EOF
360 file:foo mmap bar
361 file:foo_mmap bar
362 file:foo_mmap bar mmap
363 file:foo mmap bar_mmap
364 file:foo_mmap bar mmap baz
365 t/a/v:vvv
366 t/v:vvv
367 v:vvv
370 cat >patterns <<EOF
372 mmap
378 test_expect_success 'grep -f, ignore empty lines' '
379 git grep -f patterns >actual &&
380 test_cmp expected actual
383 test_expect_success 'grep -f, ignore empty lines, read patterns from stdin' '
384 git grep -f - <patterns >actual &&
385 test_cmp expected actual
388 cat >expected <<EOF
389 y:y yy
391 z:zzz
394 test_expect_success 'grep -q, silently report matches' '
395 >empty &&
396 git grep -q mmap >actual &&
397 test_cmp empty actual &&
398 test_must_fail git grep -q qfwfq >actual &&
399 test_cmp empty actual
402 # Create 1024 file names that sort between "y" and "z" to make sure
403 # the two files are handled by different calls to an external grep.
404 # This depends on MAXARGS in builtin-grep.c being 1024 or less.
405 c32="0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v"
406 test_expect_success 'grep -C1, hunk mark between files' '
407 for a in $c32; do for b in $c32; do : >y-$a$b; done; done &&
408 git add y-?? &&
409 git grep -C1 "^[yz]" >actual &&
410 test_cmp expected actual
413 test_expect_success 'grep -C1 hunk mark between files' '
414 git grep -C1 "^[yz]" >actual &&
415 test_cmp expected actual
418 test_expect_success 'log grep setup' '
419 echo a >>file &&
420 test_tick &&
421 GIT_AUTHOR_NAME="With * Asterisk" \
422 GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \
423 git commit -a -m "second" &&
425 echo a >>file &&
426 test_tick &&
427 git commit -a -m "third" &&
429 echo a >>file &&
430 test_tick &&
431 GIT_AUTHOR_NAME="Night Fall" \
432 GIT_AUTHOR_EMAIL="nitfol@frobozz.com" \
433 git commit -a -m "fourth"
436 test_expect_success 'log grep (1)' '
437 git log --author=author --pretty=tformat:%s >actual &&
439 echo third && echo initial
440 } >expect &&
441 test_cmp expect actual
444 test_expect_success 'log grep (2)' '
445 git log --author=" * " -F --pretty=tformat:%s >actual &&
447 echo second
448 } >expect &&
449 test_cmp expect actual
452 test_expect_success 'log grep (3)' '
453 git log --author="^A U" --pretty=tformat:%s >actual &&
455 echo third && echo initial
456 } >expect &&
457 test_cmp expect actual
460 test_expect_success 'log grep (4)' '
461 git log --author="frotz\.com>$" --pretty=tformat:%s >actual &&
463 echo second
464 } >expect &&
465 test_cmp expect actual
468 test_expect_success 'log grep (5)' '
469 git log --author=Thor -F --pretty=tformat:%s >actual &&
471 echo third && echo initial
472 } >expect &&
473 test_cmp expect actual
476 test_expect_success 'log grep (6)' '
477 git log --author=-0700 --pretty=tformat:%s >actual &&
478 >expect &&
479 test_cmp expect actual
482 test_expect_success 'log with multiple --grep uses union' '
483 git log --grep=i --grep=r --format=%s >actual &&
485 echo fourth && echo third && echo initial
486 } >expect &&
487 test_cmp expect actual
490 test_expect_success 'log --all-match with multiple --grep uses intersection' '
491 git log --all-match --grep=i --grep=r --format=%s >actual &&
493 echo third
494 } >expect &&
495 test_cmp expect actual
498 test_expect_success 'log --grep --author implicitly uses all-match' '
499 # grep matches initial and second but not third
500 # author matches only initial and third
501 git log --author="A U Thor" --grep=s --grep=l --format=%s >actual &&
503 echo initial
504 } >expect &&
505 test_cmp expect actual
508 test_expect_success 'log with multiple --author uses union' '
509 git log --author="Thor" --author="Aster" --format=%s >actual &&
511 echo third && echo second && echo initial
512 } >expect &&
513 test_cmp expect actual
516 test_expect_success 'log with --grep and multiple --author uses all-match' '
517 git log --author="Thor" --author="Night" --grep=i --format=%s >actual &&
519 echo third && echo initial
520 } >expect &&
521 test_cmp expect actual
524 test_expect_success 'log with --grep and multiple --author uses all-match' '
525 git log --author="Thor" --author="Night" --grep=q --format=%s >actual &&
526 >expect &&
527 test_cmp expect actual
530 test_expect_success 'grep with CE_VALID file' '
531 git update-index --assume-unchanged t/t &&
532 rm t/t &&
533 test "$(git grep test)" = "t/t:test" &&
534 git update-index --no-assume-unchanged t/t &&
535 git checkout t/t
538 cat >expected <<EOF
539 hello.c=#include <stdio.h>
540 hello.c: return 0;
543 test_expect_success 'grep -p with userdiff' '
544 git config diff.custom.funcname "^#" &&
545 echo "hello.c diff=custom" >.gitattributes &&
546 git grep -p return >actual &&
547 test_cmp expected actual
550 cat >expected <<EOF
551 hello.c=int main(int argc, const char **argv)
552 hello.c: return 0;
555 test_expect_success 'grep -p' '
556 rm -f .gitattributes &&
557 git grep -p return >actual &&
558 test_cmp expected actual
561 cat >expected <<EOF
562 hello.c-#include <stdio.h>
563 hello.c=int main(int argc, const char **argv)
564 hello.c-{
565 hello.c- printf("Hello world.\n");
566 hello.c: return 0;
569 test_expect_success 'grep -p -B5' '
570 git grep -p -B5 return >actual &&
571 test_cmp expected actual
574 cat >expected <<EOF
575 hello.c=int main(int argc, const char **argv)
576 hello.c-{
577 hello.c- printf("Hello world.\n");
578 hello.c: return 0;
579 hello.c- /* char ?? */
580 hello.c-}
583 test_expect_success 'grep -W' '
584 git grep -W return >actual &&
585 test_cmp expected actual
588 cat >expected <<EOF
589 hello.c= printf("Hello world.\n");
590 hello.c: return 0;
591 hello.c- /* char ?? */
594 test_expect_success 'grep -W with userdiff' '
595 test_when_finished "rm -f .gitattributes" &&
596 git config diff.custom.xfuncname "(printf.*|})$" &&
597 echo "hello.c diff=custom" >.gitattributes &&
598 git grep -W return >actual &&
599 test_cmp expected actual
602 test_expect_success 'grep from a subdirectory to search wider area (1)' '
603 mkdir -p s &&
605 cd s && git grep "x x x" ..
609 test_expect_success 'grep from a subdirectory to search wider area (2)' '
610 mkdir -p s &&
612 cd s || exit 1
613 ( git grep xxyyzz .. >out ; echo $? >status )
614 ! test -s out &&
615 test 1 = $(cat status)
619 cat >expected <<EOF
620 hello.c:int main(int argc, const char **argv)
623 test_expect_success 'grep -Fi' '
624 git grep -Fi "CHAR *" >actual &&
625 test_cmp expected actual
628 test_expect_success 'outside of git repository' '
629 rm -fr non &&
630 mkdir -p non/git/sub &&
631 echo hello >non/git/file1 &&
632 echo world >non/git/sub/file2 &&
634 echo file1:hello &&
635 echo sub/file2:world
636 } >non/expect.full &&
637 echo file2:world >non/expect.sub &&
639 GIT_CEILING_DIRECTORIES="$(pwd)/non/git" &&
640 export GIT_CEILING_DIRECTORIES &&
641 cd non/git &&
642 test_must_fail git grep o &&
643 git grep --no-index o >../actual.full &&
644 test_cmp ../expect.full ../actual.full
645 cd sub &&
646 test_must_fail git grep o &&
647 git grep --no-index o >../../actual.sub &&
648 test_cmp ../../expect.sub ../../actual.sub
649 ) &&
651 echo ".*o*" >non/git/.gitignore &&
653 GIT_CEILING_DIRECTORIES="$(pwd)/non/git" &&
654 export GIT_CEILING_DIRECTORIES &&
655 cd non/git &&
656 test_must_fail git grep o &&
657 git grep --no-index --exclude-standard o >../actual.full &&
658 test_cmp ../expect.full ../actual.full &&
661 echo ".gitignore:.*o*"
662 cat ../expect.full
663 } >../expect.with.ignored &&
664 git grep --no-index --no-exclude o >../actual.full &&
665 test_cmp ../expect.with.ignored ../actual.full
669 test_expect_success 'inside git repository but with --no-index' '
670 rm -fr is &&
671 mkdir -p is/git/sub &&
672 echo hello >is/git/file1 &&
673 echo world >is/git/sub/file2 &&
674 echo ".*o*" >is/git/.gitignore &&
676 echo file1:hello &&
677 echo sub/file2:world
678 } >is/expect.unignored &&
680 echo ".gitignore:.*o*" &&
681 cat is/expect.unignored
682 } >is/expect.full &&
683 : >is/expect.empty &&
684 echo file2:world >is/expect.sub &&
686 cd is/git &&
687 git init &&
688 test_must_fail git grep o >../actual.full &&
689 test_cmp ../expect.empty ../actual.full &&
691 git grep --untracked o >../actual.unignored &&
692 test_cmp ../expect.unignored ../actual.unignored &&
694 git grep --no-index o >../actual.full &&
695 test_cmp ../expect.full ../actual.full &&
697 git grep --no-index --exclude-standard o >../actual.unignored &&
698 test_cmp ../expect.unignored ../actual.unignored &&
700 cd sub &&
701 test_must_fail git grep o >../../actual.sub &&
702 test_cmp ../../expect.empty ../../actual.sub &&
704 git grep --no-index o >../../actual.sub &&
705 test_cmp ../../expect.sub ../../actual.sub &&
707 git grep --untracked o >../../actual.sub &&
708 test_cmp ../../expect.sub ../../actual.sub
712 test_expect_success 'setup double-dash tests' '
713 cat >double-dash <<EOF &&
716 other
718 git add double-dash
721 cat >expected <<EOF
722 double-dash:->
724 test_expect_success 'grep -- pattern' '
725 git grep -- "->" >actual &&
726 test_cmp expected actual
728 test_expect_success 'grep -- pattern -- pathspec' '
729 git grep -- "->" -- double-dash >actual &&
730 test_cmp expected actual
732 test_expect_success 'grep -e pattern -- path' '
733 git grep -e "->" -- double-dash >actual &&
734 test_cmp expected actual
737 cat >expected <<EOF
738 double-dash:--
740 test_expect_success 'grep -e -- -- path' '
741 git grep -e -- -- double-dash >actual &&
742 test_cmp expected actual
745 cat >expected <<EOF
746 hello.c:int main(int argc, const char **argv)
747 hello.c: printf("Hello world.\n");
750 test_expect_success LIBPCRE 'grep --perl-regexp pattern' '
751 git grep --perl-regexp "\p{Ps}.*?\p{Pe}" hello.c >actual &&
752 test_cmp expected actual
755 test_expect_success LIBPCRE 'grep -P pattern' '
756 git grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
757 test_cmp expected actual
760 test_expect_success 'grep pattern with grep.extendedRegexp=true' '
761 >empty &&
762 test_must_fail git -c grep.extendedregexp=true \
763 grep "\p{Ps}.*?\p{Pe}" hello.c >actual &&
764 test_cmp empty actual
767 test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=true' '
768 git -c grep.extendedregexp=true \
769 grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
770 test_cmp expected actual
773 test_expect_success LIBPCRE 'grep -P -v pattern' '
775 echo "ab:a+b*c"
776 echo "ab:a+bc"
777 } >expected &&
778 git grep -P -v "abc" ab >actual &&
779 test_cmp expected actual
782 test_expect_success LIBPCRE 'grep -P -i pattern' '
783 cat >expected <<-EOF &&
784 hello.c: printf("Hello world.\n");
786 git grep -P -i "PRINTF\([^\d]+\)" hello.c >actual &&
787 test_cmp expected actual
790 test_expect_success LIBPCRE 'grep -P -w pattern' '
792 echo "hello_world:Hello world"
793 echo "hello_world:HeLLo world"
794 } >expected &&
795 git grep -P -w "He((?i)ll)o" hello_world >actual &&
796 test_cmp expected actual
799 test_expect_success 'grep -G invalidpattern properly dies ' '
800 test_must_fail git grep -G "a["
803 test_expect_success 'grep -E invalidpattern properly dies ' '
804 test_must_fail git grep -E "a["
807 test_expect_success LIBPCRE 'grep -P invalidpattern properly dies ' '
808 test_must_fail git grep -P "a["
811 test_expect_success 'grep -G -E -F pattern' '
812 echo "ab:a+b*c" >expected &&
813 git grep -G -E -F "a+b*c" ab >actual &&
814 test_cmp expected actual
817 test_expect_success 'grep -E -F -G pattern' '
818 echo "ab:a+bc" >expected &&
819 git grep -E -F -G "a+b*c" ab >actual &&
820 test_cmp expected actual
823 test_expect_success 'grep -F -G -E pattern' '
824 echo "ab:abc" >expected &&
825 git grep -F -G -E "a+b*c" ab >actual &&
826 test_cmp expected actual
829 test_expect_success 'grep -G -F -P -E pattern' '
830 >empty &&
831 test_must_fail git grep -G -F -P -E "a\x{2b}b\x{2a}c" ab >actual &&
832 test_cmp empty actual
835 test_expect_success LIBPCRE 'grep -G -F -E -P pattern' '
836 echo "ab:a+b*c" >expected &&
837 git grep -G -F -E -P "a\x{2b}b\x{2a}c" ab >actual &&
838 test_cmp expected actual
841 test_config() {
842 git config "$1" "$2" &&
843 test_when_finished "git config --unset $1"
846 cat >expected <<EOF
847 hello.c<RED>:<RESET>int main(int argc, const char **argv)
848 hello.c<RED>-<RESET>{
849 <RED>--<RESET>
850 hello.c<RED>:<RESET> /* char ?? */
851 hello.c<RED>-<RESET>}
852 <RED>--<RESET>
853 hello_world<RED>:<RESET>Hello_world
854 hello_world<RED>-<RESET>HeLLo_world
857 test_expect_success 'grep --color, separator' '
858 test_config color.grep.context normal &&
859 test_config color.grep.filename normal &&
860 test_config color.grep.function normal &&
861 test_config color.grep.linenumber normal &&
862 test_config color.grep.match normal &&
863 test_config color.grep.selected normal &&
864 test_config color.grep.separator red &&
866 git grep --color=always -A1 -e char -e lo_w hello.c hello_world |
867 test_decode_color >actual &&
868 test_cmp expected actual
871 cat >expected <<EOF
872 hello.c:int main(int argc, const char **argv)
873 hello.c: /* char ?? */
875 hello_world:Hello_world
878 test_expect_success 'grep --break' '
879 git grep --break -e char -e lo_w hello.c hello_world >actual &&
880 test_cmp expected actual
883 cat >expected <<EOF
884 hello.c:int main(int argc, const char **argv)
885 hello.c-{
887 hello.c: /* char ?? */
888 hello.c-}
890 hello_world:Hello_world
891 hello_world-HeLLo_world
894 test_expect_success 'grep --break with context' '
895 git grep --break -A1 -e char -e lo_w hello.c hello_world >actual &&
896 test_cmp expected actual
899 cat >expected <<EOF
900 hello.c
901 int main(int argc, const char **argv)
902 /* char ?? */
903 hello_world
904 Hello_world
907 test_expect_success 'grep --heading' '
908 git grep --heading -e char -e lo_w hello.c hello_world >actual &&
909 test_cmp expected actual
912 cat >expected <<EOF
913 <BOLD;GREEN>hello.c<RESET>
914 2:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv)
915 6: /* <BLACK;BYELLOW>char<RESET> ?? */
917 <BOLD;GREEN>hello_world<RESET>
918 3:Hel<BLACK;BYELLOW>lo_w<RESET>orld
921 test_expect_success 'mimic ack-grep --group' '
922 test_config color.grep.context normal &&
923 test_config color.grep.filename "bold green" &&
924 test_config color.grep.function normal &&
925 test_config color.grep.linenumber normal &&
926 test_config color.grep.match "black yellow" &&
927 test_config color.grep.selected normal &&
928 test_config color.grep.separator normal &&
930 git grep --break --heading -n --color \
931 -e char -e lo_w hello.c hello_world |
932 test_decode_color >actual &&
933 test_cmp expected actual
936 cat >expected <<EOF
937 space: line with leading space1
938 space: line with leading space2
939 space: line with leading space3
942 test_expect_success LIBPCRE 'grep -E "^ "' '
943 git grep -E "^ " space >actual &&
944 test_cmp expected actual
947 test_expect_success LIBPCRE 'grep -P "^ "' '
948 git grep -P "^ " space >actual &&
949 test_cmp expected actual
952 test_done