summaryrefslogtreecommitdiff
path: root/tests/libgit2/config
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-01-23 15:49:09 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2023-02-09 12:10:40 +0000
commitf32ec999b0dfcef6ac53afb754f21c5a758057a8 (patch)
treee1b2713c38e95f411fc5cfe4ffcc157c2f7cbcf4 /tests/libgit2/config
parent894543827d7ad62c7b70901e949305beea34cdbd (diff)
downloadlibgit2-f32ec999b0dfcef6ac53afb754f21c5a758057a8.tar.gz
tests: configure temporary homedirs correctly
Now that we've split the notion of the home directory from the global configuration store, our tests should use the appropriate one based on what they're doing.
Diffstat (limited to 'tests/libgit2/config')
-rw-r--r--tests/libgit2/config/include.c12
-rw-r--r--tests/libgit2/config/read.c9
2 files changed, 12 insertions, 9 deletions
diff --git a/tests/libgit2/config/include.c b/tests/libgit2/config/include.c
index 9328f3cf6..1b55fdc86 100644
--- a/tests/libgit2/config/include.c
+++ b/tests/libgit2/config/include.c
@@ -42,8 +42,13 @@ void test_config_include__absolute(void)
void test_config_include__homedir(void)
{
- cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config")));
+ git_str homefile = GIT_STR_INIT;
+
+ cl_fake_homedir(&homefile);
+ cl_git_pass(git_str_joinpath(&homefile, homefile.ptr, "config-included"));
+
cl_git_mkfile("config-include-homedir", "[include]\npath = ~/config-included");
+ cl_git_mkfile(homefile.ptr, "[foo \"bar\"]\n\tbaz = huzzah\n");
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-homedir"));
@@ -53,6 +58,8 @@ void test_config_include__homedir(void)
cl_sandbox_set_search_path_defaults();
cl_git_pass(p_unlink("config-include-homedir"));
+
+ git_str_dispose(&homefile);
}
/* We need to pretend that the variables were defined where the file was included */
@@ -113,7 +120,8 @@ void test_config_include__missing(void)
void test_config_include__missing_homedir(void)
{
- cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config")));
+ cl_fake_homedir(NULL);
+
cl_git_mkfile("including", "[include]\npath = ~/.nonexistentfile\n[foo]\nbar = baz");
git_error_clear();
diff --git a/tests/libgit2/config/read.c b/tests/libgit2/config/read.c
index a2e668c20..ac6459b9e 100644
--- a/tests/libgit2/config/read.c
+++ b/tests/libgit2/config/read.c
@@ -728,14 +728,11 @@ void test_config_read__path(void)
{
git_config *cfg;
git_buf path = GIT_BUF_INIT;
- git_buf old_path = GIT_BUF_INIT;
git_str home_path = GIT_STR_INIT;
git_str expected_path = GIT_STR_INIT;
- cl_git_pass(p_mkdir("fakehome", 0777));
- cl_git_pass(git_fs_path_prettify(&home_path, "fakehome", NULL));
- cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &old_path));
- cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, home_path.ptr));
+ cl_fake_homedir(&home_path);
+
cl_git_mkfile("./testconfig", "[some]\n path = ~/somefile");
cl_git_pass(git_fs_path_join_unrooted(&expected_path, "somefile", home_path.ptr, NULL));
@@ -761,8 +758,6 @@ void test_config_read__path(void)
cl_git_mkfile("./testconfig", "[some]\n path = ~user/foo");
cl_git_fail(git_config_get_path(&path, cfg, "some.path"));
- cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, old_path.ptr));
- git_buf_dispose(&old_path);
git_str_dispose(&home_path);
git_str_dispose(&expected_path);
git_config_free(cfg);