summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a119f91)
raw | patch | inline | side by side (parent: a119f91)
author | Michał Kiedrowicz <michal.kiedrowicz@gmail.com> | |
Mon, 9 May 2011 21:52:07 +0000 (23:52 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 9 May 2011 23:29:54 +0000 (16:29 -0700) |
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>
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>
t/README | patch | blob | history | |
t/t7810-grep.sh | patch | blob | history | |
t/test-lib.sh | patch | blob | history |
diff --git a/t/README b/t/README
index 428ee05c4a5b844815ff4f9356b71bb147cb42a6..238729c5b7168919ab6f79cf0a0b11c4833ddeae 100644 (file)
--- a/t/README
+++ b/t/README
Test is not run by root user, and an attempt to write to an
unwritable file is expected to fail correctly.
+ - LIBPCRE
+
+ Git was compiled with USE_LIBPCRE=YesPlease. Wrap any tests
+ that use git-grep --perl-regexp or git-grep -P in these.
+
Tips for Writing Tests
----------------------
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 8184c264cf942bcd8e6c2f75b5526ddfdc5a11e9..e845218f67a4d14160900884bb0b0d9c8785ba97 100755 (executable)
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
echo foo mmap bar_mmap
echo foo_mmap bar mmap baz
} >file &&
+ {
+ echo Hello world
+ echo HeLLo world
+ echo Hello_world
+ echo HeLLo_world
+ } >hello_world &&
echo vvv >v &&
echo ww w >w &&
echo x x xx x >x &&
test_cmp expected actual
'
+cat >expected <<EOF
+hello.c:int main(int argc, const char **argv)
+hello.c: printf("Hello world.\n");
+EOF
+
+test_expect_success LIBPCRE 'grep --perl-regexp pattern' '
+ git grep --perl-regexp "\p{Ps}.*?\p{Pe}" hello.c >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success LIBPCRE 'grep -P pattern' '
+ git grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success LIBPCRE 'grep -P -i pattern' '
+ {
+ echo "hello.c: printf(\"Hello world.\n\");"
+ } >expected &&
+ git grep -P -i "PRINTF\([^\d]+\)" hello.c >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success LIBPCRE 'grep -P -w pattern' '
+ {
+ echo "hello_world:Hello world"
+ echo "hello_world:HeLLo world"
+ } >expected &&
+ git grep -P -w "He((?i)ll)o" hello_world >actual &&
+ test_cmp expected actual
+'
+
test_done
diff --git a/t/test-lib.sh b/t/test-lib.sh
index abc47f3abc5d925ed217d0d95f10bf078bc26034..d3ed59803f6e7c91a60cbabd38419ab0c8f8a797 100644 (file)
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
test -z "$NO_PERL" && test_set_prereq PERL
test -z "$NO_PYTHON" && test_set_prereq PYTHON
+test -n "$USE_LIBPCRE" && test_set_prereq LIBPCRE
# Can we rely on git's output in the C locale?
if test -n "$GETTEXT_POISON"