summaryrefslogtreecommitdiff
path: root/tests-clar/commit/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests-clar/commit/parse.c')
-rw-r--r--tests-clar/commit/parse.c59
1 files changed, 28 insertions, 31 deletions
diff --git a/tests-clar/commit/parse.c b/tests-clar/commit/parse.c
index b99d27991..415860a6e 100644
--- a/tests-clar/commit/parse.c
+++ b/tests-clar/commit/parse.c
@@ -264,37 +264,40 @@ gpgsig -----BEGIN PGP SIGNATURE-----\n\
a simple commit which works\n",
};
-void test_commit_parse__entire_commit(void)
+static int parse_commit(git_commit **out, const char *buffer)
{
- const int broken_commit_count = sizeof(failing_commit_cases) / sizeof(*failing_commit_cases);
- const int working_commit_count = sizeof(passing_commit_cases) / sizeof(*passing_commit_cases);
- int i;
+ git_commit *commit;
+ git_odb_object fake_odb_object;
+ int error;
- for (i = 0; i < broken_commit_count; ++i) {
- git_commit *commit;
- commit = (git_commit*)git__malloc(sizeof(git_commit));
- memset(commit, 0x0, sizeof(git_commit));
- commit->object.repo = g_repo;
+ commit = (git_commit*)git__malloc(sizeof(git_commit));
+ memset(commit, 0x0, sizeof(git_commit));
+ commit->object.repo = g_repo;
- cl_git_fail(git_commit__parse_buffer(
- commit, failing_commit_cases[i], strlen(failing_commit_cases[i]))
- );
+ memset(&fake_odb_object, 0x0, sizeof(git_odb_object));
+ fake_odb_object.buffer = (char *)buffer;
+ fake_odb_object.cached.size = strlen(fake_odb_object.buffer);
- git_commit__free(commit);
- }
+ error = git_commit__parse(commit, &fake_odb_object);
- for (i = 0; i < working_commit_count; ++i) {
- git_commit *commit;
+ *out = commit;
+ return error;
+}
+
+void test_commit_parse__entire_commit(void)
+{
+ const int failing_commit_count = ARRAY_SIZE(failing_commit_cases);
+ const int passing_commit_count = ARRAY_SIZE(passing_commit_cases);
+ int i;
+ git_commit *commit;
- commit = (git_commit*)git__malloc(sizeof(git_commit));
- memset(commit, 0x0, sizeof(git_commit));
- commit->object.repo = g_repo;
+ for (i = 0; i < failing_commit_count; ++i) {
+ cl_git_fail(parse_commit(&commit, failing_commit_cases[i]));
+ git_commit__free(commit);
+ }
- cl_git_pass(git_commit__parse_buffer(
- commit,
- passing_commit_cases[i],
- strlen(passing_commit_cases[i]))
- );
+ for (i = 0; i < passing_commit_count; ++i) {
+ cl_git_pass(parse_commit(&commit, passing_commit_cases[i]));
if (!i)
cl_assert_equal_s("", git_commit_message(commit));
@@ -383,13 +386,7 @@ This commit has a few LF at the start of the commit message";
\n\
This commit has a few LF at the start of the commit message";
- commit = (git_commit*)git__malloc(sizeof(git_commit));
- memset(commit, 0x0, sizeof(git_commit));
- commit->object.repo = g_repo;
-
- cl_git_pass(git_commit__parse_buffer(commit, buffer, strlen(buffer)));
-
+ cl_git_pass(parse_commit(&commit, buffer));
cl_assert_equal_s(message, git_commit_message(commit));
-
git_commit__free(commit);
}