@@ -716,4 +716,99 @@ test_expect_success LIBPCRE 'grep -G -F -E -P pattern' '
716716 test_cmp expected actual
717717'
718718
719+ test_config () {
720+ git config " $1 " " $2 " &&
721+ test_when_finished " git config --unset $1 "
722+ }
723+
724+ cat > expected << EOF
725+ hello.c<RED>:<RESET>int main(int argc, const char **argv)
726+ hello.c<RED>-<RESET>{
727+ <RED>--<RESET>
728+ hello.c<RED>:<RESET> /* char ?? */
729+ hello.c<RED>-<RESET>}
730+ <RED>--<RESET>
731+ hello_world<RED>:<RESET>Hello_world
732+ hello_world<RED>-<RESET>HeLLo_world
733+ EOF
734+
735+ test_expect_success ' grep --color, separator' '
736+ test_config color.grep.context normal &&
737+ test_config color.grep.filename normal &&
738+ test_config color.grep.function normal &&
739+ test_config color.grep.linenumber normal &&
740+ test_config color.grep.match normal &&
741+ test_config color.grep.selected normal &&
742+ test_config color.grep.separator red &&
743+
744+ git grep --color=always -A1 -e char -e lo_w hello.c hello_world |
745+ test_decode_color >actual &&
746+ test_cmp expected actual
747+ '
748+
749+ cat > expected << EOF
750+ hello.c:int main(int argc, const char **argv)
751+ hello.c: /* char ?? */
752+
753+ hello_world:Hello_world
754+ EOF
755+
756+ test_expect_success ' grep --break' '
757+ git grep --break -e char -e lo_w hello.c hello_world >actual &&
758+ test_cmp expected actual
759+ '
760+
761+ cat > expected << EOF
762+ hello.c:int main(int argc, const char **argv)
763+ hello.c-{
764+ --
765+ hello.c: /* char ?? */
766+ hello.c-}
767+
768+ hello_world:Hello_world
769+ hello_world-HeLLo_world
770+ EOF
771+
772+ test_expect_success ' grep --break with context' '
773+ git grep --break -A1 -e char -e lo_w hello.c hello_world >actual &&
774+ test_cmp expected actual
775+ '
776+
777+ cat > expected << EOF
778+ hello.c
779+ int main(int argc, const char **argv)
780+ /* char ?? */
781+ hello_world
782+ Hello_world
783+ EOF
784+
785+ test_expect_success ' grep --heading' '
786+ git grep --heading -e char -e lo_w hello.c hello_world >actual &&
787+ test_cmp expected actual
788+ '
789+
790+ cat > expected << EOF
791+ <BOLD;GREEN>hello.c<RESET>
792+ 2:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv)
793+ 6: /* <BLACK;BYELLOW>char<RESET> ?? */
794+
795+ <BOLD;GREEN>hello_world<RESET>
796+ 3:Hel<BLACK;BYELLOW>lo_w<RESET>orld
797+ EOF
798+
799+ test_expect_success ' mimic ack-grep --group' '
800+ test_config color.grep.context normal &&
801+ test_config color.grep.filename "bold green" &&
802+ test_config color.grep.function normal &&
803+ test_config color.grep.linenumber normal &&
804+ test_config color.grep.match "black yellow" &&
805+ test_config color.grep.selected normal &&
806+ test_config color.grep.separator normal &&
807+
808+ git grep --break --heading -n --color \
809+ -e char -e lo_w hello.c hello_world |
810+ test_decode_color >actual &&
811+ test_cmp expected actual
812+ '
813+
719814test_done
0 commit comments