tests: repo: refactor template path handling The repo::template test suite makes use of quite a few local variables that could be consolidated. Do so to make the code easier to read.
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
diff --git a/tests/repo/template.c b/tests/repo/template.c
index 9b89043..c54c0c1 100644
--- a/tests/repo/template.c
+++ b/tests/repo/template.c
@@ -101,35 +101,29 @@ static void assert_mode_seems_okay(
static const char *template_sandbox(const char *name)
{
- git_buf hooks_path = GIT_BUF_INIT, link_path = GIT_BUF_INIT,
- dotfile_path = GIT_BUF_INIT;
- const char *path = cl_fixture(name);
+ git_buf path = GIT_BUF_INIT;
cl_fixture_sandbox(name);
- /* create a symlink from link.sample to update.sample if the filesystem
+ /*
+ * Create a symlink from link.sample to update.sample if the filesystem
* supports it.
*/
-
- cl_git_pass(git_buf_joinpath(&hooks_path, name, "hooks"));
- cl_git_pass(git_buf_joinpath(&link_path, hooks_path.ptr, "link.sample"));
-
+ cl_git_pass(git_buf_join3(&path, '/', name, "hooks", "link.sample"));
#ifdef GIT_WIN32
- cl_git_mkfile(link_path.ptr, "#!/bin/sh\necho hello, world\n");
+ cl_git_mkfile(path.ptr, "#!/bin/sh\necho hello, world\n");
#else
- cl_must_pass(symlink("update.sample", link_path.ptr));
+ cl_must_pass(p_symlink("update.sample", path.ptr));
#endif
- /* create a file starting with a dot */
- cl_git_pass(git_buf_joinpath(&dotfile_path, hooks_path.ptr, ".dotfile"));
- cl_git_mkfile(dotfile_path.ptr, "something\n");
- git_buf_dispose(&dotfile_path);
+ git_buf_clear(&path);
- git_buf_dispose(&dotfile_path);
- git_buf_dispose(&link_path);
- git_buf_dispose(&hooks_path);
+ /* Create a file starting with a dot */
+ cl_git_pass(git_buf_join3(&path, '/', name, "hooks", ".dotfile"));
+ cl_git_mkfile(path.ptr, "something\n");
- return path;
+ git_buf_dispose(&path);
+ return cl_fixture(name);
}
static void configure_templatedir(const char *template_path)
@@ -139,19 +133,16 @@ static void configure_templatedir(const char *template_path)
static void validate_templates(git_repository *repo, const char *template_path)
{
- git_buf template_description = GIT_BUF_INIT;
- git_buf repo_description = GIT_BUF_INIT;
- git_buf expected = GIT_BUF_INIT;
- git_buf actual = GIT_BUF_INIT;
+ git_buf path = GIT_BUF_INIT, expected = GIT_BUF_INIT, actual = GIT_BUF_INIT;
int filemode;
- cl_git_pass(git_buf_joinpath(&template_description, template_path,
- "description"));
- cl_git_pass(git_buf_joinpath(&repo_description, git_repository_path(repo),
- "description"));
+ cl_git_pass(git_buf_joinpath(&path, template_path, "description"));
+ cl_git_pass(git_futils_readbuffer(&expected, path.ptr));
- cl_git_pass(git_futils_readbuffer(&expected, template_description.ptr));
- cl_git_pass(git_futils_readbuffer(&actual, repo_description.ptr));
+ git_buf_clear(&path);
+
+ cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "description"));
+ cl_git_pass(git_futils_readbuffer(&actual, path.ptr));
cl_assert_equal_s(expected.ptr, actual.ptr);
@@ -160,19 +151,16 @@ static void validate_templates(git_repository *repo, const char *template_path)
assert_hooks_match(
template_path, git_repository_path(repo),
"hooks/update.sample", filemode);
-
assert_hooks_match(
template_path, git_repository_path(repo),
"hooks/link.sample", filemode);
-
assert_hooks_match(
template_path, git_repository_path(repo),
"hooks/.dotfile", filemode);
git_buf_dispose(&expected);
git_buf_dispose(&actual);
- git_buf_dispose(&repo_description);
- git_buf_dispose(&template_description);
+ git_buf_dispose(&path);
}
void test_repo_template__external_templates_specified_in_options(void)