Merge branch 'fg/submodule-keep-updating'
[gitweb.git] / t / t7810-grep.sh
index e061108a6439e23c201d728aba8dd4ad74d54fe4..a29ae45b399f89123f886f5b35580bcdc0e803f1 100755 (executable)
@@ -33,9 +33,9 @@ test_expect_success setup '
                echo HeLLo_world
        } >hello_world &&
        {
-               echo aab
-               echo a+b
-               echo a\\+b
+               echo "a+b*c"
+               echo "a+bc"
+               echo "abc"
        } >ab &&
        echo vvv >v &&
        echo ww w >w &&
@@ -233,14 +233,14 @@ do
                test_cmp expected actual
        '
        test_expect_success "grep $L with grep.extendedRegexp=false" '
-               echo "ab:a+b" >expected &&
-               git -c grep.extendedRegexp=false grep "a+b" >actual &&
+               echo "ab:a+bc" >expected &&
+               git -c grep.extendedRegexp=false grep "a+b*c" ab >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep $L with grep.extendedRegexp=true" '
-               echo "ab:aab" >expected &&
-               git -c grep.extendedRegexp=true grep "a+b" >actual &&
+               echo "ab:abc" >expected &&
+               git -c grep.extendedRegexp=true grep "a+b*c" ab >actual &&
                test_cmp expected actual
        '
 done
@@ -636,7 +636,7 @@ test_expect_success LIBPCRE 'grep -P pattern' '
 '
 
 test_expect_success 'grep pattern with grep.extendedRegexp=true' '
-       :>empty &&
+       >empty &&
        test_must_fail git -c grep.extendedregexp=true \
                grep "\p{Ps}.*?\p{Pe}" hello.c >actual &&
        test_cmp empty actual
@@ -650,17 +650,17 @@ test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=true' '
 
 test_expect_success LIBPCRE 'grep -P -v pattern' '
        {
-               echo ab:a+b
-               echo ab:a\\+b
+               echo "ab:a+b*c"
+               echo "ab:a+bc"
        } >expected &&
-       git grep -P -v "aab" ab >actual &&
+       git grep -P -v "abc" ab >actual &&
        test_cmp expected actual
 '
 
 test_expect_success LIBPCRE 'grep -P -i pattern' '
-       {
-               echo "hello.c:  printf(\"Hello world.\n\");"
-       } >expected &&
+       cat >expected <<-EOF &&
+       hello.c:        printf("Hello world.\n");
+       EOF
        git grep -P -i "PRINTF\([^\d]+\)" hello.c >actual &&
        test_cmp expected actual
 '
@@ -686,39 +686,128 @@ test_expect_success LIBPCRE 'grep -P invalidpattern properly dies ' '
        test_must_fail git grep -P "a["
 '
 
-test_expect_success 'grep -F -E -G pattern' '
-       echo ab:a+b >expected &&
-       git grep -F -E -G a+b >actual &&
+test_expect_success 'grep -G -E -F pattern' '
+       echo "ab:a+b*c" >expected &&
+       git grep -G -E -F "a+b*c" ab >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'grep -E -F -G pattern' '
+       echo "ab:a+bc" >expected &&
+       git grep -E -F -G "a+b*c" ab >actual &&
        test_cmp expected actual
 '
 
 test_expect_success 'grep -F -G -E pattern' '
-       echo ab:aab >expected &&
-       git grep -F -G -E a+b >actual &&
+       echo "ab:abc" >expected &&
+       git grep -F -G -E "a+b*c" ab >actual &&
        test_cmp expected actual
 '
 
