Re: [GSoC][PATCH v8 05/20] stash: add tests for `git stash show` config

2 messages, 2 authors, 2018-09-03 · open the first message on its own page

Re: [GSoC][PATCH v8 05/20] stash: add tests for `git stash show` config

From: Junio C Hamano <hidden>
Date: 2018-08-30 22:07:50

Paul-Sebastian Ungureanu [off-list ref] writes:
quoted hunk
This commit introduces tests for `git stash show`
config. It tests all the cases where `stash.showStat`
and `stash.showPatch` are unset or set to true / false.

Signed-off-by: Paul-Sebastian Ungureanu <redacted>
---
 t/t3907-stash-show-config.sh | 81 ++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100755 t/t3907-stash-show-config.sh
diff --git a/t/t3907-stash-show-config.sh b/t/t3907-stash-show-config.sh
new file mode 100755
index 0000000000..8fe369c1a1
--- /dev/null
+++ b/t/t3907-stash-show-config.sh
@@ -0,0 +1,81 @@
+#!/bin/sh
+
+test_description='Test git stash show configuration.'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+	test_commit file
+'
+
+# takes three parameters:
+# 1. the stash.showStat value (or "<unset>")
+# 2. the stash.showPatch value (or "<unset>")
+# 3. the diff options of the expected output (or nothing for no output)
+test_stat_and_patch () {
+	if test "<unset>" = "$1"
+	then
+		test_might_fail git config --unset stash.showStat
+	else
+		test_config stash.showStat "$1"
+	fi &&
+
+	if test "<unset>" = "$2"
+	then
+		test_might_fail git config --unset stash.showPatch
I think you are trying to protect yourself from an error triggered
by unsetting what is not set, but for that, test_unconfig is
probably a better choice, as it still catches errors of other types
and ignores only that "unset a variable that is not set" error.
+	else
+		test_config stash.showPatch "$2"
+	fi &&
+
+	shift &&
+	shift &&
You can use "shift 2 &&" here (not worth a reroll).
+	echo 2 >file.t &&
+	git diff "$@" >expect &&
When the caller does not give $3 to this function, it does not look
at 'expect'.  I think it is clearer if you did

	if test $# != 0
	then
		git diff "$@" >expect
	fi &&

here, and ...
+	git stash &&
+	git stash show >actual &&
+
+	if test -z "$1"
... wrote this as

	if test $# = 0

The only difference between '-z "$1"' and '$# = 0' is when he caller
passes an empty string to the function as $3, which you never do, so
the distinction is theoretical, but using $# makes your intention
clear that you do not mean to treat an empty string any specially.
+	then
+		test_must_be_empty actual
+	else
+		test_cmp expect actual
+	fi
+}
+
+test_expect_success 'showStat unset showPatch unset' '
+	test_stat_and_patch "<unset>" "<unset>" --stat
+'
+
+test_expect_success 'showStat unset showPatch false' '
+	test_stat_and_patch "<unset>" false --stat
+'
+
+test_expect_success 'showStat unset showPatch true' '
+	test_stat_and_patch "<unset>" true --stat -p
+'
+
+test_expect_success 'showStat false showPatch unset' '
+	test_stat_and_patch false "<unset>"
+'
+
+test_expect_success 'showStat false showPatch false' '
+	test_stat_and_patch false false
+'
+
+test_expect_success 'showStat false showPatch true' '
+	test_stat_and_patch false true -p
+'
+
+test_expect_success 'showStat true showPatch unset' '
+	test_stat_and_patch true "<unset>" --stat
+'
+
+test_expect_success 'showStat true showPatch false' '
+	test_stat_and_patch true false --stat
+'
+
+test_expect_success 'showStat true showPatch true' '
+	test_stat_and_patch true true --stat -p
+'
+
+test_done

Re: [GSoC][PATCH v8 05/20] stash: add tests for `git stash show` config

From: Johannes Schindelin <hidden>
Date: 2018-09-03 12:11:55

Hi Junio,

On Thu, 30 Aug 2018, Junio C Hamano wrote:
Paul-Sebastian Ungureanu [off-list ref] writes:
quoted
+test_stat_and_patch () {
+	if test "<unset>" = "$1"
+	then
+		test_might_fail git config --unset stash.showStat
+	else
+		test_config stash.showStat "$1"
+	fi &&
+
+	if test "<unset>" = "$2"
+	then
+		test_might_fail git config --unset stash.showPatch
I think you are trying to protect yourself from an error triggered
by unsetting what is not set, but for that, test_unconfig is
probably a better choice, as it still catches errors of other types
and ignores only that "unset a variable that is not set" error.
My mistake. I did not realize that tehere is a `test_unconfig` when I
suggested the current version.
quoted
+	shift &&
+	shift &&
You can use "shift 2 &&" here (not worth a reroll).
Again, my mistake. I was not sure how portable that construct is. (Is it?)
quoted
+	echo 2 >file.t &&
quoted
+	git diff "$@" >expect &&
When the caller does not give $3 to this function, it does not look
at 'expect'.  I think it is clearer if you did

	if test $# != 0
	then
		git diff "$@" >expect
	fi &&

here, and ...
quoted
+	git stash &&
+	git stash show >actual &&
+
+	if test -z "$1"
... wrote this as

	if test $# = 0

The only difference between '-z "$1"' and '$# = 0' is when he caller
passes an empty string to the function as $3, which you never do, so
the distinction is theoretical, but using $# makes your intention
clear that you do not mean to treat an empty string any specially.
Good advice in general (in this case, we know the callers).

Paul, when it comes to shell scripting, listen to Junio more than myself
because he is even more of a shell script wiz than I am.

Ciao,
Dscho
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help