Make tests pass if XDG config exists
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
diff --git a/tests-clar/config/global.c b/tests-clar/config/global.c
index 2ecdf97..d5f95f5 100644
--- a/tests-clar/config/global.c
+++ b/tests-clar/config/global.c
@@ -6,18 +6,21 @@ void test_config_global__initialize(void)
{
git_buf path = GIT_BUF_INIT;
- cl_must_pass(p_mkdir("home", 0777));
+ cl_assert_equal_i(0, p_mkdir("home", 0777));
cl_git_pass(git_path_prettify(&path, "home", NULL));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
- cl_must_pass(p_mkdir("xdg", 0777));
- cl_git_pass(git_path_prettify(&path, "xdg", NULL));
+ cl_assert_equal_i(0, p_mkdir("xdg", 0777));
+ cl_assert_equal_i(0, p_mkdir("xdg/git", 0777));
+ cl_git_pass(git_path_prettify(&path, "xdg/git", NULL));
cl_git_pass(git_libgit2_opts(
- GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
+ cl_assert_equal_i(0, p_mkdir("etc", 0777));
+ cl_git_pass(git_path_prettify(&path, "etc", NULL));
cl_git_pass(git_libgit2_opts(
- GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, NULL));
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
git_buf_free(&path);
}
@@ -26,6 +29,11 @@ void test_config_global__cleanup(void)
{
cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES));
cl_git_pass(git_futils_rmdir_r("xdg", NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_git_pass(git_futils_rmdir_r("etc", NULL, GIT_RMDIR_REMOVE_FILES));
+
+ git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, NULL);
+ git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, NULL);
+ git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, NULL);
}
void test_config_global__open_global(void)
@@ -48,10 +56,7 @@ void test_config_global__open_xdg(void)
const char *val, *str = "teststring";
const char *key = "this.variable";
- p_setenv("XDG_CONFIG_HOME", "xdg", 1);
-
- cl_must_pass(p_mkdir("xdg/git/", 0777));
- cl_git_mkfile("xdg/git/config", "");
+ cl_git_mkfile("xdg/git/config", "# XDG config\n[core]\n test = 1\n");
cl_git_pass(git_config_open_default(&cfg));
cl_git_pass(git_config_open_level(&xdg, cfg, GIT_CONFIG_LEVEL_XDG));