# [PATCH 1/2] t7800: simplify basic usage test

3 messages from 2017-02-07 to 2017-02-07. Participants: David Aguilar, Johannes Schindelin.
Thread: https://gitlist.dev/t/45068

## David Aguilar, 2017-02-07 09:16

Subject: [PATCH 1/2] t7800: simplify basic usage test
Message-ID: <20170207091700.20156-1-davvid@gmail.com>
URL: https://gitlist.dev/e/20170207091700.20156-1-davvid%40gmail.com

```
Use "test_line_count" instead of "wc -l", use "git -C" instead of a
subshell, and use test_expect_code when calling difftool.  Ease
debugging by capturing output into temporary files.

Suggested-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: David Aguilar <davvid@gmail.com>
---
This patch applies on top of js/difftool-builtin in next
"difftool: fix bug when printing usage"

 t/t7800-difftool.sh | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index 21e2ac4ad6..97bae54d83 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -24,16 +24,15 @@ prompt_given ()
 }
 
 test_expect_success 'basic usage requires no repo' '
-	lines=$(git difftool -h | grep ^usage: | wc -l) &&
-	test "$lines" -eq 1 &&
+	test_expect_code 129 git difftool -h >output &&
+	grep ^usage: output &&
 	# create a ceiling directory to prevent Git from finding a repo
 	mkdir -p not/repo &&
-	ceiling="$PWD/not" &&
-	lines=$(cd not/repo &&
-		GIT_CEILING_DIRECTORIES="$ceiling" git difftool -h |
-		grep ^usage: | wc -l) &&
-	test "$lines" -eq 1 &&
-	rmdir -p not/repo
+	test_when_finished rm -r not &&
+	test_expect_code 129 \
+	env GIT_CEILING_DIRECTORIES="$(pwd)/not" \
+	git -C not/repo difftool -h >output &&
+	grep ^usage: output
 '
 
 # Create a file on master and change it on branch
-- 
2.12.0.rc0.228.g6c028b8e94


```

## David Aguilar, 2017-02-07 09:17

Subject: [PATCH 2/2] t7800: replace "wc -l" with test_line_count
Message-ID: <20170207091700.20156-2-davvid@gmail.com>
URL: https://gitlist.dev/e/20170207091700.20156-2-davvid%40gmail.com
In-Reply-To: <20170207091700.20156-1-davvid@gmail.com>

```
Make t7800 easier to debug by capturing output into temporary files and
using test_line_count to make assertions on those files.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
 t/t7800-difftool.sh | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index 97bae54d83..25241f4096 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -290,8 +290,8 @@ test_expect_success 'difftool + mergetool config variables' '
 test_expect_success 'difftool.<tool>.path' '
 	test_config difftool.tkdiff.path echo &&
 	git difftool --tool=tkdiff --no-prompt branch >output &&
-	lines=$(grep file output | wc -l) &&
-	test "$lines" -eq 1
+	grep file output >grep-output &&
+	test_line_count = 1 grep-output
 '
 
 test_expect_success 'difftool --extcmd=cat' '
@@ -428,9 +428,12 @@ run_dir_diff_test 'difftool --dir-diff branch from subdirectory' '
 		git difftool --dir-diff $symlinks --extcmd ls branch >output &&
 		# "sub" must only exist in "right"
 		# "file" and "file2" must be listed in both "left" and "right"
-		test "1" = $(grep sub output | wc -l) &&
-		test "2" = $(grep file"$" output | wc -l) &&
-		test "2" = $(grep file2 output | wc -l)
+		grep sub output > sub-output &&
+		test_line_count = 1 sub-output &&
+		grep file"$" output >file-output &&
+		test_line_count = 2 file-output &&
+		grep file2 output >file2-output &&
+		test_line_count = 2 file2-output
 	)
 '
 
@@ -440,9 +443,11 @@ run_dir_diff_test 'difftool --dir-diff v1 from subdirectory' '
 		git difftool --dir-diff $symlinks --extcmd ls v1 >output &&
 		# "sub" and "file" exist in both v1 and HEAD.
 		# "file2" is unchanged.
-		test "2" = $(grep sub output | wc -l) &&
-		test "2" = $(grep file output | wc -l) &&
-		test "0" = $(grep file2 output | wc -l)
+		grep sub output >sub-output &&
+		test_line_count = 2 sub-output &&
+		grep file output >file-output &&
+		test_line_count = 2 file-output &&
+		! grep file2 output
 	)
 '
 
@@ -452,8 +457,9 @@ run_dir_diff_test 'difftool --dir-diff branch from subdirectory w/ pathspec' '
 		git difftool --dir-diff $symlinks --extcmd ls branch -- .>output &&
 		# "sub" only exists in "right"
 		# "file" and "file2" must not be listed
-		test "1" = $(grep sub output | wc -l) &&
-		test "0" = $(grep file output | wc -l)
+		grep sub output >sub-output &&
+		test_line_count = 1 sub-output &&
+		! grep file output
 	)
 '
 
@@ -463,8 +469,9 @@ run_dir_diff_test 'difftool --dir-diff v1 from subdirectory w/ pathspec' '
 		git difftool --dir-diff $symlinks --extcmd ls v1 -- .>output &&
 		# "sub" exists in v1 and HEAD
 		# "file" is filtered out by the pathspec
-		test "2" = $(grep sub output | wc -l) &&
-		test "0" = $(grep file output | wc -l)
+		grep sub output >sub-output &&
+		test_line_count = 2 sub-output &&
+		! grep file output
 	)
 '
 
-- 
2.12.0.rc0.228.g6c028b8e94


```

## Johannes Schindelin, 2017-02-07 12:02

Subject: Re: [PATCH 2/2] t7800: replace "wc -l" with test_line_count
Message-ID: <alpine.DEB.2.20.1702071300021.3496@virtualbox>
URL: https://gitlist.dev/e/alpine.DEB.2.20.1702071300021.3496%40virtualbox
In-Reply-To: <20170207091700.20156-2-davvid@gmail.com>

```
Hi David,

On Tue, 7 Feb 2017, David Aguilar wrote:

> Make t7800 easier to debug by capturing output into temporary files and
> using test_line_count to make assertions on those files.
> 
> Signed-off-by: David Aguilar <davvid@gmail.com>

Both patches look like an obvious improvement with no obvious bugs to me.

In this case, I allowed myself to forego the more thorough code review in
favor of merely glancing over the diffs, seeing as the changes do not
really need a lot of context.

Thank you,
Johannes

```
