git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jacob Keller <jacob.keller@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Jacob Keller <jacob.e.keller@intel.com>
Subject: [PATCH v3 4/6] tests: only automatically unset matching values from test_config
Date: Thu, 16 Jun 2022 17:20:34 -0700	[thread overview]
Message-ID: <20220617002036.1577-5-jacob.keller@gmail.com> (raw)
In-Reply-To: <20220617002036.1577-1-jacob.keller@gmail.com>

From: Jacob Keller <jacob.e.keller@intel.com>

The test_config function is used to set a configuration value and then
ensure that its unset at the end of the test using test_unconfig. This
currently unsets all configurations with the specified name regardless
of whether they match a value.

The git config command can optionally only unset keys which have
specific values. Add support for this by using the 2 argument form, and
add handling for the --fixed-value option.

Pass --fixed-value and both the key and value to the test_unconfig call
from test_config. This ensures that test_config will only setup a
trigger to remove the matching values instead of removing all
configurations of the specified key.

Directly using test_unconfig will still unset all values by default,
unless a 2nd value-pattern parameter is provided. This matches the
behavior of git config and allows some control over the behavior.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
 t/test-lib-functions.sh | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index e518b89bf128..9957eb2e6c30 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -506,15 +506,18 @@ test_modebits () {
 			  -e 's|^\(......\)S|\1-|' -e 's|^\(......\)s|\1x|'
 }
 
-# Usage: test_unconfig [options] <name>
+# Usage: test_unconfig [options] <name> <value-pattern>
 #   -C <dir>:
 #	Run all git commits in directory <dir>
 #   --global:
 #	Modify the global configuration instead of repository.
+#   --fixed-value:
+#	Match the value pattern as a fixed string instead of a regex.
 #
 # Unset a configuration variable, but don't fail if it doesn't exist.
 test_unconfig () {
 	global=
+	fixed=
 	config_dir=
 	while test $# != 0
 	do
@@ -526,6 +529,9 @@ test_unconfig () {
 		--global)
 			global=--global
 			;;
+		--fixed-value)
+			fixed=--fixed-value
+			;;
 		-*)
 			BUG "invalid test_unconfig option: $1"
 			;;
@@ -535,7 +541,20 @@ test_unconfig () {
 		esac
 		shift
 	done
-	git ${config_dir:+-C "$config_dir"} config $global --unset-all "$1"
+
+	case "$#" in
+	1)
+		# Only enable --fixed-value if we have two parameters
+		fixed=
+		;;
+	2)
+		;;
+	*)
+		BUG "test_unconfig requires 1 or 2 positional arguments"
+		;;
+	esac
+
+	git ${config_dir:+-C "$config_dir"} config $global $fixed --unset-all "$1" "$2"
 	config_status=$?
 	case "$config_status" in
 	5) # ok, nothing to unset
@@ -575,7 +594,18 @@ test_config () {
 		esac
 		shift
 	done
-	test_when_finished "test_unconfig ${config_dir:+-C '$config_dir'} $global '$1'" &&
+
+	case "$#" in
+	1)
+		;;
+	2)
+		;;
+	*)
+		BUG "test_config requires 1 or 2 positional arguments"
+		;;
+	esac
+
+	test_when_finished "test_unconfig ${config_dir:+-C '$config_dir'} --fixed-value $global '$1' '$2'" &&
 	git ${config_dir:+-C "$config_dir"} config $global "$1" "$2"
 }
 
-- 
2.36.1


  parent reply	other threads:[~2022-06-17  0:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-17  0:20 [PATCH v3 0/6] remote: handle negative refspecs with show Jacob Keller
2022-06-17  0:20 ` [PATCH v3 1/6] remote: handle negative refspecs in git remote show Jacob Keller
2022-06-17  0:20 ` [PATCH v3 2/6] t5505: remove sub shell use in favor of git -C Jacob Keller
2022-06-17  0:20 ` [PATCH v3 3/6] tests: handle --global directly in test_config/test_unconfig Jacob Keller
2022-06-17  0:20 ` Jacob Keller [this message]
2022-06-17  0:20 ` [PATCH v3 5/6] t5505: use test_config where appropriate Jacob Keller
2022-06-17  0:20 ` [PATCH v3 6/6] remote: add test for negative refspec with prune Jacob Keller

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20220617002036.1577-5-jacob.keller@gmail.com \
    --to=jacob.keller@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jacob.e.keller@intel.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).