summaryrefslogtreecommitdiff
path: root/tests/core/rmdir.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/core/rmdir.c
parent5346be3ddd3bcf19779c5d62e71f8442a0171133 (diff)
downloadlibgit2-f0e693b18afbe1de37d7da5b5a8967b6c87d8e53.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/core/rmdir.c')
-rw-r--r--tests/core/rmdir.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/tests/core/rmdir.c b/tests/core/rmdir.c
index b436b97e0..56ea320be 100644
--- a/tests/core/rmdir.c
+++ b/tests/core/rmdir.c
@@ -5,26 +5,26 @@ static const char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test";
void test_core_rmdir__initialize(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_must_pass(p_mkdir(empty_tmp_dir, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_one"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one/two_one"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_two"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one/two_two"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_two/three"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one/two_two/three"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/two"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/two"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_core_rmdir__cleanup(void)
@@ -36,25 +36,25 @@ void test_core_rmdir__cleanup(void)
/* make sure empty dir can be deleted recusively */
void test_core_rmdir__delete_recursive(void)
{
- git_buf path = GIT_BUF_INIT;
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one"));
- cl_assert(git_path_exists(git_buf_cstr(&path)));
+ git_str path = GIT_STR_INIT;
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one"));
+ cl_assert(git_path_exists(git_str_cstr(&path)));
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
- cl_assert(!git_path_exists(git_buf_cstr(&path)));
+ cl_assert(!git_path_exists(git_str_cstr(&path)));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
/* make sure non-empty dir cannot be deleted recusively */
void test_core_rmdir__fail_to_delete_non_empty_dir(void)
{
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
+ cl_git_pass(git_str_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
- cl_git_mkfile(git_buf_cstr(&file), "dummy");
+ cl_git_mkfile(git_str_cstr(&file), "dummy");
cl_git_fail(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
@@ -63,7 +63,7 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void)
cl_assert(!git_path_exists(empty_tmp_dir));
- git_buf_dispose(&file);
+ git_str_dispose(&file);
}
void test_core_rmdir__keep_base(void)
@@ -74,47 +74,47 @@ void test_core_rmdir__keep_base(void)
void test_core_rmdir__can_skip_non_empty_dir(void)
{
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
+ cl_git_pass(git_str_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
- cl_git_mkfile(git_buf_cstr(&file), "dummy");
+ cl_git_mkfile(git_str_cstr(&file), "dummy");
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_SKIP_NONEMPTY));
- cl_assert(git_path_exists(git_buf_cstr(&file)) == true);
+ cl_assert(git_path_exists(git_str_cstr(&file)) == true);
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_REMOVE_FILES));
cl_assert(git_path_exists(empty_tmp_dir) == false);
- git_buf_dispose(&file);
+ git_str_dispose(&file);
}
void test_core_rmdir__can_remove_empty_parents(void)
{
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
cl_git_pass(
- git_buf_joinpath(&file, empty_tmp_dir, "/one/two_two/three/file.txt"));
- cl_git_mkfile(git_buf_cstr(&file), "dummy");
- cl_assert(git_path_isfile(git_buf_cstr(&file)));
+ git_str_joinpath(&file, empty_tmp_dir, "/one/two_two/three/file.txt"));
+ cl_git_mkfile(git_str_cstr(&file), "dummy");
+ cl_assert(git_path_isfile(git_str_cstr(&file)));
cl_git_pass(git_futils_rmdir_r("one/two_two/three/file.txt", empty_tmp_dir,
GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_EMPTY_PARENTS));
- cl_assert(!git_path_exists(git_buf_cstr(&file)));
+ cl_assert(!git_path_exists(git_str_cstr(&file)));
- git_buf_rtruncate_at_char(&file, '/'); /* three (only contained file.txt) */
- cl_assert(!git_path_exists(git_buf_cstr(&file)));
+ git_str_rtruncate_at_char(&file, '/'); /* three (only contained file.txt) */
+ cl_assert(!git_path_exists(git_str_cstr(&file)));
- git_buf_rtruncate_at_char(&file, '/'); /* two_two (only contained three) */
- cl_assert(!git_path_exists(git_buf_cstr(&file)));
+ git_str_rtruncate_at_char(&file, '/'); /* two_two (only contained three) */
+ cl_assert(!git_path_exists(git_str_cstr(&file)));
- git_buf_rtruncate_at_char(&file, '/'); /* one (contained two_one also) */
- cl_assert(git_path_exists(git_buf_cstr(&file)));
+ git_str_rtruncate_at_char(&file, '/'); /* one (contained two_one also) */
+ cl_assert(git_path_exists(git_str_cstr(&file)));
cl_assert(git_path_exists(empty_tmp_dir) == true);
- git_buf_dispose(&file);
+ git_str_dispose(&file);
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
}