Skip to content

Commit 8f852ce

Browse files
mkiedrowiczgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a119f91 commit 8f852ce

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

t/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,11 @@ use these, and "test_set_prereq" for how to define your own.
587587
Test is not run by root user, and an attempt to write to an
588588
unwritable file is expected to fail correctly.
589589

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+
590595
Tips for Writing Tests
591596
----------------------
592597

t/t7810-grep.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ test_expect_success setup '
2626
echo foo mmap bar_mmap
2727
echo foo_mmap bar mmap baz
2828
} >file &&
29+
{
30+
echo Hello world
31+
echo HeLLo world
32+
echo Hello_world
33+
echo HeLLo_world
34+
} >hello_world &&
2935
echo vvv >v &&
3036
echo ww w >w &&
3137
echo x x xx x >x &&
@@ -599,4 +605,36 @@ test_expect_success 'grep -e -- -- path' '
599605
test_cmp expected actual
600606
'
601607

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+
602640
test_done

t/test-lib.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ esac
10671067

10681068
test -z "$NO_PERL" && test_set_prereq PERL
10691069
test -z "$NO_PYTHON" && test_set_prereq PYTHON
1070+
test -n "$USE_LIBPCRE" && test_set_prereq LIBPCRE
10701071

10711072
# Can we rely on git's output in the C locale?
10721073
if test -n "$GETTEXT_POISON"

0 commit comments

Comments
 (0)