Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-05-02 01:47:33 +0400
committerRussell Belfer <rb@github.com>2014-05-02 20:21:33 +0400
commit0f603132bc2397bf8308e72651c56cb7dbd3ad70 (patch)
tree0ea052ae8023fc0929e8af5e08422bd336b946e1 /tests/config
parentbc91347b5894c98964a12c6637d5ca91d9723b42 (diff)
Improve handling of fake home directory
There are a few tests that set up a fake home directory and a fake GLOBAL search path so that we can test things in global ignore or attribute or config files. This cleans up that code to work more robustly even if there is a test failure. This also fixes some valgrind warnings where scanning search paths for separators could end up doing a little bit of sketchy data access when coming to the end of search list.
Diffstat (limited to 'tests/config')
-rw-r--r--tests/config/global.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/tests/config/global.c b/tests/config/global.c
index d5f95f504..006b34628 100644
--- a/tests/config/global.c
+++ b/tests/config/global.c
@@ -2,22 +2,36 @@
#include "buffer.h"
#include "fileops.h"
+static git_config_level_t setting[3] = {
+ GIT_CONFIG_LEVEL_GLOBAL,
+ GIT_CONFIG_LEVEL_XDG,
+ GIT_CONFIG_LEVEL_SYSTEM
+};
+static char *restore[3];
+
void test_config_global__initialize(void)
{
+ int i;
git_buf path = GIT_BUF_INIT;
- cl_assert_equal_i(0, p_mkdir("home", 0777));
+ /* snapshot old settings to restore later */
+ for (i = 0; i < 3; ++i) {
+ cl_git_pass(
+ git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, setting[i], &path));
+ restore[i] = git_buf_detach(&path);
+ }
+
+ cl_git_pass(git_futils_mkdir_r("home", NULL, 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_assert_equal_i(0, p_mkdir("xdg", 0777));
- cl_assert_equal_i(0, p_mkdir("xdg/git", 0777));
+ cl_git_pass(git_futils_mkdir_r("xdg/git", NULL, 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_XDG, path.ptr));
- cl_assert_equal_i(0, p_mkdir("etc", 0777));
+ cl_git_pass(git_futils_mkdir_r("etc", NULL, 0777));
cl_git_pass(git_path_prettify(&path, "etc", NULL));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
@@ -27,13 +41,18 @@ void test_config_global__initialize(void)
void test_config_global__cleanup(void)
{
+ int i;
+
+ for (i = 0; i < 3; ++i) {
+ cl_git_pass(
+ git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, setting[i], restore[i]));
+ git__free(restore[i]);
+ restore[i] = NULL;
+ }
+
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)