diff mbox series

[v2] t4015: improve coverage of function context test

Message ID 86fbb0fd-6b77-5d11-69cd-f0994a8ed759@web.de (mailing list archive)
State New, archived
Headers show
Series [v2] t4015: improve coverage of function context test | expand

Commit Message

René Scharfe Dec. 19, 2019, 5:35 p.m. UTC
Add a test that includes an actual function line in the test file to
check if context is expanded to include the whole function, and add an
ignored change before function context to check if that one stays hidden
while the originally ignored change within function context is shown.

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
Changes:
* Keep existing test intact, add a new one instead.
* Use unique content for the part before the function context to make
  clear that it's independent.

 t/t4015-diff-whitespace.sh | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

--
2.24.1

Comments

Jeff King Dec. 19, 2019, 5:51 p.m. UTC | #1
On Thu, Dec 19, 2019 at 06:35:43PM +0100, René Scharfe wrote:

> Add a test that includes an actual function line in the test file to
> check if context is expanded to include the whole function, and add an
> ignored change before function context to check if that one stays hidden
> while the originally ignored change within function context is shown.
> 
> Helped-by: Jeff King <peff@peff.net>
> Signed-off-by: René Scharfe <l.s.r@web.de>

Thanks, the patch looks good.

Maybe worth noting in the commit message why there are two tests.
Something like:

  This differs from the existing test, which is concerned with the case
  where there is no function line at all in the file (and we might look
  past the beginning of the file).

-Peff
diff mbox series

Patch

diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 65615e2fa9..88d3026894 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -2068,4 +2068,27 @@  test_expect_success 'combine --ignore-blank-lines with --function-context' '
 	test_cmp expect actual
 '

+test_expect_success 'combine --ignore-blank-lines with --function-context 2' '
+	test_write_lines    a b c "" function 1 2 3 4 5 "" 6 7 8 9 >a &&
+	test_write_lines "" a b c "" function 1 2 3 4 5    6 7 8   >b &&
+	test_must_fail git diff --no-index \
+		--ignore-blank-lines --function-context a b >actual.raw &&
+	sed -n "/@@/,\$p" <actual.raw >actual &&
+	cat <<-\EOF >expect &&
+	@@ -5,11 +6,9 @@ c
+	 function
+	 1
+	 2
+	 3
+	 4
+	 5
+	-
+	 6
+	 7
+	 8
+	-9
+	EOF
+	test_cmp expect actual
+'
+
 test_done