summaryrefslogtreecommitdiff
path: root/tests/config/include.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-09-07 17:53:49 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-10-17 09:49:01 -0400
commitf0e693b18afbe1de37d7da5b5a8967b6c87d8e53 (patch)
treebe5e1cdbfa218ba81ec06bf45e45cfeb7f79a2a5 /tests/config/include.c
parent5346be3ddd3bcf19779c5d62e71f8442a0171133 (diff)
downloadlibgit2-ethomson/gitstr.tar.gz
str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstr
libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
Diffstat (limited to 'tests/config/include.c')
-rw-r--r--tests/config/include.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/tests/config/include.c b/tests/config/include.c
index b702d6211..9328f3cf6 100644
--- a/tests/config/include.c
+++ b/tests/config/include.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
static git_config *cfg;
@@ -7,14 +6,14 @@ static git_buf buf;
void test_config_include__initialize(void)
{
- cfg = NULL;
- git_buf_init(&buf, 0);
+ cfg = NULL;
+ memset(&buf, 0, sizeof(git_buf));
}
void test_config_include__cleanup(void)
{
- git_config_free(cfg);
- git_buf_dispose(&buf);
+ git_config_free(cfg);
+ git_buf_dispose(&buf);
}
void test_config_include__relative(void)
@@ -22,19 +21,21 @@ void test_config_include__relative(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-include")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
- cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ cl_assert_equal_s("huzzah", buf.ptr);
}
void test_config_include__absolute(void)
{
- cl_git_pass(git_buf_printf(&buf, "[include]\npath = %s/config-included", cl_fixture("config")));
+ git_str cfgdata = GIT_STR_INIT;
+ cl_git_pass(git_str_printf(&cfgdata, "[include]\npath = %s/config-included", cl_fixture("config")));
+
+ cl_git_mkfile("config-include-absolute", cfgdata.ptr);
+ git_str_dispose(&cfgdata);
- cl_git_mkfile("config-include-absolute", git_buf_cstr(&buf));
- git_buf_dispose(&buf);
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-absolute"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
- cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ cl_assert_equal_s("huzzah", buf.ptr);
cl_git_pass(p_unlink("config-include-absolute"));
}
@@ -47,7 +48,7 @@ void test_config_include__homedir(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-homedir"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
- cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ cl_assert_equal_s("huzzah", buf.ptr);
cl_sandbox_set_search_path_defaults();
@@ -66,10 +67,10 @@ void test_config_include__ordering(void)
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
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_assert_equal_s("hiya", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
- cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ cl_assert_equal_s("huzzah", buf.ptr);
cl_git_pass(p_unlink("included"));
cl_git_pass(p_unlink("including"));
@@ -92,7 +93,7 @@ void test_config_include__empty_path_sanely_handled(void)
cl_git_mkfile("a", "[include]\npath");
cl_git_pass(git_config_open_ondisk(&cfg, "a"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "include.path"));
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", buf.ptr);
cl_git_pass(p_unlink("a"));
}
@@ -105,7 +106,7 @@ void test_config_include__missing(void)
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_assert(git_error_last() == NULL);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ cl_assert_equal_s("baz", buf.ptr);
cl_git_pass(p_unlink("including"));
}
@@ -119,7 +120,7 @@ void test_config_include__missing_homedir(void)
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_assert(git_error_last() == NULL);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ cl_assert_equal_s("baz", buf.ptr);
cl_sandbox_set_search_path_defaults();
cl_git_pass(p_unlink("including"));
@@ -137,11 +138,11 @@ void test_config_include__depth2(void)
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ cl_assert_equal_s("baz", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar2"));
- cl_assert_equal_s("baz2", git_buf_cstr(&buf));
+ cl_assert_equal_s("baz2", buf.ptr);
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("middle"));
@@ -186,13 +187,13 @@ void test_config_include__rewriting_include_twice_refreshes_values(void)
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_mkfile("included", "[foo]\nother = value2");
cl_git_fail(git_config_get_string_buf(&buf, cfg, "foo.bar"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.other"));
cl_assert_equal_s(buf.ptr, "value2");
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_mkfile("included", "[foo]\nanother = bar");
cl_git_fail(git_config_get_string_buf(&buf, cfg, "foo.other"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.another"));