summaryrefslogtreecommitdiff
path: root/tests/config/include.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-12-21 15:31:03 +0000
committerCarlos Martín Nieto <cmn@dwim.me>2015-03-03 18:35:12 +0100
commit9a97f49e3aa15edc479fc590f4b28fc44c155c40 (patch)
treeb85de2d396b9d0d408f688212c0cdc74347ea7b3 /tests/config/include.c
parent76f034180aee96fcc1fffd5267ccbc6ada68482a (diff)
downloadlibgit2-cmn/config-borrow-entry.tar.gz
config: borrow refcounted referencescmn/config-borrow-entry
This changes the get_entry() method to return a refcounted version of the config entry, which you have to free when you're done. This allows us to avoid freeing the memory in which the entry is stored on a refresh, which may happen at any time for a live config. For this reason, get_string() has been forbidden on live configs and a new function get_string_buf() has been added, which stores the string in a git_buf which the user then owns. The functions which parse the string value takea advantage of the borrowing to parse safely and then release the entry.
Diffstat (limited to 'tests/config/include.c')
-rw-r--r--tests/config/include.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/tests/config/include.c b/tests/config/include.c
index 8232af489..e9f542afe 100644
--- a/tests/config/include.c
+++ b/tests/config/include.c
@@ -5,20 +5,20 @@
void test_config_include__relative(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-include")));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
- cl_assert_equal_s(str, "huzzah");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
+ cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
void test_config_include__absolute(void)
{
git_config *cfg;
- const char *str;
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_buf_printf(&buf, "[include]\npath = %s/config-included", cl_fixture("config")));
@@ -27,25 +27,27 @@ void test_config_include__absolute(void)
git_buf_free(&buf);
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-absolute"));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
- cl_assert_equal_s(str, "huzzah");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
+ cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
void test_config_include__homedir(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config")));
cl_git_mkfile("config-include-homedir", "[include]\npath = ~/config-included");
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-homedir"));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
- cl_assert_equal_s(str, "huzzah");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
+ cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
cl_sandbox_set_search_path_defaults();
@@ -55,7 +57,7 @@ void test_config_include__homedir(void)
void test_config_include__ordering(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_mkfile("included", "[foo \"bar\"]\nbaz = hurrah\nfrotz = hiya");
cl_git_mkfile("including",
@@ -65,11 +67,13 @@ void test_config_include__ordering(void)
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.frotz"));
- cl_assert_equal_s(str, "hiya");
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
- cl_assert_equal_s(str, "huzzah");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.frotz"));
+ cl_assert_equal_s("hiya", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
+ cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -90,16 +94,17 @@ void test_config_include__depth(void)
void test_config_include__missing(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_mkfile("including", "[include]\npath = nonexistentfile\n[foo]\nbar = baz");
giterr_clear();
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_assert(giterr_last() == NULL);
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar"));
- cl_assert_equal_s(str, "baz");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
+ cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -107,7 +112,7 @@ void test_config_include__missing(void)
void test_config_include__depth2(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
const char *content = "[include]\n" replicate10(replicate10("path=bottom\n"));
cl_git_mkfile("top-level", "[include]\npath = middle\n[foo]\nbar = baz");
@@ -116,11 +121,12 @@ void test_config_include__depth2(void)
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar"));
- cl_assert_equal_s(str, "baz");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
+ cl_assert_equal_s("baz", git_buf_cstr(&buf));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar2"));
- cl_assert_equal_s(str, "baz2");
+ git_buf_clear(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar2"));
+ cl_assert_equal_s("baz2", git_buf_cstr(&buf));
git_config_free(cfg);
}