summaryrefslogtreecommitdiff
path: root/tests/repo
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-05-15 10:56:28 -0700
committerRussell Belfer <rb@github.com>2014-05-15 10:56:28 -0700
commit8487e23797cef0284b592b5ef93eaacbac7196dc (patch)
treeda883f84114eceaf6e69f7b87e16e7aac45bbdad /tests/repo
parent4af0ef9690e9fdfc81afbeed7039d02a5f191001 (diff)
downloadlibgit2-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/repo')
-rw-r--r--tests/repo/config.c38
-rw-r--r--tests/repo/open.c5
2 files changed, 23 insertions, 20 deletions
diff --git a/tests/repo/config.c b/tests/repo/config.c
index 2e7be37aa..93dedd576 100644
--- a/tests/repo/config.c
+++ b/tests/repo/config.c
@@ -8,7 +8,8 @@ static git_buf path = GIT_BUF_INIT;
void test_repo_config__initialize(void)
{
cl_fixture_sandbox("empty_standard_repo");
- cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
+ cl_git_pass(cl_rename(
+ "empty_standard_repo/.gitted", "empty_standard_repo/.git"));
git_buf_clear(&path);
@@ -18,15 +19,19 @@ void test_repo_config__initialize(void)
void test_repo_config__cleanup(void)
{
- cl_git_pass(git_path_prettify(&path, "alternate", NULL));
- cl_git_pass(git_futils_rmdir_r(path.ptr, NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_sandbox_set_search_path_defaults();
+
git_buf_free(&path);
+
+ cl_git_pass(
+ git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES));
cl_assert(!git_path_isdir("alternate"));
cl_fixture_cleanup("empty_standard_repo");
+
}
-void test_repo_config__open_missing_global(void)
+void test_repo_config__can_open_global_when_there_is_no_file(void)
{
git_repository *repo;
git_config *config, *global;
@@ -40,23 +45,23 @@ void test_repo_config__open_missing_global(void)
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
cl_git_pass(git_repository_config(&config, repo));
- cl_git_pass(git_config_open_level(&global, config, GIT_CONFIG_LEVEL_GLOBAL));
+ cl_git_pass(git_config_open_level(
+ &global, config, GIT_CONFIG_LEVEL_GLOBAL));
cl_git_pass(git_config_set_string(global, "test.set", "42"));
git_config_free(global);
git_config_free(config);
git_repository_free(repo);
-
- git_sysdir_global_shutdown();
}
-void test_repo_config__open_missing_global_with_separators(void)
+void test_repo_config__can_open_missing_global_with_separators(void)
{
git_repository *repo;
git_config *config, *global;
- cl_git_pass(git_buf_printf(&path, "%c%s", GIT_PATH_LIST_SEPARATOR, "dummy"));
+ cl_git_pass(git_buf_printf(
+ &path, "%c%s", GIT_PATH_LIST_SEPARATOR, "dummy"));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
@@ -69,20 +74,19 @@ void test_repo_config__open_missing_global_with_separators(void)
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
cl_git_pass(git_repository_config(&config, repo));
- cl_git_pass(git_config_open_level(&global, config, GIT_CONFIG_LEVEL_GLOBAL));
+ cl_git_pass(git_config_open_level(
+ &global, config, GIT_CONFIG_LEVEL_GLOBAL));
cl_git_pass(git_config_set_string(global, "test.set", "42"));
git_config_free(global);
git_config_free(config);
git_repository_free(repo);
-
- git_sysdir_global_shutdown();
}
#include "repository.h"
-void test_repo_config__read_no_configs(void)
+void test_repo_config__read_with_no_configs_at_all(void)
{
git_repository *repo;
int val;
@@ -106,9 +110,9 @@ void test_repo_config__read_no_configs(void)
cl_assert_equal_i(GIT_ABBREV_DEFAULT, val);
git_repository_free(repo);
- git_sysdir_global_shutdown();
+ /* with no local config, just system */
- /* with just system */
+ cl_sandbox_set_search_path_defaults();
cl_must_pass(p_mkdir("alternate/1", 0777));
cl_git_pass(git_buf_joinpath(&path, path.ptr, "1"));
@@ -123,7 +127,7 @@ void test_repo_config__read_no_configs(void)
cl_assert_equal_i(10, val);
git_repository_free(repo);
- /* with xdg + system */
+ /* with just xdg + system */
cl_must_pass(p_mkdir("alternate/2", 0777));
path.ptr[path.size - 1] = '2';
@@ -204,6 +208,4 @@ void test_repo_config__read_no_configs(void)
cl_assert(!git_path_exists("empty_standard_repo/.git/config"));
cl_assert(!git_path_exists("alternate/3/.gitconfig"));
-
- git_sysdir_global_shutdown();
}
diff --git a/tests/repo/open.c b/tests/repo/open.c
index 190adff1c..637c785d5 100644
--- a/tests/repo/open.c
+++ b/tests/repo/open.c
@@ -298,7 +298,8 @@ void test_repo_open__no_config(void)
git_config *config;
cl_fixture_sandbox("empty_standard_repo");
- cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
+ cl_git_pass(cl_rename(
+ "empty_standard_repo/.gitted", "empty_standard_repo/.git"));
/* remove local config */
cl_git_pass(git_futils_rmdir_r(
@@ -325,7 +326,7 @@ void test_repo_open__no_config(void)
git_repository_free(repo);
cl_fixture_cleanup("empty_standard_repo");
- git_sysdir_global_shutdown();
+ cl_sandbox_set_search_path_defaults();
}
void test_repo_open__force_bare(void)