diff options
author | Russell Belfer <rb@github.com> | 2014-05-01 14:47:33 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-05-02 09:21:33 -0700 |
commit | 0f603132bc2397bf8308e72651c56cb7dbd3ad70 (patch) | |
tree | 0ea052ae8023fc0929e8af5e08422bd336b946e1 /tests/clar_libgit2.c | |
parent | bc91347b5894c98964a12c6637d5ca91d9723b42 (diff) | |
download | libgit2-0f603132bc2397bf8308e72651c56cb7dbd3ad70.tar.gz |
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/clar_libgit2.c')
-rw-r--r-- | tests/clar_libgit2.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/tests/clar_libgit2.c b/tests/clar_libgit2.c index 6f6143dad..9ec9a6419 100644 --- a/tests/clar_libgit2.c +++ b/tests/clar_libgit2.c @@ -484,23 +484,34 @@ void clar__assert_equal_file( (size_t)expected_bytes, (size_t)total_bytes); } -void cl_fake_home(git_buf *restore) +static char *_cl_restore_home = NULL; + +void cl_fake_home_cleanup(void *payload) +{ + char *restore = _cl_restore_home; + _cl_restore_home = NULL; + + GIT_UNUSED(payload); + + cl_git_pass(git_libgit2_opts( + GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, restore)); + git__free(restore); +} + +void cl_fake_home(void) { git_buf path = GIT_BUF_INIT; cl_git_pass(git_libgit2_opts( - GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, restore)); + GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &path)); + + _cl_restore_home = git_buf_detach(&path); + cl_set_cleanup(cl_fake_home_cleanup, NULL); - cl_must_pass(p_mkdir("home", 0777)); + if (!git_path_exists("home")) + cl_must_pass(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)); git_buf_free(&path); } - -void cl_fake_home_cleanup(git_buf *restore) -{ - cl_git_pass(git_libgit2_opts( - GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, restore->ptr)); - git_buf_free(restore); -} |