git-grep: Update tests (mainly for -P)

Add few more tests for "-P/--perl-regexp" option of "git grep". While at it, add some generic tests for grep.extendedRegexp config option, for detecting invalid regexep and check if "last one wins" rule works for selecting regexp type. Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michał Kiedrowicz committed May 22, 2011 at 13:37 UTC f556e4af2790bc8f0918093bd2b3053c7d2898dc
1 file changed +85
t/t7810-grep.sh
+85
@@ -32,6 +32,11 @@ test_expect_success setup '
32 echo Hello_world
33 echo HeLLo_world
34 } >hello_world &&
35 + {
36 + echo aab
37 + echo a+b
38 + echo a\\+b
39 + } >ab &&
40 echo vvv >v &&
41 echo ww w >w &&
42 echo x x xx x >x &&
@@ -227,7 +232,17 @@ do
232 git grep --max-depth 0 -n -e vvv $H -- t . >actual &&
233 test_cmp expected actual
234 '
235 + test_expect_success "grep $L with grep.extendedRegexp=false" '
236 + echo "ab:a+b" >expected &&
237 + git -c grep.extendedRegexp=false grep "a+b" >actual &&
238 + test_cmp expected actual
239 + '
240
241 + test_expect_success "grep $L with grep.extendedRegexp=true" '
242 + echo "ab:aab" >expected &&
243 + git -c grep.extendedRegexp=true grep "a+b" >actual &&
244 + test_cmp expected actual
245 + '
246 done
247
248 cat >expected <<EOF
@@ -620,6 +635,28 @@ test_expect_success LIBPCRE 'grep -P pattern' '
635 test_cmp expected actual
636 '
637
638 +test_expect_success 'grep pattern with grep.extendedRegexp=true' '
639 + :>empty &&
640 + test_must_fail git -c grep.extendedregexp=true \
641 + grep "\p{Ps}.*?\p{Pe}" hello.c >actual &&
642 + test_cmp empty actual
643 +'
644 +
645 +test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=true' '
646 + git -c grep.extendedregexp=true \
647 + grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
648 + test_cmp expected actual
649 +'
650 +
651 +test_expect_success LIBPCRE 'grep -P -v pattern' '
652 + {
653 + echo ab:a+b
654 + echo ab:a\\+b
655 + } >expected &&
656 + git grep -P -v "aab" ab >actual &&
657 + test_cmp expected actual
658 +'
659 +
660 test_expect_success LIBPCRE 'grep -P -i pattern' '
661 {
662 echo "hello.c: printf(\"Hello world.\n\");"
@@ -637,4 +674,52 @@ test_expect_success LIBPCRE 'grep -P -w pattern' '
674 test_cmp expected actual
675 '
676
677 +test_expect_success 'grep -G invalidpattern properly dies ' '
678 + test_must_fail git grep -G "a["
679 +'
680 +
681 +test_expect_success 'grep -E invalidpattern properly dies ' '
682 + test_must_fail git grep -E "a["
683 +'
684 +
685 +test_expect_success LIBPCRE 'grep -P invalidpattern properly dies ' '
686 + test_must_fail git grep -P "a["
687 +'
688 +
689 +test_expect_success 'grep -F -E -G pattern' '
690 + echo ab:a+b >expected &&
691 + git grep -F -E -G a+b >actual &&
692 + test_cmp expected actual
693 +'
694 +
695 +test_expect_success 'grep -F -G -E pattern' '
696 + echo ab:aab >expected &&
697 + git grep -F -G -E a+b >actual &&
698 + test_cmp expected actual
699 +'
700 +
701 +test_expect_success 'grep -E -F -G pattern' '
702 + echo ab:aab >expected &&
703 + git grep -E -F -G a\\+b >actual &&
704 + test_cmp expected actual
705 +'
706 +
707 +test_expect_success 'grep -E -G -F pattern' '
708 + echo ab:a\\+b >expected &&
709 + git grep -E -G -F a\\+b >actual &&
710 + test_cmp expected actual
711 +'
712 +
713 +test_expect_success 'grep -G -F -E pattern' '
714 + echo ab:a+b >expected &&
715 + git grep -G -F -E a\\+b >actual &&
716 + test_cmp expected actual
717 +'
718 +
719 +test_expect_success LIBPCRE 'grep -E -G -F -P pattern' '
720 + echo ab:a+b >expected &&
721 + git grep -E -G -F -P a\\+b >actual &&
722 + test_cmp expected actual
723 +'
724 +
725 test_done