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

[PATCH v14 5/6] t7507-commit-verbose: improve test coverage by testing number of diffs

From
Pranit Bauva <pranit.bauva@gmail.com>
Date
Apr 12, 2016, 23:02 UTC
Message-ID
<010201540cb6096f-5d2150af-6595-4d88-85e5-18eaeb699fb7-000000@eu-west-1.amazonses.com>
In-Reply-To
<010201540cb60832-9402a692-3caa-47a1-9e8e-ae5a1bc7eb2f-000000@eu-west-1.amazonses.com>

Make the fake "editor" store output of grep in a file so that we can see how many diffs were contained in the message and use them in individual tests where ever it is required. A subsequent commit will introduce scenarios where it is important to be able to exactly determine how many diffs were present.

Also use write_script() to create the fake "editor".

The fake "editor" is always made to succeed regardless of whether grep found diff headers or not so that we don't have to use 'test_must_fail' for which 'test_line_count = 0' is an easy substitute and also helps in maintaining the consistency.

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
---
Previous version of this patch:
 - [v12] : $gmane/288820
 - [v11] : $gmane/288820
 - [v10]: $gmane/288820
Changes this version wrt previous one:
Change the commit message as suggested by Eric
---
 t/t7507-commit-verbose.sh | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh
index 2ddf28c..0f28a86 100755
--- a/t/t7507-commit-verbose.sh
+++ b/t/t7507-commit-verbose.sh
@@ -3,11 +3,10 @@
 test_description='verbose commit template'
 . ./test-lib.sh
 
-cat >check-for-diff <<EOF
-#!$SHELL_PATH
-exec grep '^diff --git' "\$1"
+write_script "check-for-diff" <<\EOF &&
+grep '^diff --git' "$1" >out
+exit 0
 EOF
-chmod +x check-for-diff
 test_set_editor "$PWD/check-for-diff"
 
 cat >message <<'EOF'
@@ -23,7 +22,8 @@ test_expect_success 'setup' '
 '
 
 test_expect_success 'initial commit shows verbose diff' '
-	git commit --amend -v
+	git commit --amend -v &&
+	test_line_count = 1 out
 '
 
 test_expect_success 'second commit' '
@@ -39,13 +39,15 @@ check_message() {
 
 test_expect_success 'verbose diff is stripped out' '
 	git commit --amend -v &&
-	check_message message
+	check_message message &&
+	test_line_count = 1 out
 '
 
 test_expect_success 'verbose diff is stripped out (mnemonicprefix)' '
 	git config diff.mnemonicprefix true &&
 	git commit --amend -v &&
-	check_message message
+	check_message message &&
+	test_line_count = 1 out
 '
 
 cat >diff <<'EOF'

--
https://github.com/git/git/pull/218
Previous: Eric SunshineNext: Eric Sunshine
Message 20 of 22 in “t0040-test-parse-options.sh: fix style issues”
  1. 1/6 t0040-test-parse-options.sh: fix style issuesPranit Bauva, Apr 12, 2016
  2. 2/6 test-parse-options: print quiet as integerPranit Bauva, Apr 12, 2016
  3. 3/6 t0040-parse-options: improve test coveragePranit Bauva, Apr 12, 2016
  4. Eric SunshineApr 13, 2016
  5. Pranit BauvaApr 13, 2016
  6. Eric SunshineApr 13, 2016
  7. Pranit BauvaApr 25, 2016
  8. Eric SunshineApr 27, 2016
  9. Pranit BauvaApr 27, 2016
  10. 6/6 commit: add a commit.verbose config variablePranit Bauva, Apr 12, 2016
  11. Eric SunshineApr 13, 2016
  12. Pranit BauvaApr 13, 2016
  13. Eric SunshineApr 13, 2016
  14. 4/6 parse-options.c: make OPTION_COUNTUP respect "unspecified" valuesPranit Bauva, Apr 12, 2016
  15. Eric SunshineApr 13, 2016
  16. Pranit BauvaApr 13, 2016
  17. Eric SunshineApr 13, 2016
  18. Pranit BauvaApr 13, 2016
  19. Eric SunshineApr 13, 2016
  20. 5/6 t7507-commit-verbose: improve test coverage by testing number of diffsPranit Bauva, Apr 12, 2016
  21. Eric SunshineApr 13, 2016
  22. Pranit BauvaApr 13, 2016

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.