All of lore.kernel.org
 help / color / mirror / Atom feed
From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"SZEDER Gábor" <szeder.dev@gmail.com>
Subject: [PATCH] t7800-difftool: don't accidentally match tmp dirs
Date: Thu, 24 Dec 2020 10:24:31 +0100	[thread overview]
Message-ID: <20201224092431.13354-1-szeder.dev@gmail.com> (raw)

In a bunch of test cases in 't7800-difftool.sh' we 'grep' for specific
filenames in 'git difftool's output, and those test cases are prone to
occasional failures because those filenames might be part of the name
of difftool's temporary directory as well, e.g.:

  +git difftool --dir-diff --no-symlinks --extcmd ls v1
  +grep sub output
  +test_line_count = 2 sub-output
  test_line_count: line count for sub-output != 2
  /tmp/git-difftool.Ssubfq/left/:
  sub
  /tmp/git-difftool.Ssubfq/right/:
  sub
  error: last command exited with $?=1
  not ok 50 - difftool --dir-diff v1 from subdirectory --no-symlinks

Fix this by tightening those test cases: filter out difftool's
temporary directories from its output, and use here docs to list and
test_cmp to check all files expected to present in those directories
explicitly.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 t/t7800-difftool.sh | 112 ++++++++++++++++++++++++++++++--------------
 1 file changed, 78 insertions(+), 34 deletions(-)

diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index a578b35761..fe02fe1688 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -439,73 +439,104 @@ run_dir_diff_test () {
 }
 
 run_dir_diff_test 'difftool -d' '
+	cat >expect <<-\EOF &&
+	file
+	file2
+
+	file
+	file2
+	sub
+	EOF
 	git difftool -d $symlinks --extcmd ls branch >output &&
-	grep sub output &&
-	grep file output
+	grep -v ^/ output >actual &&
+	test_cmp expect actual
 '
 
 run_dir_diff_test 'difftool --dir-diff' '
+	cat >expect <<-\EOF &&
+	file
+	file2
+
+	file
+	file2
+	sub
+	EOF
 	git difftool --dir-diff $symlinks --extcmd ls branch >output &&
-	grep sub output &&
-	grep file output
+	grep -v ^/ output >actual &&
+	test_cmp expect actual
 '
 
 run_dir_diff_test 'difftool --dir-diff ignores --prompt' '
+	cat >expect <<-\EOF &&
+	file
+	file2
+
+	file
+	file2
+	sub
+	EOF
 	git difftool --dir-diff $symlinks --prompt --extcmd ls branch >output &&
-	grep sub output &&
-	grep file output
+	grep -v ^/ output >actual &&
+	test_cmp expect actual
 '
 
 run_dir_diff_test 'difftool --dir-diff branch from subdirectory' '
 	(
 		cd sub &&
+		cat >expect <<-\EOF &&
+		file
+		file2
+
+		file
+		file2
+		sub
+		EOF
 		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"
-		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
+		grep -v ^/ output >actual &&
+		test_cmp expect actual
 	)
 '
 
 run_dir_diff_test 'difftool --dir-diff v1 from subdirectory' '
 	(
 		cd sub &&
+		cat >expect <<-\EOF &&
+		file
+		sub
+
+		file
+		sub
+		EOF
 		git difftool --dir-diff $symlinks --extcmd ls v1 >output &&
-		# "sub" and "file" exist in both v1 and HEAD.
-		# "file2" is unchanged.
-		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
+		grep -v ^/ output >actual &&
+		test_cmp expect actual
 	)
 '
 
 run_dir_diff_test 'difftool --dir-diff branch from subdirectory w/ pathspec' '
 	(
 		cd sub &&
+		cat >expect <<-\EOF &&
+
+		sub
+		EOF
 		git difftool --dir-diff $symlinks --extcmd ls branch -- .>output &&
-		# "sub" only exists in "right"
-		# "file" and "file2" must not be listed
-		grep sub output >sub-output &&
-		test_line_count = 1 sub-output &&
-		! grep file output
+		grep -v ^/ output >actual &&
+		test_cmp expect actual
 	)
 '
 
 run_dir_diff_test 'difftool --dir-diff v1 from subdirectory w/ pathspec' '
 	(
 		cd sub &&
+		cat >expect <<-\EOF &&
+		sub
+
+		sub
+		EOF
 		git difftool --dir-diff $symlinks --extcmd ls v1 -- .>output &&
-		# "sub" exists in v1 and HEAD
-		# "file" is filtered out by the pathspec
-		grep sub output >sub-output &&
-		test_line_count = 2 sub-output &&
-		! grep file output
+		grep -v ^/ output >actual &&
+		test_cmp expect actual
 	)
 '
 
@@ -516,18 +547,31 @@ run_dir_diff_test 'difftool --dir-diff from subdirectory with GIT_DIR set' '
 		GIT_WORK_TREE=$(pwd) &&
 		export GIT_WORK_TREE &&
 		cd sub &&
+		cat >expect <<-\EOF &&
+
+		sub
+		EOF
 		git difftool --dir-diff $symlinks --extcmd ls \
 			branch -- sub >output &&
-		grep sub output &&
-		! grep file output
+		grep -v ^/ output >actual &&
+		test_cmp expect actual
 	)
 '
 
 run_dir_diff_test 'difftool --dir-diff when worktree file is missing' '
 	test_when_finished git reset --hard &&
 	rm file2 &&
+	cat >expect <<-\EOF &&
+	file
+	file2
+
+	file
+	file2
+	sub
+	EOF
 	git difftool --dir-diff $symlinks --extcmd ls branch master >output &&
-	grep file2 output
+	grep -v ^/ output >actual &&
+	test_cmp expect actual
 '
 
 run_dir_diff_test 'difftool --dir-diff with unmerged files' '
-- 
2.30.0.rc2.444.gff896a3b01


             reply	other threads:[~2020-12-24  9:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-24  9:24 SZEDER Gábor [this message]
2021-01-07  6:24 ` [PATCH] t7800-difftool: don't accidentally match tmp dirs Junio C Hamano
2021-01-08  9:20   ` SZEDER Gábor
2021-01-08 15:23     ` Johannes Schindelin
2021-01-08 20:10     ` Junio C Hamano
2021-01-09 17:05     ` [PATCH v2] " SZEDER Gábor
2021-01-09 21:40       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201224092431.13354-1-szeder.dev@gmail.com \
    --to=szeder.dev@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.