Skip to content

Commit 799e09e

Browse files
rscharfegitster
authored andcommitted
t7810: add test for grep -W and trailing empty context lines
Add a test demonstrating that git grep -W prints empty lines following the function context we're actually interested in. The modified test file makes it necessary to adjust three unrelated test cases. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e0876bc commit 799e09e

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

t/t7810-grep.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ test_description='git grep various.
99
. ./test-lib.sh
1010

1111
cat >hello.c <<EOF
12+
#include <assert.h>
1213
#include <stdio.h>
14+
1315
int main(int argc, const char **argv)
1416
{
1517
printf("Hello world.\n");
@@ -715,6 +717,7 @@ test_expect_success 'grep -p' '
715717

716718
cat >expected <<EOF
717719
hello.c-#include <stdio.h>
720+
hello.c-
718721
hello.c=int main(int argc, const char **argv)
719722
hello.c-{
720723
hello.c- printf("Hello world.\n");
@@ -740,6 +743,16 @@ test_expect_success 'grep -W' '
740743
test_cmp expected actual
741744
'
742745

746+
cat >expected <<EOF
747+
hello.c-#include <assert.h>
748+
hello.c:#include <stdio.h>
749+
EOF
750+
751+
test_expect_failure 'grep -W shows no trailing empty lines' '
752+
git grep -W stdio >actual &&
753+
test_cmp expected actual
754+
'
755+
743756
cat >expected <<EOF
744757
hello.c= printf("Hello world.\n");
745758
hello.c: return 0;
@@ -1205,8 +1218,8 @@ test_expect_success 'grep --heading' '
12051218

12061219
cat >expected <<EOF
12071220
<BOLD;GREEN>hello.c<RESET>
1208-
2:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv)
1209-
6: /* <BLACK;BYELLOW>char<RESET> ?? */
1221+
4:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv)
1222+
8: /* <BLACK;BYELLOW>char<RESET> ?? */
12101223
12111224
<BOLD;GREEN>hello_world<RESET>
12121225
3:Hel<BLACK;BYELLOW>lo_w<RESET>orld
@@ -1313,7 +1326,7 @@ test_expect_success 'grep --color -e A --and --not -e B with context' '
13131326
'
13141327

13151328
cat >expected <<EOF
1316-
hello.c-#include <stdio.h>
1329+
hello.c-
13171330
hello.c=int main(int argc, const char **argv)
13181331
hello.c-{
13191332
hello.c: pr<RED>int<RESET>f("<RED>Hello<RESET> world.\n");

0 commit comments

Comments
 (0)