tests: don't generate false positives on empty path segments
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
diff --git a/tests/iterator/workdir.c b/tests/iterator/workdir.c
index 547fb7d..82ee363 100644
--- a/tests/iterator/workdir.c
+++ b/tests/iterator/workdir.c
@@ -1024,7 +1024,7 @@ static void create_paths(const char *root, int depth)
int i;
cl_git_pass(git_buf_puts(&fullpath, root));
- cl_git_pass(git_buf_putc(&fullpath, '/'));
+ cl_git_pass(git_path_to_dir(&fullpath));
root_len = fullpath.size;
diff --git a/tests/merge/workdir/setup.c b/tests/merge/workdir/setup.c
index ad29fcd..0b85f27 100644
--- a/tests/merge/workdir/setup.c
+++ b/tests/merge/workdir/setup.c
@@ -49,7 +49,7 @@ static bool test_file_contents(const char *filename, const char *expected)
git_buf file_path_buf = GIT_BUF_INIT, file_buf = GIT_BUF_INIT;
bool equals;
- git_buf_printf(&file_path_buf, "%s/%s", git_repository_path(repo), filename);
+ git_buf_joinpath(&file_path_buf, git_repository_path(repo), filename);
cl_git_pass(git_futils_readbuffer(&file_buf, file_path_buf.ptr));
equals = (strcmp(file_buf.ptr, expected) == 0);
@@ -64,7 +64,7 @@ static void write_file_contents(const char *filename, const char *output)
{
git_buf file_path_buf = GIT_BUF_INIT;
- git_buf_printf(&file_path_buf, "%s/%s", git_repository_path(repo),
+ git_buf_joinpath(&file_path_buf, git_repository_path(repo),
filename);
cl_git_rewritefile(file_path_buf.ptr, output);
diff --git a/tests/odb/foreach.c b/tests/odb/foreach.c
index 7a45a57..0211238 100644
--- a/tests/odb/foreach.c
+++ b/tests/odb/foreach.c
@@ -127,7 +127,7 @@ void test_odb_foreach__files_in_objects_dir(void)
cl_fixture_sandbox("testrepo.git");
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
- cl_git_pass(git_buf_printf(&buf, "%s/objects/somefile", git_repository_path(repo)));
+ cl_git_pass(git_buf_joinpath(&buf, git_repository_path(repo), "objects/somefile"));
cl_git_mkfile(buf.ptr, "");
git_buf_dispose(&buf);
diff --git a/tests/worktree/merge.c b/tests/worktree/merge.c
index 4b74382..2a12060 100644
--- a/tests/worktree/merge.c
+++ b/tests/worktree/merge.c
@@ -70,9 +70,9 @@ void test_worktree_merge__merge_setup(void)
ours, (const git_annotated_commit **)&theirs, 1));
for (i = 0; i < ARRAY_SIZE(merge_files); i++) {
- git_buf_clear(&path);
- cl_git_pass(git_buf_printf(&path, "%s/%s",
- fixture.worktree->gitdir, merge_files[i]));
+ cl_git_pass(git_buf_joinpath(&path,
+ fixture.worktree->gitdir,
+ merge_files[i]));
cl_assert(git_path_exists(path.ptr));
}
diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c
index f2078a3..9b87bfa 100644
--- a/tests/worktree/worktree.c
+++ b/tests/worktree/worktree.c
@@ -44,8 +44,9 @@ void test_worktree_worktree__list_with_invalid_worktree_dirs(void)
git_strarray wts;
size_t i, j, len;
- cl_git_pass(git_buf_printf(&path, "%s/worktrees/invalid",
- fixture.repo->commondir));
+ cl_git_pass(git_buf_joinpath(&path,
+ fixture.repo->commondir,
+ "worktrees/invalid"));
cl_git_pass(p_mkdir(path.ptr, 0755));
len = path.size;
@@ -145,9 +146,9 @@ void test_worktree_worktree__open_invalid_commondir(void)
git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/commondir"));
- cl_git_pass(git_buf_printf(&path,
- "%s/worktrees/testrepo-worktree/commondir",
- fixture.repo->commondir));
+ cl_git_pass(git_buf_joinpath(&path,
+ fixture.repo->commondir,
+ "worktrees/testrepo-worktree/commondir"));
cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
@@ -165,9 +166,9 @@ void test_worktree_worktree__open_invalid_gitdir(void)
git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/gitdir"));
- cl_git_pass(git_buf_printf(&path,
- "%s/worktrees/testrepo-worktree/gitdir",
- fixture.repo->commondir));
+ cl_git_pass(git_buf_joinpath(&path,
+ fixture.repo->commondir,
+ "worktrees/testrepo-worktree/gitdir"));
cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));