Introduce cl_assert_equal_oid · nodegit/libgit2@0cee70e · GitHub
Skip to content

Commit 0cee70e

Browse files
committed
Introduce cl_assert_equal_oid
1 parent e1fc03c commit 0cee70e

39 files changed

Lines changed: 158 additions & 148 deletions

‎tests/blame/blame_helpers.c‎

Lines changed: 1 addition & 1 deletion

‎tests/checkout/binaryunicode.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ static void execute_test(void)
3737
/* Verify that the lenna.jpg file was checked out correctly */
3838
cl_git_pass(git_oid_fromstr(&check, "8ab005d890fe53f65eda14b23672f60d9f4ec5a1"));
3939
cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/lenna.jpg", GIT_OBJ_BLOB));
40-
cl_assert(git_oid_equal(&oid, &check));
40+
cl_assert_equal_oid(&oid, &check);
4141

4242
/* Verify that the text file was checked out correctly */
4343
cl_git_pass(git_oid_fromstr(&check, "965b223880dd4249e2c66a0cc0b4cffe1dc40f5a"));
4444
cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/utf16_withbom_noeol_crlf.txt", GIT_OBJ_BLOB));
45-
cl_assert(git_oid_equal(&oid, &check));
45+
cl_assert_equal_oid(&oid, &check);
4646
}
4747

4848
void test_checkout_binaryunicode__noautocrlf(void)

‎tests/checkout/conflict.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static void ensure_workdir_oid(const char *path, const char *oid_str)
156156

157157
cl_git_pass(git_oid_fromstr(&expected, oid_str));
158158
cl_git_pass(git_repository_hashfile(&actual, g_repo, path, GIT_OBJ_BLOB, NULL));
159-
cl_assert(git_oid_cmp(&expected, &actual) == 0);
159+
cl_assert_equal_oid(&expected, &actual);
160160
}
161161

162162
static void ensure_workdir_mode(const char *path, int mode)

‎tests/clar_libgit2.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,24 @@ void clar__assert_equal_file(
7878
const char *file,
7979
int line);
8080

81+
GIT_INLINE(void) clar__assert_equal_oid(
82+
const char *file, int line, const char *desc,
83+
const git_oid *one, const git_oid *two)
84+
{
85+
if (git_oid_cmp(one, two)) {
86+
char err[] = "\"........................................\" != \"........................................\"";
87+
88+
git_oid_fmt(&err[1], one);
89+
git_oid_fmt(&err[47], two);
90+
91+
clar__fail(file, line, desc, err, 1);
92+
}
93+
}
94+
95+
#define cl_assert_equal_oid(one, two) \
96+
clar__assert_equal_oid(__FILE__, __LINE__, \
97+
"OID mismatch: " #one " != " #two, (one), (two))
98+
8199
/*
82100
* Some utility macros for building long strings
83101
*/

‎tests/clone/nonetwork.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void test_clone_nonetwork__can_detached_head(void)
228228
cl_assert(git_repository_head_detached(cloned));
229229

230230
cl_git_pass(git_repository_head(&cloned_head, cloned));
231-
cl_assert(!git_oid_cmp(git_object_id(obj), git_reference_target(cloned_head)));
231+
cl_assert_equal_oid(git_object_id(obj), git_reference_target(cloned_head));
232232

233233
cl_git_pass(git_reflog_read(&log, cloned, "HEAD"));
234234
entry = git_reflog_entry_byindex(log, 0);

‎tests/commit/commit.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void test_commit_commit__create_unexisting_update_ref(void)
4343
NULL, "some msg", tree, 1, (const git_commit **) &commit));
4444

4545
cl_git_pass(git_reference_lookup(&ref, _repo, "refs/heads/foo/bar"));
46-
cl_assert(!git_oid_cmp(&oid, git_reference_target(ref)));
46+
cl_assert_equal_oid(&oid, git_reference_target(ref));
4747

4848
git_tree_free(tree);
4949
git_commit_free(commit);

‎tests/commit/write.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void test_commit_write__root(void)
145145
cl_assert(git_commit_parentcount(commit) == 0);
146146
cl_git_pass(git_reference_lookup(&branch, g_repo, branch_name));
147147
branch_oid = git_reference_target(branch);
148-
cl_git_pass(git_oid_cmp(branch_oid, &commit_id));
148+
cl_assert_equal_oid(branch_oid, &commit_id);
149149
cl_assert_equal_s(root_commit_message, git_commit_message(commit));
150150

151151
cl_git_pass(git_reflog_read(&log, g_repo, branch_name));

‎tests/diff/blob.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ static void assert_patch_matches_blobs(
137137
cl_assert(delta != NULL);
138138

139139
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
140-
cl_assert(git_oid_equal(git_blob_id(a), &delta->old_file.id));
140+
cl_assert_equal_oid(git_blob_id(a), &delta->old_file.id);
141141
cl_assert_equal_sz(git_blob_rawsize(a), delta->old_file.size);
142-
cl_assert(git_oid_equal(git_blob_id(b), &delta->new_file.id));
142+
cl_assert_equal_oid(git_blob_id(b), &delta->new_file.id);
143143
cl_assert_equal_sz(git_blob_rawsize(b), delta->new_file.size);
144144

145145
cl_assert_equal_i(hunks, (int)git_patch_num_hunks(p));
@@ -274,7 +274,7 @@ void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
274274
delta = git_patch_get_delta(p);
275275
cl_assert(delta != NULL);
276276
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
277-
cl_assert(git_oid_equal(git_blob_id(d), &delta->old_file.id));
277+
cl_assert_equal_oid(git_blob_id(d), &delta->old_file.id);
278278
cl_assert_equal_sz(git_blob_rawsize(d), delta->old_file.size);
279279
cl_assert(git_oid_iszero(&delta->new_file.id));
280280
cl_assert_equal_sz(0, delta->new_file.size);
@@ -301,7 +301,7 @@ void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
301301
cl_assert_equal_i(GIT_DELTA_ADDED, delta->status);
302302
cl_assert(git_oid_iszero(&delta->old_file.id));
303303
cl_assert_equal_sz(0, delta->old_file.size);
304-
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.id));
304+
cl_assert_equal_oid(git_blob_id(d), &delta->new_file.id);
305305
cl_assert_equal_sz(git_blob_rawsize(d), delta->new_file.size);
306306

307307
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
@@ -392,9 +392,9 @@ void test_diff_blob__can_compare_identical_blobs_with_patch(void)
392392
cl_assert(delta != NULL);
393393
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, delta->status);
394394
cl_assert_equal_sz(delta->old_file.size, git_blob_rawsize(d));
395-
cl_assert(git_oid_equal(git_blob_id(d), &delta->old_file.id));
395+
cl_assert_equal_oid(git_blob_id(d), &delta->old_file.id);
396396
cl_assert_equal_sz(delta->new_file.size, git_blob_rawsize(d));
397-
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.id));
397+
cl_assert_equal_oid(git_blob_id(d), &delta->new_file.id);
398398

399399
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
400400
git_patch_free(p);

‎tests/diff/iterator.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ static void index_iterator_test(
380380
if (expected_oids != NULL) {
381381
git_oid oid;
382382
cl_git_pass(git_oid_fromstr(&oid, expected_oids[count]));
383-
cl_assert_equal_i(git_oid_cmp(&oid, &entry->id), 0);
383+
cl_assert_equal_oid(&oid, &entry->id);
384384
}
385385

386386
count++;

‎tests/fetchhead/nonetwork.c‎

Lines changed: 4 additions & 4 deletions

0 commit comments

Comments
 (0)