-test_expect_success 'grep -E -F -G pattern' '
-       echo ab:aab >expected &&
-       git grep -E -F -G a\\+b >actual &&
+test_expect_success 'grep -G -F -P -E pattern' '
+       >empty &&
+       test_must_fail git grep -G -F -P -E "a\x{2b}b\x{2a}c" ab >actual &&
+       test_cmp empty actual
+'
+
+test_expect_success LIBPCRE 'grep -G -F -E -P pattern' '
+       echo "ab:a+b*c" >expected &&
+       git grep -G -F -E -P "a\x{2b}b\x{2a}c" ab >actual &&
+       test_cmp expected actual
+'
+
+test_config() {
+       git config "$1" "$2" &&
+       test_when_finished "git config --unset $1"
+}
+
+cat >expected <<EOF
+hello.c<RED>:<RESET>int main(int argc, const char **argv)
+hello.c<RED>-<RESET>{
+<RED>--<RESET>
+hello.c<RED>:<RESET>   /* char ?? */
+hello.c<RED>-<RESET>}
+<RED>--<RESET>
+hello_world<RED>:<RESET>Hello_world
+hello_world<RED>-<RESET>HeLLo_world
+EOF
+
+test_expect_success 'grep --color, separator' '
+       test_config color.grep.context          normal &&
+       test_config color.grep.filename         normal &&
+       test_config color.grep.function         normal &&
+       test_config color.grep.linenumber       normal &&
+       test_config color.grep.match            normal &&
+       test_config color.grep.selected         normal &&
+       test_config color.grep.separator        red &&
+
+       git grep --color=always -A1 -e char -e lo_w hello.c hello_world |
+       test_decode_color >actual &&
+       test_cmp expected actual
+'
+
+cat >expected <<EOF
+hello.c:int main(int argc, const char **argv)
+hello.c:       /* char ?? */
+
+hello_world:Hello_world
+EOF
+
+test_expect_success 'grep --break' '
+       git grep --break -e char -e lo_w hello.c hello_world >actual &&
        test_cmp expected actual
 '
 
-test_expect_success 'grep -E -G -F pattern' '
-       echo ab:a\\+b >expected &&
-       git grep -E -G -F a\\+b >actual &&
+cat >expected <<EOF
+hello.c:int main(int argc, const char **argv)
+hello.c-{
+--
+hello.c:       /* char ?? */
+hello.c-}
+
+hello_world:Hello_world
+hello_world-HeLLo_world
+EOF
+
+test_expect_success 'grep --break with context' '
+       git grep --break -A1 -e char -e lo_w hello.c hello_world >actual &&
        test_cmp expected actual
 '
 
-test_expect_success 'grep -G -F -E pattern' '
-       echo ab:a+b >expected &&
-       git grep -G -F -E a\\+b >actual &&
+cat >expected <<EOF
+hello.c
+int main(int argc, const char **argv)
+       /* char ?? */
+hello_world
+Hello_world
+EOF
+
+test_expect_success 'grep --heading' '
+       git grep --heading -e char -e lo_w hello.c hello_world >actual &&
        test_cmp expected actual
 '
 
-test_expect_success LIBPCRE 'grep -E -G -F -P pattern' '
-       echo ab:a+b >expected &&
-       git grep -E -G -F -P a\\+b >actual &&
+cat >expected <<EOF
+<BOLD;GREEN>hello.c<RESET>
+2:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv)
+6:     /* <BLACK;BYELLOW>char<RESET> ?? */
+
+<BOLD;GREEN>hello_world<RESET>
+3:Hel<BLACK;BYELLOW>lo_w<RESET>orld
+EOF
+
+test_expect_success 'mimic ack-grep --group' '
+       test_config color.grep.context          normal &&
+       test_config color.grep.filename         "bold green" &&
+       test_config color.grep.function         normal &&
+       test_config color.grep.linenumber       normal &&
+       test_config color.grep.match            "black yellow" &&
+       test_config color.grep.selected         normal &&
+       test_config color.grep.separator        normal &&
+
+       git grep --break --heading -n --color \
+               -e char -e lo_w hello.c hello_world |
+       test_decode_color >actual &&
        test_cmp expected actual
 '