Skip to content

Commit de45dbb

Browse files
pranitbauva1997gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Pranit Bauva <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e0070e8 commit de45dbb

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

t/t7507-commit-verbose.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
test_description='verbose commit template'
44
. ./test-lib.sh
55

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
99
EOF
10-
chmod +x check-for-diff
1110
test_set_editor "$PWD/check-for-diff"
1211

1312
cat >message <<'EOF'
@@ -23,7 +22,8 @@ test_expect_success 'setup' '
2322
'
2423

2524
test_expect_success 'initial commit shows verbose diff' '
26-
git commit --amend -v
25+
git commit --amend -v &&
26+
test_line_count = 1 out
2727
'
2828

2929
test_expect_success 'second commit' '
@@ -39,13 +39,15 @@ check_message() {
3939

4040
test_expect_success 'verbose diff is stripped out' '
4141
git commit --amend -v &&
42-
check_message message
42+
check_message message &&
43+
test_line_count = 1 out
4344
'
4445

4546
test_expect_success 'verbose diff is stripped out (mnemonicprefix)' '
4647
git config diff.mnemonicprefix true &&
4748
git commit --amend -v &&
48-
check_message message
49+
check_message message &&
50+
test_line_count = 1 out
4951
'
5052

5153
cat >diff <<'EOF'

0 commit comments

Comments
 (0)