git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Witten <mfwitten@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Huynh Khoi Nguyen Nguyen 
	<Huynh-Khoi-Nguyen.Nguyen@ensimag.imag.fr>,
	git@vger.kernel.org
Subject: [PATCH 2/3] Testing: XDG config files: Use "$HOME" and "$XDG_CONFIG_HOME" explicitly
Date: Tue, 17 Jul 2012 16:41:21 -0000	[thread overview]
Message-ID: <e118f47351094d4fb45dd34bc08b9e9b-mfwitten@gmail.com> (raw)
In-Reply-To: <82316e5034d940e09fed719ae7bfdc3b-mfwitten@gmail.com>

The tests in:

  t/t1306-xdg-files.sh

relied on brittle conventions:

  * "$HOME" and "$XDG_CONFIG_HOME" having certain values.

  * The testing commands having a certain current working
    directory; at least one test failed as a result.

This commit mitigates the problem by using the variables "$HOME"
and "$XDG_CONFIG_HOME" explicitly.

Signed-off-by: Michael Witten <mfwitten@gmail.com>
---
 t/t1306-xdg-files.sh | 69 +++++++++++++++++++++++++++-------------------------
 1 file changed, 36 insertions(+), 33 deletions(-)

diff --git a/t/t1306-xdg-files.sh b/t/t1306-xdg-files.sh
index 3c75c3f..2327047 100755
--- a/t/t1306-xdg-files.sh
+++ b/t/t1306-xdg-files.sh
@@ -9,58 +9,60 @@ test_description='Compatibility with $XDG_CONFIG_HOME/git/ files'
 
 . ./test-lib.sh
 
+GIT_CONFIG_DIR=$XDG_CONFIG_HOME/git
+
-test_expect_success 'read config: xdg file exists and ~/.gitconfig doesn'\''t' '
+test_expect_success 'read config: xdg file exists and "$HOME"/.gitconfig doesn'\''t' '
-	mkdir -p .config/git &&
+	mkdir -p "$GIT_CONFIG_DIR" &&
-	echo "[alias]" >.config/git/config &&
+	echo "[alias]" >"$GIT_CONFIG_DIR"/config &&
-	echo "	myalias = !echo in_config" >>.config/git/config &&
+	echo "	myalias = !echo in_config" >>"$GIT_CONFIG_DIR"/config &&
 	echo in_config >expected &&
 	git myalias >actual &&
 	test_cmp expected actual
 '
 
 
-test_expect_success 'read config: xdg file exists and ~/.gitconfig exists' '
+test_expect_success 'read config: xdg file exists and "$HOME"/.gitconfig exists' '
-	>.gitconfig &&
+	>"$HOME"/.gitconfig &&
-	echo "[alias]" >.gitconfig &&
+	echo "[alias]" >"$HOME"/.gitconfig &&
-	echo "	myalias = !echo in_gitconfig" >>.gitconfig &&
+	echo "	myalias = !echo in_gitconfig" >>"$HOME"/.gitconfig &&
 	echo in_gitconfig >expected &&
 	git myalias >actual &&
 	test_cmp expected actual
 '
 
 
-test_expect_success 'read with --get: xdg file exists and ~/.gitconfig doesn'\''t' '
+test_expect_success 'read with --get: xdg file exists and "$HOME"/.gitconfig doesn'\''t' '
-	rm .gitconfig &&
+	rm "$HOME"/.gitconfig &&
-	echo "[user]" >.config/git/config &&
+	echo "[user]" >"$GIT_CONFIG_DIR"/config &&
-	echo "	name = read_config" >>.config/git/config &&
+	echo "	name = read_config" >>"$GIT_CONFIG_DIR"/config &&
 	echo read_config >expected &&
 	git config --get user.name >actual &&
 	test_cmp expected actual
 '
 
 
-test_expect_success 'read with --get: xdg file exists and ~/.gitconfig exists' '
+test_expect_success 'read with --get: xdg file exists and "$HOME"/.gitconfig exists' '
-	>.gitconfig &&
+	>"$HOME"/.gitconfig &&
-	echo "[user]" >.gitconfig &&
+	echo "[user]" >"$HOME"/.gitconfig &&
-	echo "	name = read_gitconfig" >>.gitconfig &&
+	echo "	name = read_gitconfig" >>"$HOME"/.gitconfig &&
 	echo read_gitconfig >expected &&
 	git config --get user.name >actual &&
 	test_cmp expected actual
 '
 
 
-test_expect_success 'read with --list: xdg file exists and ~/.gitconfig doesn'\''t' '
+test_expect_success 'read with --list: xdg file exists and "$HOME"/.gitconfig doesn'\''t' '
-	rm .gitconfig &&
+	rm "$HOME"/.gitconfig &&
 	echo user.name=read_config >expected &&
 	git config --global --list >actual &&
 	test_cmp expected actual
 '
 
 
