[PATCH 2/3] Testing: XDG config files: Use $HOME and $XDG_CONFIG_HOME explicitly

2012-07-17 Thread Michael Witten
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 mfwit...@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 

Re: [PATCH 2/3] Testing: XDG config files: Use $HOME and $XDG_CONFIG_HOME explicitly

2012-07-17 Thread Matthieu Moy
Michael Witten mfwit...@gmail.com writes:

 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;

Other tests (t1305-config-include.sh at least) use the fact that the
tests are ran in $HOME. I'm not sure if we want to change that.

About XDG_CONFIG_HOME, the tests were just assuming it was unset.

 +GIT_CONFIG_DIR=$XDG_CONFIG_HOME/git

As I said in my earlier message, I'd rather test the default value
($HOME/.config/git) than the particular case whe $XDG_CONFIG_HOME is
set.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html