diff options
| author | Russell Belfer <rb@github.com> | 2014-05-15 10:56:28 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2014-05-15 10:56:28 -0700 |
| commit | 8487e23797cef0284b592b5ef93eaacbac7196dc (patch) | |
| tree | da883f84114eceaf6e69f7b87e16e7aac45bbdad /tests/config | |
| parent | 4af0ef9690e9fdfc81afbeed7039d02a5f191001 (diff) | |
| download | libgit2-8487e23797cef0284b592b5ef93eaacbac7196dc.tar.gz | |
Better search path sandboxingrb/restore-search-paths
There are a number of tests that modify the global or system
search paths during the tests. This adds a helper function to
make it easier to restore those paths and makes sure that they
are getting restored in a manner that preserves test isolation.
Diffstat (limited to 'tests/config')
| -rw-r--r-- | tests/config/global.c | 28 | ||||
| -rw-r--r-- | tests/config/include.c | 2 |
2 files changed, 3 insertions, 27 deletions
diff --git a/tests/config/global.c b/tests/config/global.c index 006b34628..fc471f90d 100644 --- a/tests/config/global.c +++ b/tests/config/global.c @@ -2,25 +2,10 @@ #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; - /* 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( @@ -41,18 +26,7 @@ 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)); + cl_sandbox_set_search_path_defaults(); } void test_config_global__open_global(void) diff --git a/tests/config/include.c b/tests/config/include.c index 535573808..58bc690ff 100644 --- a/tests/config/include.c +++ b/tests/config/include.c @@ -47,6 +47,8 @@ void test_config_include__homedir(void) cl_assert_equal_s(str, "huzzah"); git_config_free(cfg); + + cl_sandbox_set_search_path_defaults(); } void test_config_include__refresh(void) |
