grep: Add basic tests

This modest patch adds simple tests for git grep -P/--perl-regexp and its interoperation with -i and -w. Tests are only enabled when prerequisite LIBPCRE is defined (it's automatically set based on USE_LIBPCRE in test-lib.sh). Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michał Kiedrowicz committed May 9, 2011 at 23:52 UTC 8f852ce613650b0cccf02adecbc18865d8e21fb6
3 files changed +44
t/README
+5
@@ -587,6 +587,11 @@ use these, and "test_set_prereq" for how to define your own.
587 Test is not run by root user, and an attempt to write to an
588 unwritable file is expected to fail correctly.
589
590 + - LIBPCRE
591 +
592 + Git was compiled with USE_LIBPCRE=YesPlease. Wrap any tests
593 + that use git-grep --perl-regexp or git-grep -P in these.
594 +
595 Tips for Writing Tests
596 ----------------------
597
t/t7810-grep.sh
+38
@@ -26,6 +26,12 @@ test_expect_success setup '
26 echo foo mmap bar_mmap
27 echo foo_mmap bar mmap baz
28 } >file &&
29 + {
30 + echo Hello world
31 + echo HeLLo world
32 + echo Hello_world
33 + echo HeLLo_world
34 + } >hello_world &&
35 echo vvv >v &&
36 echo ww w >w &&
37 echo x x xx x >x &&
@@ -599,4 +605,36 @@ test_expect_success 'grep -e -- -- path' '
605 test_cmp expected actual
606 '
607
608 +cat >expected <<EOF
609 +hello.c:int main(int argc, const char **argv)
610 +hello.c: printf("Hello world.\n");
611 +EOF
612 +
613 +test_expect_success LIBPCRE 'grep --perl-regexp pattern' '
614 + git grep --perl-regexp "\p{Ps}.*?\p{Pe}" hello.c >actual &&
615 + test_cmp expected actual
616 +'
617 +
618 +test_expect_success LIBPCRE 'grep -P pattern' '
619 + git grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
620 + test_cmp expected actual
621 +'
622 +
623 +test_expect_success LIBPCRE 'grep -P -i pattern' '
624 + {
625 + echo "hello.c: printf(\"Hello world.\n\");"
626 + } >expected &&
627 + git grep -P -i "PRINTF\([^\d]+\)" hello.c >actual &&
628 + test_cmp expected actual
629 +'
630 +
631 +test_expect_success LIBPCRE 'grep -P -w pattern' '
632 + {
633 + echo "hello_world:Hello world"
634 + echo "hello_world:HeLLo world"
635 + } >expected &&
636 + git grep -P -w "He((?i)ll)o" hello_world >actual &&
637 + test_cmp expected actual
638 +'
639 +
640 test_done
t/test-lib.sh
+1
@@ -1067,6 +1067,7 @@ esac
1067
1068 test -z "$NO_PERL" && test_set_prereq PERL
1069 test -z "$NO_PYTHON" && test_set_prereq PYTHON
1070 +test -n "$USE_LIBPCRE" && test_set_prereq LIBPCRE
1071
1072 # Can we rely on git's output in the C locale?
1073 if test -n "$GETTEXT_POISON"