diff options
| author | Etienne Samson <samson.etienne@gmail.com> | 2017-07-21 17:45:44 +0000 |
|---|---|---|
| committer | Etienne Samson <samson.etienne@gmail.com> | 2017-11-15 00:36:56 +0100 |
| commit | f01a8587ded789103d342316696de4fef932a7de (patch) | |
| tree | bfbb0423cac3179f54b505628eac76a03559644d /tests/refs | |
| parent | b9b1f9f8a94ff7cc9bd3f4fe39651d0ab6dd391c (diff) | |
| download | libgit2-f01a8587ded789103d342316696de4fef932a7de.tar.gz | |
tests: make reflog_check_entry more clar-y
Diffstat (limited to 'tests/refs')
| -rw-r--r-- | tests/refs/reflog/messages.c | 38 | ||||
| -rw-r--r-- | tests/refs/reflog/reflog_helpers.c | 66 | ||||
| -rw-r--r-- | tests/refs/reflog/reflog_helpers.h | 8 |
3 files changed, 75 insertions, 37 deletions
diff --git a/tests/refs/reflog/messages.c b/tests/refs/reflog/messages.c index 9932f7381..5b83d14c1 100644 --- a/tests/refs/reflog/messages.c +++ b/tests/refs/reflog/messages.c @@ -37,23 +37,23 @@ void test_refs_reflog_messages__setting_head_updates_reflog(void) cl_git_pass(git_repository_set_head(g_repo, "refs/tags/test")); /* 1 */ cl_git_pass(git_repository_set_head(g_repo, "refs/remotes/test/master")); /* 0 */ - reflog_check_entry(g_repo, GIT_HEAD_FILE, 4, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 4, NULL, "refs/heads/haacked", "foo@example.com", "checkout: moving from master to haacked"); - reflog_check_entry(g_repo, GIT_HEAD_FILE, 3, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 3, NULL, "tags/test^{commit}", "foo@example.com", "checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d"); - reflog_check_entry(g_repo, GIT_HEAD_FILE, 2, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 2, "tags/test^{commit}", "refs/heads/haacked", "foo@example.com", "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked"); - reflog_check_entry(g_repo, GIT_HEAD_FILE, 1, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 1, "refs/heads/haacked", "tags/test^{commit}", "foo@example.com", "checkout: moving from haacked to test"); - reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, "tags/test^{commit}", "refs/remotes/test/master", "foo@example.com", "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to test/master"); @@ -61,7 +61,7 @@ void test_refs_reflog_messages__setting_head_updates_reflog(void) cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "haacked~0")); cl_git_pass(git_repository_set_head_detached_from_annotated(g_repo, annotated)); - reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, NULL, "refs/heads/haacked", "foo@example.com", "checkout: moving from be3563ae3f795b2b4353bcce3a527ad0a4f7f644 to haacked~0"); @@ -96,14 +96,14 @@ void test_refs_reflog_messages__detaching_writes_reflog(void) msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d"; git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d"); cl_git_pass(git_repository_set_head_detached(g_repo, &id)); - reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "e90810b8df3e80c413d903f631643c716887138d", NULL, msg); msg = "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked"; cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked")); - reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, "e90810b8df3e80c413d903f631643c716887138d", "258f0e2a959a364e40ed6603d5d44fbb24765b10", NULL, msg); @@ -120,14 +120,14 @@ void test_refs_reflog_messages__orphan_branch_does_not_count(void) msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d"; git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d"); cl_git_pass(git_repository_set_head_detached(g_repo, &id)); - reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "e90810b8df3e80c413d903f631643c716887138d", NULL, msg); /* Switching to an orphan branch does not write to the reflog */ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/orphan")); - reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "e90810b8df3e80c413d903f631643c716887138d", NULL, msg); @@ -135,7 +135,7 @@ void test_refs_reflog_messages__orphan_branch_does_not_count(void) /* And coming back, we set the source to zero */ msg = "checkout: moving from orphan to haacked"; cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked")); - reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, "0000000000000000000000000000000000000000", "258f0e2a959a364e40ed6603d5d44fbb24765b10", NULL, msg); @@ -245,7 +245,7 @@ void test_refs_reflog_messages__show_merge_for_merge_commits(void) "Merge commit", tree, 2, (const struct git_commit **) parent_commits)); - reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, NULL, git_oid_tostr_s(&merge_commit_oid), NULL, "commit (merge): Merge commit"); @@ -291,7 +291,7 @@ void test_refs_reflog_messages__renaming_ref(void) cl_git_pass(git_reference_rename(&new_ref, ref, "refs/heads/renamed", false, "message")); - reflog_check_entry(g_repo, git_reference_name(new_ref), 0, + cl_reflog_check_entry(g_repo, git_reference_name(new_ref), 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "foo@example.com", "message"); @@ -313,7 +313,7 @@ void test_refs_reflog_messages__updating_a_direct_reference(void) cl_git_pass(git_reference_set_target(&ref_out, ref, &target_id, message)); - reflog_check_entry(g_repo, "refs/heads/master", 0, + cl_reflog_check_entry(g_repo, "refs/heads/master", 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "258f0e2a959a364e40ed6603d5d44fbb24765b10", NULL, message); @@ -340,7 +340,7 @@ void test_refs_reflog_messages__creating_branches_default_messages(void) cl_git_pass(git_branch_create(&branch, g_repo, NEW_BRANCH_NAME, target, false)); cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target)))); - reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0, + cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0, GIT_OID_HEX_ZERO, git_oid_tostr_s(git_commit_id(target)), g_email, git_buf_cstr(&buf)); @@ -352,7 +352,7 @@ void test_refs_reflog_messages__creating_branches_default_messages(void) cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "e90810b8df3")); cl_git_pass(git_branch_create_from_annotated(&branch, g_repo, NEW_BRANCH_NAME, annotated, true)); - reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0, + cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0, GIT_OID_HEX_ZERO, git_oid_tostr_s(git_commit_id(target)), g_email, "branch: Created from e90810b8df3"); @@ -371,7 +371,7 @@ void test_refs_reflog_messages__moving_branch_default_message(void) git_oid_cpy(&id, git_reference_target(branch)); cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0)); - reflog_check_entry(g_repo, git_reference_name(new_branch), 0, + cl_reflog_check_entry(g_repo, git_reference_name(new_branch), 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", g_email, @@ -388,7 +388,7 @@ void test_refs_reflog_messages__detaching_head_default_message(void) cl_assert_equal_i(false, git_repository_head_detached(g_repo)); cl_git_pass(git_repository_detach_head(g_repo)); - reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, "checkout: moving from master to a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); @@ -399,7 +399,7 @@ void test_refs_reflog_messages__detaching_head_default_message(void) true, "REATTACH")); git_reference_free(ref); - reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, + cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, "REATTACH"); diff --git a/tests/refs/reflog/reflog_helpers.c b/tests/refs/reflog/reflog_helpers.c index 4f8f7cc0f..7a1b397c2 100644 --- a/tests/refs/reflog/reflog_helpers.c +++ b/tests/refs/reflog/reflog_helpers.c @@ -15,51 +15,89 @@ size_t reflog_entrycount(git_repository *repo, const char *name) return ret; } -void reflog_check_entry(git_repository *repo, const char *reflog, size_t idx, +void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx, const char *old_spec, const char *new_spec, - const char *email, const char *message) + const char *email, const char *message, const char *file, int line) { git_reflog *log; const git_reflog_entry *entry; + git_buf result = GIT_BUF_INIT; cl_git_pass(git_reflog_read(&log, repo, reflog)); entry = git_reflog_entry_byindex(log, idx); + if (entry == NULL) + clar__fail(file, line, "Reflog has no such entry", NULL, 1); if (old_spec) { git_object *obj = NULL; if (git_revparse_single(&obj, repo, old_spec) == GIT_OK) { - cl_assert_equal_oid(git_object_id(obj), git_reflog_entry_id_old(entry)); + if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_old(entry)) != 0) { + git_oid__writebuf(&result, "\tOld OID: \"", git_object_id(obj)); + git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry)); + git_buf_puts(&result, "\"\n"); + } git_object_free(obj); } else { git_oid *oid = git__calloc(1, sizeof(*oid)); git_oid_fromstr(oid, old_spec); - cl_assert_equal_oid(oid, git_reflog_entry_id_old(entry)); + if (git_oid_cmp(oid, git_reflog_entry_id_old(entry)) != 0) { + git_oid__writebuf(&result, "\tOld OID: \"", oid); + git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry)); + git_buf_puts(&result, "\"\n"); + } git__free(oid); } } if (new_spec) { git_object *obj = NULL; if (git_revparse_single(&obj, repo, new_spec) == GIT_OK) { - cl_assert_equal_oid(git_object_id(obj), git_reflog_entry_id_new(entry)); + if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_new(entry)) != 0) { + git_oid__writebuf(&result, "\tNew OID: \"", git_object_id(obj)); + git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry)); + git_buf_puts(&result, "\"\n"); + } git_object_free(obj); } else { git_oid *oid = git__calloc(1, sizeof(*oid)); git_oid_fromstr(oid, new_spec); - cl_assert_equal_oid(oid, git_reflog_entry_id_new(entry)); + if (git_oid_cmp(oid, git_reflog_entry_id_new(entry)) != 0) { + git_oid__writebuf(&result, "\tNew OID: \"", oid); + git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry)); + git_buf_puts(&result, "\"\n"); + } git__free(oid); } } - if (email) { - cl_assert_equal_s(email, git_reflog_entry_committer(entry)->email); - } + if (email && strcmp(email, git_reflog_entry_committer(entry)->email) != 0) + git_buf_printf(&result, "\tEmail: \"%s\" != \"%s\"\n", email, git_reflog_entry_committer(entry)->email); + if (message) { - cl_assert_equal_s(message, git_reflog_entry_message(entry)); + const char *entry_msg = git_reflog_entry_message(entry); + if (entry_msg == NULL) entry_msg = ""; + + if (entry_msg && strcmp(message, entry_msg) != 0) + git_buf_printf(&result, "\tMessage: \"%s\" != \"%s\"\n", message, entry_msg); } + if (git_buf_len(&result) != 0) + clar__fail(file, line, "Reflog entry mismatch", git_buf_cstr(&result), 1); + git_buf_free(&result); git_reflog_free(log); } +static int reflog_entry_tostr(git_buf *out, const git_reflog_entry *entry) +{ + char old_oid[GIT_OID_HEXSZ], new_oid[GIT_OID_HEXSZ]; + + assert(out && entry); + + git_oid_tostr((char *)&old_oid, GIT_OID_HEXSZ, git_reflog_entry_id_old(entry)); + git_oid_tostr((char *)&new_oid, GIT_OID_HEXSZ, git_reflog_entry_id_new(entry)); + + return git_buf_printf(out, "%s %s %s %s", old_oid, new_oid, "somesig", git_reflog_entry_message(entry)); +} + void reflog_print(git_repository *repo, const char *reflog_name) { git_reflog *reflog; @@ -70,12 +108,8 @@ void reflog_print(git_repository *repo, const char *reflog_name) for (idx = 0; idx < git_reflog_entrycount(reflog); idx++) { const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, idx); - char old_oid[GIT_OID_HEXSZ], new_oid[GIT_OID_HEXSZ];; - - git_oid_tostr((char *)&old_oid, GIT_OID_HEXSZ, git_reflog_entry_id_old(entry)); - git_oid_tostr((char *)&new_oid, GIT_OID_HEXSZ, git_reflog_entry_id_new(entry)); - - git_buf_printf(&out, "%ld: %s %s %s %s\n", idx, old_oid, new_oid, "somesig", git_reflog_entry_message(entry)); + reflog_entry_tostr(&out, entry); + git_buf_putc(&out, '\n'); } fprintf(stderr, "%s", git_buf_cstr(&out)); diff --git a/tests/refs/reflog/reflog_helpers.h b/tests/refs/reflog/reflog_helpers.h index fa343c657..80814ea28 100644 --- a/tests/refs/reflog/reflog_helpers.h +++ b/tests/refs/reflog/reflog_helpers.h @@ -1,6 +1,10 @@ size_t reflog_entrycount(git_repository *repo, const char *name); -void reflog_check_entry(git_repository *repo, const char *reflog, size_t idx, + +#define cl_reflog_check_entry(repo, reflog, idx, old_spec, new_spec, email, message) \ + cl_reflog_check_entry_(repo, reflog, idx, old_spec, new_spec, email, message, __FILE__, __LINE__) + +void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx, const char *old_spec, const char *new_spec, - const char *email, const char *message); + const char *email, const char *message, const char *file, int line); void reflog_print(git_repository *repo, const char *reflog_name); |
