[PATCH v3 4/4] t7800: new tests of difftool.tabbed feature

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A few helper functions were put in the script that manage faked binaries in a
temporary directory for $PATH. The helpers restore state before test finish.

Besides, two tests of rewritten prompting were added. "git difftool" now asks
again on incorrect input. Plus, fixed a typo in a test of the --extcmd option.

Signed-off-by: Nicholas Guriev <nicholas@xxxxxxxxx>
---
 t/t7800-difftool.sh | 175 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 174 insertions(+), 1 deletion(-)

diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index a578b35761..249d7a4821 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -270,6 +270,22 @@ test_expect_success 'difftool last flag wins' '
 	prompt_given "$prompt"
 '
 
+test_expect_success 'ignore unknown input then launch the tool' '
+	difftool_test_setup &&
+	(echo Qwerty && echo Yes) >input &&
+	git difftool branch <input >output &&
+	tail -1 output | grep -q -x -F \
+		"Launch '\''test-tool'\'' [Y/n]? Launch '\''test-tool'\'' [Y/n]? branch"
+'
+
+test_expect_success 'ignore unknown input then skip the tool' '
+	difftool_test_setup &&
+	(echo Qwerty && echo No) >input &&
+	git difftool branch <input >output &&
+	tail -1 output | grep -q -x -F \
+		"Launch '\''test-tool'\'' [Y/n]? Launch '\''test-tool'\'' [Y/n]? "
+'
+
 # git-difftool falls back to git-mergetool config variables
 # so test that behavior here
 test_expect_success 'difftool + mergetool config variables' '
@@ -319,7 +335,7 @@ test_expect_success 'difftool --extcmd=cat' '
 test_expect_success 'difftool --extcmd cat' '
 	echo branch >expect &&
 	echo master >>expect &&
-	git difftool --no-prompt --extcmd=cat branch >actual &&
+	git difftool --no-prompt --extcmd cat branch >actual &&
 	test_cmp expect actual
 '
 
@@ -390,6 +406,163 @@ test_expect_success 'ending prompt input with EOF' '
 	! grep br2 output
 '
 
