t7507-commit-verbose: improve test coverage by testing number of diffs

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. 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. Also use write_script() to create the fake "editor". Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pranit Bauva committed May 5, 2016 at 15:20 UTC de45dbb8188ecbc74c1e8a95bf861c6acdda393d
1 file changed +9 -7
t/t7507-commit-verbose.sh
+9 -7
@@ -3,11 +3,10 @@
3 test_description='verbose commit template'
4 . ./test-lib.sh
5
6 -cat >check-for-diff <<EOF
7 -#!$SHELL_PATH
8 -exec grep '^diff --git' "\$1"
6 +write_script "check-for-diff" <<\EOF &&
7 +grep '^diff --git' "$1" >out
8 +exit 0
9 EOF
10 -chmod +x check-for-diff
10 test_set_editor "$PWD/check-for-diff"
11
12 cat >message <<'EOF'
@@ -23,7 +22,8 @@ test_expect_success 'setup' '
22 '
23
24 test_expect_success 'initial commit shows verbose diff' '
26 - git commit --amend -v
25 + git commit --amend -v &&
26 + test_line_count = 1 out
27 '
28
29 test_expect_success 'second commit' '
@@ -39,13 +39,15 @@ check_message() {
39
40 test_expect_success 'verbose diff is stripped out' '
41 git commit --amend -v &&
42 - check_message message
42 + check_message message &&
43 + test_line_count = 1 out
44 '
45
46 test_expect_success 'verbose diff is stripped out (mnemonicprefix)' '
47 git config diff.mnemonicprefix true &&
48 git commit --amend -v &&
48 - check_message message
49 + check_message message &&
50 + test_line_count = 1 out
51 '
52
53 cat >diff <<'EOF'