-test_expect_success 'read with --list: xdg file exists and ~/.gitconfig exists' '
+test_expect_success 'read with --list: xdg file exists and "$HOME"/.gitconfig exists' '
-	>.gitconfig &&
+	>"$HOME"/.gitconfig &&
-	echo "[user]" >.gitconfig &&
+	echo "[user]" >"$HOME"/.gitconfig &&
-	echo "	name = read_gitconfig" >>.gitconfig &&
+	echo "	name = read_gitconfig" >>"$HOME"/.gitconfig &&
 	echo user.name=read_gitconfig >expected &&
 	git config --global --list >actual &&
 	test_cmp expected actual
@@ -75,8 +77,8 @@ test_expect_success 'Setup' '
 
 
 test_expect_success 'Exclusion of a file in the XDG ignore file' '
-	mkdir -p "$HOME"/.config/git/ &&
+	mkdir -p "$GIT_CONFIG_DIR" &&
-	echo to_be_excluded >"$HOME"/.config/git/ignore &&
+	echo to_be_excluded >"$GIT_CONFIG_DIR"/ignore &&
 	test_must_fail git add to_be_excluded
 '
 
@@ -89,7 +91,7 @@ test_expect_success 'Exclusion in both XDG and local ignore files' '
 
 test_expect_success 'Exclusion in a non-XDG global ignore file' '
 	rm .gitignore &&
-	echo >"$HOME"/.config/git/ignore &&
+	echo >"$GIT_CONFIG_DIR"/ignore &&
 	echo to_be_excluded >"$HOME"/my_gitignore &&
 	git config core.excludesfile "$HOME"/my_gitignore &&
 	test_must_fail git add to_be_excluded
@@ -100,7 +102,7 @@ test_expect_success 'Checking attributes in the XDG attributes file' '
 	echo foo >f &&
 	git check-attr -a f >actual &&
 	test_line_count -eq 0 actual &&
-	echo "f attr_f" >"$HOME"/.config/git/attributes &&
+	echo "f attr_f" >"$GIT_CONFIG_DIR"/attributes &&
 	echo "f: attr_f: set" >expected &&
 	git check-attr -a f >actual &&
 	test_cmp expected actual
@@ -125,18 +127,18 @@ test_expect_success 'Checking attributes in a non-XDG global attributes file' '
 '
 
 
-test_expect_success 'write: xdg file exists and ~/.gitconfig doesn'\''t' '
+test_expect_success 'write: xdg file exists and "$HOME"/.gitconfig doesn'\''t' '
-	mkdir -p "$HOME"/.config/git &&
+	mkdir -p "$GIT_CONFIG_DIR" &&
-	>"$HOME"/.config/git/config &&
+	>"$GIT_CONFIG_DIR"/config &&
 	test_might_fail rm "$HOME"/.gitconfig &&
 	git config --global user.name "write_config" &&
 	echo "[user]" >expected &&
 	echo "	name = write_config" >>expected &&
-	test_cmp expected "$HOME"/.config/git/config
+	test_cmp expected "$GIT_CONFIG_DIR"/config
 '
 
 
-test_expect_success 'write: xdg file exists and ~/.gitconfig exists' '
+test_expect_success 'write: xdg file exists and "$HOME"/.gitconfig exists' '
 	>"$HOME"/.gitconfig &&
 	git config --global user.name "write_gitconfig" &&
 	echo "[user]" >expected &&
@@ -145,14 +147,15 @@ test_expect_success 'write: xdg file exists and ~/.gitconfig exists' '
 '
 
 
-test_expect_success 'write: ~/.config/git/ exists and config file doesn'\''t' '
+test_expect_success 'write: "$XDG_CONFIG_HOME/git" exists and config file doesn'\''t' '
 	test_might_fail rm "$HOME"/.gitconfig &&
-	test_might_fail rm "$HOME"/.config/git/config &&
+	test_might_fail rm "$GIT_CONFIG_DIR"/config &&
 	git config --global user.name "write_gitconfig" &&
 	echo "[user]" >expected &&
 	echo "	name = write_gitconfig" >>expected &&
 	test_cmp expected "$HOME"/.gitconfig
 '
 
+unset GIT_CONFIG_DIR
 
 test_done
-- 
1.7.11.1.29.gf71be5c

  parent reply	other threads:[~2012-07-17 17:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-17 17:25 [PATCH 0/3] Testing: XDG config files: Fix broken tests Michael Witten
2012-07-17 16:41 ` [PATCH 1/3] Testing: XDG config files: Export a suitable `XDG_CONFIG_HOME' environment variable Michael Witten
2012-07-17 17:57   ` Jonathan Nieder
2012-07-17 18:14   ` Matthieu Moy
2012-07-17 18:31     ` Junio C Hamano
2012-07-17 16:41 ` Michael Witten [this message]
2012-07-17 18:19   ` [PATCH 2/3] Testing: XDG config files: Use "$HOME" and "$XDG_CONFIG_HOME" explicitly Matthieu Moy
2012-07-17 16:41 ` [PATCH 3/3] Testing: XDG config files: Trivial: `xdg' -> `XDG' Michael Witten

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=e118f47351094d4fb45dd34bc08b9e9b-mfwitten@gmail.com \
    --to=mfwitten@gmail.com \
    --cc=Huynh-Khoi-Nguyen.Nguyen@ensimag.imag.fr \
    --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 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 NNTP newsgroup(s).