git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] t4051-diff-function-context: read the right file

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Aug 22, 2018, 12:44 UTC
Message-ID
<20180822124437.11242-2-szeder.dev@gmail.com>
In-Reply-To
<20180822124437.11242-1-szeder.dev@gmail.com>

The test ' context does not include preceding empty lines' in the block of tests 'change with long common tail and no context' in 't4051-diff-function-context.sh' tries to read the file 'long_common_tail.diff.diff', but that file doesn't exist as its name contains one more '.diff' suffixes than necessary.

Despite this error the test still succeeded without checking what it's supposed to, because this erroneous read is done on the line:

  test "$(first_context_line <long_common_tail.diff.diff)" != " "
which means that:
  - the command substitution hides the error, so it won't fail the
    test, and
  - the result of the command substitution is the empty string, which
    is, of course, not equal to a single space character, so the
    condition is fulfilled, and the test succeeds.
As a minimal fix, fix the name of the file to be read.

In the future we might want to reorganize this test script (1) to use 'test_cmp' instead of 'test's and command substitutions to catch failing commands and to provide helpful error messages, and (2) to specify what the expected result actually _is_ instead of what it isn't.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 t/t4051-diff-function-context.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/t/t4051-diff-function-context.sh b/t/t4051-diff-function-context.sh
index 2d76a971c4..4838a1df8b 100755
--- a/t/t4051-diff-function-context.sh
+++ b/t/t4051-diff-function-context.sh
@@ -174,7 +174,7 @@ test_expect_success ' context does not include other functions' '
 '
 
 test_expect_success ' context does not include preceding empty lines' '
-	test "$(first_context_line <long_common_tail.diff.diff)" != " "
+	test "$(first_context_line <long_common_tail.diff)" != " "
 '
 
 check_diff changed_hello_appended 'changed function plus appended function'
-- 
2.19.0.rc0.136.gd2dd172e64
Previous: SZEDER GáborNext: Junio C Hamano
Message 2 of 4 in “t0020-crlf: check the right file”
  1. 1/2 t0020-crlf: check the right fileSZEDER Gábor, Aug 22, 2018
  2. 2/2 t4051-diff-function-context: read the right fileSZEDER Gábor, Aug 22, 2018
  3. Junio C HamanoAug 22, 2018
  4. Jeff KingAug 22, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.