+prepend_shared_path () {
+	directory="$1"
+	first="${PATH%%:*}"
+	if test "$directory" != "$first"
+	then
+		: ${clean_shared_path=$PATH}
+		PATH="$directory:$PATH"
+		test_when_finished 'PATH=$clean_shared_path'
+	fi
+}
+
+mock_binary () {
+	name="$1" body="$2"
+	prepend_shared_path "$PWD/fake-bin" &&
+	touch run-cmds &&
+	mkdir -p fake-bin &&
+	write_script "fake-bin/$name" <<-EOF &&
+	printf '%s ' $name "\$@" |
+	tr -s '[:space:]' ' ' |
+	sed 's/ \$/\\n/' >>"\$HOME/run-cmds" &&
+	${body:-true}
+	EOF
+	test_when_finished "rm -f fake-bin/$name run-cmds"
+}
+
+test_invoked () {
+	pattern="$1"
+	if ! grep -q -x -e "$pattern" run-cmds
+	then
+		set -- $pattern
+		echo "$1 does not seem to be invoked"
+		echo "entry '$pattern' was not found in the 'run-cmds' file"
+		false
+	fi
+}
+
+test_expect_success 'tabbed mode with --tabbed option' '
+	mock_binary vim &&
+	test_config_global diff.tool vimdiff &&
+	yes | git difftool --tabbed branch | tee actual &&
+	(
+		printf "Viewing 2 files:\n" &&
+		printf "  '\''file'\''\n" &&
+		printf "  '\''file2'\''\n" &&
+		printf "Launch '\''vimdiff'\'' [Y/n]? "
+	) >expect &&
+	test_cmp expect actual &&
+	test_invoked "vim -R -f -c .* file .* file2"
+'
+
+test_expect_success 'tabbed mode with GIT_DIFFTOOL_TABBED environment' '
+	mock_binary vim &&
+	test_config_global diff.tool vimdiff &&
+	yes | GIT_DIFFTOOL_TABBED=yes git difftool branch | tee actual &&
+	(
+		printf "Viewing 2 files:\n" &&
+		printf "  '\''file'\''\n" &&
+		printf "  '\''file2'\''\n" &&
+		printf "Launch '\''vimdiff'\'' [Y/n]? "
+	) >expect &&
+	test_cmp expect actual &&
+	test_invoked "vim -R -f -c .* file .* file2"
+'
+
+test_expect_success 'tabbed mode with difftool.tabbed setting' '
+	mock_binary vim &&
+	test_config_global diff.tool vimdiff &&
+	test_config_global difftool.tabbed 1 &&
+	yes | git difftool branch | tee actual &&
+	(
+		printf "Viewing 2 files:\n" &&
+		printf "  '\''file'\''\n" &&
+		printf "  '\''file2'\''\n" &&
+		printf "Launch '\''vimdiff'\'' [Y/n]? "
+	) >expect &&
+	test_cmp expect actual &&
+	test_invoked "vim -R -f -c .* file .* file2"
+'
+
+test_expect_success 'environment variable wins over config in tabbed mode' '
+	mock_binary vim &&
+	test_config_global diff.tool vimdiff &&
+	test_config_global difftool.tabbed true &&
+	GIT_DIFFTOOL_TABBED=FALSE git difftool -y branch </dev/null >output &&
+	test_must_be_empty output &&
+	test_invoked "vim -R -f -d -c .* file" &&
+	test_invoked "vim -R -f -d -c .* file2"
+'
+
+test_expect_success 'cli option wins over environment in tabbed mode' '
+	mock_binary vim &&
+	test_config_global diff.tool vimdiff &&
+	GIT_DIFFTOOL_TABBED=1 git difftool -y --no-tabbed branch </dev/null >output &&
+	test_must_be_empty output &&
+	test_invoked "vim -R -f -d -c .* file" &&
+	test_invoked "vim -R -f -d -c .* file2"
+'
+
+test_expect_success 'say no in tabbed mode' '
+	mock_binary meld &&
+	yes no | git difftool -t meld --tabbed branch &&
+	! test_invoked "meld\\>.*"
+'
+
+test_expect_success 'no tabbed mode for single file' '
+	mock_binary meld &&
+	git difftool -y -t meld --tabbed branch file &&
+	test_invoked "meld \\S\\+ file"
+'
+
+test_expect_success 'both --tabbed and --trust-exit-code options' '
+	mock_binary meld false &&
+	test_config_global diff.tool meld &&
+	test_config_global difftool.prompt false &&
+	test_must_fail git difftool --tabbed --trust-exit-code branch >output &&
+	test_must_be_empty output &&
+	test_invoked "meld --diff \\S\\+ file --diff \\S\\+ file2"
+'
+
+test_expect_success 'tempdir is still clean after successful tabbed mode' '
+	mock_binary meld &&
+	mkdir tempdir &&
+	test_when_finished "rm -r tempdir" &&
+	TMPDIR="$PWD/tempdir" git difftool -y -t meld --tabbed branch &&
+	test_dir_is_empty tempdir
+'
+
+test_expect_success 'tempdir is still clean after failed tabbed mode' '
+	mock_binary meld false &&
+	mkdir tempdir &&
+	test_when_finished "rm -r tempdir" &&
+	TMPDIR="$PWD/tempdir" git difftool -y -t meld --tabbed branch &&
+	test_dir_is_empty tempdir
+'
+
+test_background () {
+	# https://stackoverflow.com/a/45112755/5000805
+	set -m
+	"$@" &
+	set +m
+}
+
+# Create a named queue for synchronizing. Our test process will get blocked on
+# "echo line" until faked meld reaches "cat chain", and so we do not kill early.
+test_expect_success PIPE 'tempdir is still clean after SIGTERM in tabbed mode' '
+	mkfifo chan &&
+	mock_binary meld "while true; do cat chan; done" &&
+	mkdir tempdir &&
+	test_when_finished "rm -r tempdir" &&
+	test_background env TMPDIR="$PWD/tempdir" \
+		git difftool -y -t meld --tabbed branch &&
+	echo line >chan &&
+	kill -TERM -$! &&
+	wait && # for clean up
+	test_dir_is_empty tempdir
+'
+
 test_expect_success 'difftool --tool-help' '
 	git difftool --tool-help >output &&
 	grep tool output
-- 
2.27.0




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux