Re: [PATCH v11 3/4] t7507-commit-verbose: improve test coverage by testing number of diffs

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH v11 3/4] t7507-commit-verbose: improve test coverage by testing number of diffs

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:09:08

Pranit Bauva [off-list ref] writes:
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. Also use write_script()
to create the fake "editor".

A subsequent commit will introduce scenarios where it is important to be
able to exactly determine how many diffs were present.

Helped-by: Eric Sunshine [off-list ref]
Signed-off-by: Pranit Bauva <redacted>

Previous version of this patch:
 - [v10]: $gmane/288820

Changes this version wrt previous one:
I decided to include no of diffs in every test and rewrote the commit
message so as to sell this idea. This was given as an option to me by
Eric and the other option being to drop unnecessary testing of lines
where it isn't required. Also this patch uses a suggestion given by Eric
to make the "editor" look more clean as compared to the editor in my
previous version.
---
OK, by always exiting 0 from the editor, you do not interfere with
the "git commit" that invoked it, and you inspect the editor's
finding after "git commit" returns.  The approach taken by this
patch looks a lot more sensible than the previous one.

You'd need the three-dash right before "Previous version of..."
line, though.
quoted hunk
 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

Re: [PATCH v11 3/4] t7507-commit-verbose: improve test coverage by testing number of diffs

From: Pranit Bauva <hidden>
Date: 2016-06-15 23:09:08

On Thu, Mar 31, 2016 at 11:53 PM, Junio C Hamano [off-list ref] wrote:
Pranit Bauva [off-list ref] writes:
quoted
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. Also use write_script()
to create the fake "editor".

A subsequent commit will introduce scenarios where it is important to be
able to exactly determine how many diffs were present.

Helped-by: Eric Sunshine [off-list ref]
Signed-off-by: Pranit Bauva <redacted>

Previous version of this patch:
 - [v10]: $gmane/288820

Changes this version wrt previous one:
I decided to include no of diffs in every test and rewrote the commit
message so as to sell this idea. This was given as an option to me by
Eric and the other option being to drop unnecessary testing of lines
where it isn't required. Also this patch uses a suggestion given by Eric
to make the "editor" look more clean as compared to the editor in my
previous version.
---
OK, by always exiting 0 from the editor, you do not interfere with
the "git commit" that invoked it, and you inspect the editor's
finding after "git commit" returns.  The approach taken by this
patch looks a lot more sensible than the previous one.

You'd need the three-dash right before "Previous version of..."
line, though.
That's silly of me to forget this. Will do it.
quoted
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help