diff options
Diffstat (limited to 'tests')
56 files changed, 538 insertions, 318 deletions
diff --git a/tests/blame/blame_helpers.c b/tests/blame/blame_helpers.c index 56240dbde..9bb77a52d 100644 --- a/tests/blame/blame_helpers.c +++ b/tests/blame/blame_helpers.c @@ -48,7 +48,7 @@ void check_blame_hunk_index(git_repository *repo, git_blame *blame, int idx, actual, expected); } cl_assert_equal_s(actual, expected); - cl_assert_equal_i(git_oid_cmp(&hunk->final_commit_id, &hunk->orig_commit_id), 0); + cl_assert_equal_oid(&hunk->final_commit_id, &hunk->orig_commit_id); if (strcmp(hunk->orig_path, orig_path)) { diff --git a/tests/checkout/binaryunicode.c b/tests/checkout/binaryunicode.c index 1172816c7..27e70d3f1 100644 --- a/tests/checkout/binaryunicode.c +++ b/tests/checkout/binaryunicode.c @@ -37,12 +37,12 @@ static void execute_test(void) /* Verify that the lenna.jpg file was checked out correctly */ cl_git_pass(git_oid_fromstr(&check, "8ab005d890fe53f65eda14b23672f60d9f4ec5a1")); cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/lenna.jpg", GIT_OBJ_BLOB)); - cl_assert(git_oid_equal(&oid, &check)); + cl_assert_equal_oid(&oid, &check); /* Verify that the text file was checked out correctly */ cl_git_pass(git_oid_fromstr(&check, "965b223880dd4249e2c66a0cc0b4cffe1dc40f5a")); cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/utf16_withbom_noeol_crlf.txt", GIT_OBJ_BLOB)); - cl_assert(git_oid_equal(&oid, &check)); + cl_assert_equal_oid(&oid, &check); } void test_checkout_binaryunicode__noautocrlf(void) diff --git a/tests/checkout/conflict.c b/tests/checkout/conflict.c index 2cb7c224d..b8ae80576 100644 --- a/tests/checkout/conflict.c +++ b/tests/checkout/conflict.c @@ -156,7 +156,7 @@ static void ensure_workdir_oid(const char *path, const char *oid_str) cl_git_pass(git_oid_fromstr(&expected, oid_str)); cl_git_pass(git_repository_hashfile(&actual, g_repo, path, GIT_OBJ_BLOB, NULL)); - cl_assert(git_oid_cmp(&expected, &actual) == 0); + cl_assert_equal_oid(&expected, &actual); } static void ensure_workdir_mode(const char *path, int mode) @@ -169,7 +169,7 @@ static void ensure_workdir_mode(const char *path, int mode) git_buf_joinpath(&fullpath, git_repository_workdir(g_repo), path)); cl_git_pass(p_stat(git_buf_cstr(&fullpath), &st)); - cl_assert_equal_i(mode, st.st_mode); + cl_assert_equal_i((mode & S_IRWXU), (st.st_mode & S_IRWXU)); git_buf_free(&fullpath); #endif diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c index 6b2c1b122..496f83d5d 100644 --- a/tests/checkout/crlf.c +++ b/tests/checkout/crlf.c @@ -79,10 +79,7 @@ void test_checkout_crlf__more_lf_autocrlf_true(void) git_checkout_head(g_repo, &opts); - if (GIT_EOL_NATIVE == GIT_EOL_LF) - check_file_contents("./crlf/more-lf", MORE_LF_TEXT_RAW); - else - check_file_contents("./crlf/more-lf", MORE_LF_TEXT_AS_CRLF); + check_file_contents("./crlf/more-lf", MORE_LF_TEXT_RAW); } void test_checkout_crlf__more_crlf_autocrlf_true(void) @@ -94,10 +91,7 @@ void test_checkout_crlf__more_crlf_autocrlf_true(void) git_checkout_head(g_repo, &opts); - if (GIT_EOL_NATIVE == GIT_EOL_LF) - check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_RAW); - else - check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_AS_CRLF); + check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_RAW); } void test_checkout_crlf__all_crlf_autocrlf_true(void) @@ -285,8 +279,13 @@ void test_checkout_crlf__autocrlf_false_text_auto_attr(void) git_checkout_head(g_repo, &opts); - check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW); - check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW); + if (GIT_EOL_NATIVE == GIT_EOL_CRLF) { + check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF); + check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_AS_CRLF); + } else { + check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW); + check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW); + } } void test_checkout_crlf__autocrlf_true_text_auto_attr(void) diff --git a/tests/clar_libgit2.c b/tests/clar_libgit2.c index 0a4c3e8e5..faeee031a 100644 --- a/tests/clar_libgit2.c +++ b/tests/clar_libgit2.c @@ -471,7 +471,7 @@ void clar__assert_equal_file( buf, sizeof(buf), "file content mismatch at byte %d", (int)(total_bytes + pos)); p_close(fd); - clar__fail(file, line, buf, path, 1); + clar__fail(file, line, path, buf, 1); } expected_data += bytes; diff --git a/tests/clar_libgit2.h b/tests/clar_libgit2.h index da37bd655..0744877cb 100644 --- a/tests/clar_libgit2.h +++ b/tests/clar_libgit2.h @@ -78,6 +78,24 @@ void clar__assert_equal_file( const char *file, int line); +GIT_INLINE(void) clar__assert_equal_oid( + const char *file, int line, const char *desc, + const git_oid *one, const git_oid *two) +{ + if (git_oid_cmp(one, two)) { + char err[] = "\"........................................\" != \"........................................\""; + + git_oid_fmt(&err[1], one); + git_oid_fmt(&err[47], two); + + clar__fail(file, line, desc, err, 1); + } +} + +#define cl_assert_equal_oid(one, two) \ + clar__assert_equal_oid(__FILE__, __LINE__, \ + "OID mismatch: " #one " != " #two, (one), (two)) + /* * Some utility macros for building long strings */ diff --git a/tests/clone/local.c b/tests/clone/local.c index a4406c1cc..78d026794 100644 --- a/tests/clone/local.c +++ b/tests/clone/local.c @@ -7,55 +7,78 @@ #include "posix.h" #include "fileops.h" +static int file_url(git_buf *buf, const char *host, const char *path) +{ + if (path[0] == '/') + path++; + + git_buf_clear(buf); + return git_buf_printf(buf, "file://%s/%s", host, path); +} + void test_clone_local__should_clone_local(void) { git_buf buf = GIT_BUF_INIT; - const char *path; /* we use a fixture path because it needs to exist for us to want to clone */ - - cl_git_pass(git_buf_printf(&buf, "file://%s", cl_fixture("testrepo.git"))); - cl_assert_equal_i(false, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO)); - cl_assert_equal_i(true, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL)); - cl_assert_equal_i(true, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS)); - cl_assert_equal_i(false, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL)); - git_buf_free(&buf); + const char *path = cl_fixture("testrepo.git"); + + cl_git_pass(file_url(&buf, "", path)); + cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO)); + cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL)); + cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS)); + cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL)); + + cl_git_pass(file_url(&buf, "localhost", path)); + cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO)); + cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL)); + cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS)); + cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL)); + + cl_git_pass(file_url(&buf, "other-host.mycompany.com", path)); + cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO)); + cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL)); + cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS)); + cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL)); + + /* Ensure that file:/// urls are percent decoded: .git == %2e%67%69%74 */ + cl_git_pass(file_url(&buf, "", path)); + git_buf_shorten(&buf, 4); + cl_git_pass(git_buf_puts(&buf, "%2e%67%69%74")); + cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO)); + cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL)); + cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS)); + cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL)); + + cl_assert_equal_i(1, git_clone__should_clone_local(path, GIT_CLONE_LOCAL_AUTO)); + cl_assert_equal_i(1, git_clone__should_clone_local(path, GIT_CLONE_LOCAL)); + cl_assert_equal_i(1, git_clone__should_clone_local(path, GIT_CLONE_LOCAL_NO_LINKS)); + cl_assert_equal_i(0, git_clone__should_clone_local(path, GIT_CLONE_NO_LOCAL)); - path = cl_fixture("testrepo.git"); - cl_assert_equal_i(true, git_clone__should_clone_local(path, GIT_CLONE_LOCAL_AUTO)); - cl_assert_equal_i(true, git_clone__should_clone_local(path, GIT_CLONE_LOCAL)); - cl_assert_equal_i(true, git_clone__should_clone_local(path, GIT_CLONE_LOCAL_NO_LINKS)); - cl_assert_equal_i(false, git_clone__should_clone_local(path, GIT_CLONE_NO_LOCAL)); + git_buf_free(&buf); } void test_clone_local__hardlinks(void) { git_repository *repo; - git_remote *remote; - git_signature *sig; + git_clone_options opts = GIT_CLONE_OPTIONS_INIT; git_buf buf = GIT_BUF_INIT; struct stat st; - /* * In this first clone, we just copy over, since the temp dir * will often be in a different filesystem, so we cannot * link. It also allows us to control the number of links */ - cl_git_pass(git_repository_init(&repo, "./clone.git", true)); - cl_git_pass(git_remote_create(&remote, repo, "origin", cl_fixture("testrepo.git"))); - cl_git_pass(git_signature_now(&sig, "foo", "bar")); - cl_git_pass(git_clone_local_into(repo, remote, NULL, NULL, false, sig)); - - git_remote_free(remote); + opts.bare = true; + opts.local = GIT_CLONE_LOCAL_NO_LINKS; + cl_git_pass(git_clone(&repo, cl_fixture("testrepo.git"), "./clone.git", &opts)); git_repository_free(repo); /* This second clone is in the same filesystem, so we can hardlink */ - cl_git_pass(git_repository_init(&repo, "./clone2.git", true)); - cl_git_pass(git_buf_puts(&buf, cl_git_path_url("clone.git"))); - cl_git_pass(git_remote_create(&remote, repo, "origin", buf.ptr)); - cl_git_pass(git_clone_local_into(repo, remote, NULL, NULL, true, sig)); + opts.local = GIT_CLONE_LOCAL; + cl_git_pass(git_clone(&repo, cl_git_path_url("clone.git"), "./clone2.git", &opts)); #ifndef GIT_WIN32 git_buf_clear(&buf); @@ -65,14 +88,11 @@ void test_clone_local__hardlinks(void) cl_assert_equal_i(2, st.st_nlink); #endif - git_remote_free(remote); git_repository_free(repo); git_buf_clear(&buf); - cl_git_pass(git_repository_init(&repo, "./clone3.git", true)); - cl_git_pass(git_buf_puts(&buf, cl_git_path_url("clone.git"))); - cl_git_pass(git_remote_create(&remote, repo, "origin", buf.ptr)); - cl_git_pass(git_clone_local_into(repo, remote, NULL, NULL, false, sig)); + opts.local = GIT_CLONE_LOCAL_NO_LINKS; + cl_git_pass(git_clone(&repo, cl_git_path_url("clone.git"), "./clone3.git", &opts)); git_buf_clear(&buf); cl_git_pass(git_buf_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125")); @@ -80,7 +100,6 @@ void test_clone_local__hardlinks(void) cl_git_pass(p_stat(buf.ptr, &st)); cl_assert_equal_i(1, st.st_nlink); - git_remote_free(remote); git_repository_free(repo); /* this one should automatically use links */ @@ -95,7 +114,6 @@ void test_clone_local__hardlinks(void) #endif git_buf_free(&buf); - git_signature_free(sig); git_repository_free(repo); cl_git_pass(git_futils_rmdir_r("./clone.git", NULL, GIT_RMDIR_REMOVE_FILES)); diff --git a/tests/clone/nonetwork.c b/tests/clone/nonetwork.c index 4bdc6e13b..e9853313e 100644 --- a/tests/clone/nonetwork.c +++ b/tests/clone/nonetwork.c @@ -110,12 +110,25 @@ void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(vo cl_git_fail(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options)); } +int custom_origin_name_remote_create( + git_remote **out, + git_repository *repo, + const char *name, + const char *url, + void *payload) +{ + GIT_UNUSED(name); + GIT_UNUSED(payload); + + return git_remote_create(out, repo, "my_origin", url); +} + void test_clone_nonetwork__custom_origin_name(void) { - g_options.remote_name = "my_origin"; - cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options)); + g_options.remote_cb = custom_origin_name_remote_create; + cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options)); - cl_git_pass(git_remote_load(&g_remote, g_repo, "my_origin")); + cl_git_pass(git_remote_load(&g_remote, g_repo, "my_origin")); } void test_clone_nonetwork__defaults(void) @@ -228,7 +241,7 @@ void test_clone_nonetwork__can_detached_head(void) cl_assert(git_repository_head_detached(cloned)); cl_git_pass(git_repository_head(&cloned_head, cloned)); - cl_assert(!git_oid_cmp(git_object_id(obj), git_reference_target(cloned_head))); + cl_assert_equal_oid(git_object_id(obj), git_reference_target(cloned_head)); cl_git_pass(git_reflog_read(&log, cloned, "HEAD")); entry = git_reflog_entry_byindex(log, 0); @@ -266,23 +279,6 @@ void test_clone_nonetwork__clone_updates_reflog_properly(void) assert_correct_reflog("refs/heads/master"); } -void test_clone_nonetwork__clone_into_updates_reflog_properly(void) -{ - git_remote *remote; - git_signature *sig; - cl_git_pass(git_signature_now(&sig, "Me", "foo@example.com")); - - cl_git_pass(git_repository_init(&g_repo, "./foo", false)); - cl_git_pass(git_remote_create(&remote, g_repo, "origin", cl_git_fixture_url("testrepo.git"))); - cl_git_pass(git_clone_into(g_repo, remote, NULL, NULL, sig)); - - assert_correct_reflog("HEAD"); - assert_correct_reflog("refs/heads/master"); - - git_remote_free(remote); - git_signature_free(sig); -} - static void cleanup_repository(void *path) { if (g_repo) { diff --git a/tests/clone/transport.c b/tests/clone/transport.c new file mode 100644 index 000000000..27568f228 --- /dev/null +++ b/tests/clone/transport.c @@ -0,0 +1,50 @@ +#include "clar_libgit2.h" + +#include "git2/clone.h" +#include "git2/transport.h" +#include "fileops.h" + +static int custom_transport( + git_transport **out, + git_remote *owner, + void *payload) +{ + *((int*)payload) = 1; + + return git_transport_local(out, owner, payload); +} + +static int custom_transport_remote_create( + git_remote **out, + git_repository *repo, + const char *name, + const char *url, + void *payload) +{ + int error; + + if ((error = git_remote_create(out, repo, name, url)) < 0) + return error; + + if ((error = git_remote_set_transport(*out, custom_transport, payload)) < 0) + return error; + + return 0; +} + +void test_clone_transport__custom_transport(void) +{ + git_repository *repo; + git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; + int custom_transport_used = 0; + + clone_opts.remote_cb = custom_transport_remote_create; + clone_opts.remote_cb_payload = &custom_transport_used; + + cl_git_pass(git_clone(&repo, cl_fixture("testrepo.git"), "./custom_transport.git", &clone_opts)); + git_repository_free(repo); + + cl_git_pass(git_futils_rmdir_r("./custom_transport.git", NULL, GIT_RMDIR_REMOVE_FILES)); + + cl_assert(custom_transport_used == 1); +} diff --git a/tests/commit/commit.c b/tests/commit/commit.c index fa181b703..f5461cfd3 100644 --- a/tests/commit/commit.c +++ b/tests/commit/commit.c @@ -43,7 +43,7 @@ void test_commit_commit__create_unexisting_update_ref(void) NULL, "some msg", tree, 1, (const git_commit **) &commit)); cl_git_pass(git_reference_lookup(&ref, _repo, "refs/heads/foo/bar")); - cl_assert(!git_oid_cmp(&oid, git_reference_target(ref))); + cl_assert_equal_oid(&oid, git_reference_target(ref)); git_tree_free(tree); git_commit_free(commit); diff --git a/tests/commit/write.c b/tests/commit/write.c index b1cdf4485..6212ef641 100644 --- a/tests/commit/write.c +++ b/tests/commit/write.c @@ -145,7 +145,7 @@ void test_commit_write__root(void) cl_assert(git_commit_parentcount(commit) == 0); cl_git_pass(git_reference_lookup(&branch, g_repo, branch_name)); branch_oid = git_reference_target(branch); - cl_git_pass(git_oid_cmp(branch_oid, &commit_id)); + cl_assert_equal_oid(branch_oid, &commit_id); cl_assert_equal_s(root_commit_message, git_commit_message(commit)); cl_git_pass(git_reflog_read(&log, g_repo, branch_name)); diff --git a/tests/config/write.c b/tests/config/write.c index 402be9317..0f11ae8da 100644 --- a/tests/config/write.c +++ b/tests/config/write.c @@ -229,6 +229,22 @@ void test_config_write__add_value_at_file_with_no_clrf_at_the_end(void) git_config_free(cfg); } +void test_config_write__add_section_at_file_with_no_clrf_at_the_end(void) +{ + git_config *cfg; + int i; + + cl_git_pass(git_config_open_ondisk(&cfg, "config17")); + cl_git_pass(git_config_set_int32(cfg, "diff.context", 10)); + git_config_free(cfg); + + cl_git_pass(git_config_open_ondisk(&cfg, "config17")); + cl_git_pass(git_config_get_int32(&i, cfg, "diff.context")); + cl_assert_equal_i(10, i); + + git_config_free(cfg); +} + void test_config_write__add_value_which_needs_quotes(void) { git_config *cfg; diff --git a/tests/core/buffer.c b/tests/core/buffer.c index da5ec605c..8310deae1 100644 --- a/tests/core/buffer.c +++ b/tests/core/buffer.c @@ -1034,18 +1034,14 @@ void test_core_buffer__lf_and_crlf_conversions(void) git_buf_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n"); - cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src)); - check_buf("crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n", tgt); - check_buf(src.ptr, tgt); + cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src)); cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src)); check_buf("crlf\ncrlf\ncrlf\ncrlf\n", tgt); git_buf_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf"); - cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src)); - check_buf("\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf", tgt); - check_buf(src.ptr, tgt); + cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src)); cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src)); check_buf("\ncrlf\ncrlf\ncrlf\ncrlf\ncrlf", tgt); @@ -1054,8 +1050,7 @@ void test_core_buffer__lf_and_crlf_conversions(void) git_buf_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n"); - cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src)); - check_buf("\r\nlf\r\nlf\r\ncrlf\r\nlf\r\nlf\r\ncrlf\r\n", tgt); + cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src)); cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src)); check_buf("\nlf\nlf\ncrlf\nlf\nlf\ncrlf\n", tgt); @@ -1063,8 +1058,7 @@ void test_core_buffer__lf_and_crlf_conversions(void) git_buf_sets(&src, "\ncrlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf"); - cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src)); - check_buf("\r\ncrlf\r\ncrlf\r\nlf\r\ncrlf\r\ncrlf", tgt); + cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src)); cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src)); check_buf("\ncrlf\ncrlf\nlf\ncrlf\ncrlf", tgt); @@ -1072,8 +1066,7 @@ void test_core_buffer__lf_and_crlf_conversions(void) git_buf_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r"); - cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src)); - check_buf("\rcrlf\r\nlf\r\nlf\r\ncr\rcrlf\r\nlf\r\ncr\r", tgt); + cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src)); cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src)); check_buf("\rcrlf\nlf\nlf\ncr\rcrlf\nlf\ncr\r", tgt); @@ -1089,8 +1082,7 @@ void test_core_buffer__lf_and_crlf_conversions(void) /* blob correspondence tests */ git_buf_sets(&src, ALL_CRLF_TEXT_RAW); - cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src)); - check_buf(ALL_CRLF_TEXT_AS_CRLF, tgt); + cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src)); cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src)); check_buf(ALL_CRLF_TEXT_AS_LF, tgt); git_buf_free(&src); @@ -1105,16 +1097,14 @@ void test_core_buffer__lf_and_crlf_conversions(void) git_buf_free(&tgt); git_buf_sets(&src, MORE_CRLF_TEXT_RAW); - cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src)); - check_buf(MORE_CRLF_TEXT_AS_CRLF, tgt); + cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src)); cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src)); check_buf(MORE_CRLF_TEXT_AS_LF, tgt); git_buf_free(&src); git_buf_free(&tgt); git_buf_sets(&src, MORE_LF_TEXT_RAW); - cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src)); - check_buf(MORE_LF_TEXT_AS_CRLF, tgt); + cl_git_fail_with(GIT_PASSTHROUGH, git_buf_text_lf_to_crlf(&tgt, &src)); cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src)); check_buf(MORE_LF_TEXT_AS_LF, tgt); git_buf_free(&src); diff --git a/tests/core/pool.c b/tests/core/pool.c index 351d0c20f..a7ec8801b 100644 --- a/tests/core/pool.c +++ b/tests/core/pool.c @@ -38,19 +38,19 @@ void test_core_pool__1(void) cl_assert(git_pool_malloc(&p, i) != NULL); /* with fixed page size, allocation must end up with these values */ - cl_assert(git_pool__open_pages(&p) == 1); - cl_assert(git_pool__full_pages(&p) == 505); + cl_assert_equal_i(1, git_pool__open_pages(&p)); + cl_assert_equal_i(507, git_pool__full_pages(&p)); git_pool_clear(&p); - cl_git_pass(git_pool_init(&p, 1, 4100)); + cl_git_pass(git_pool_init(&p, 1, 4120)); for (i = 2010; i > 0; i--) cl_assert(git_pool_malloc(&p, i) != NULL); /* with fixed page size, allocation must end up with these values */ - cl_assert(git_pool__open_pages(&p) == 1); - cl_assert(git_pool__full_pages(&p) == 492); + cl_assert_equal_i(1, git_pool__open_pages(&p)); + cl_assert_equal_i(492, git_pool__full_pages(&p)); git_pool_clear(&p); } diff --git a/tests/diff/blob.c b/tests/diff/blob.c index 527007965..51bdbab15 100644 --- a/tests/diff/blob.c +++ b/tests/diff/blob.c @@ -137,9 +137,9 @@ static void assert_patch_matches_blobs( cl_assert(delta != NULL); cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status); - cl_assert(git_oid_equal(git_blob_id(a), &delta->old_file.id)); + cl_assert_equal_oid(git_blob_id(a), &delta->old_file.id); cl_assert_equal_sz(git_blob_rawsize(a), delta->old_file.size); - cl_assert(git_oid_equal(git_blob_id(b), &delta->new_file.id)); + cl_assert_equal_oid(git_blob_id(b), &delta->new_file.id); cl_assert_equal_sz(git_blob_rawsize(b), delta->new_file.size); 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) delta = git_patch_get_delta(p); cl_assert(delta != NULL); cl_assert_equal_i(GIT_DELTA_DELETED, delta->status); - cl_assert(git_oid_equal(git_blob_id(d), &delta->old_file.id)); + cl_assert_equal_oid(git_blob_id(d), &delta->old_file.id); cl_assert_equal_sz(git_blob_rawsize(d), delta->old_file.size); cl_assert(git_oid_iszero(&delta->new_file.id)); 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) cl_assert_equal_i(GIT_DELTA_ADDED, delta->status); cl_assert(git_oid_iszero(&delta->old_file.id)); cl_assert_equal_sz(0, delta->old_file.size); - cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.id)); + cl_assert_equal_oid(git_blob_id(d), &delta->new_file.id); cl_assert_equal_sz(git_blob_rawsize(d), delta->new_file.size); 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) cl_assert(delta != NULL); cl_assert_equal_i(GIT_DELTA_UNMODIFIED, delta->status); cl_assert_equal_sz(delta->old_file.size, git_blob_rawsize(d)); - cl_assert(git_oid_equal(git_blob_id(d), &delta->old_file.id)); + cl_assert_equal_oid(git_blob_id(d), &delta->old_file.id); cl_assert_equal_sz(delta->new_file.size, git_blob_rawsize(d)); - cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.id)); + cl_assert_equal_oid(git_blob_id(d), &delta->new_file.id); cl_assert_equal_i(0, (int)git_patch_num_hunks(p)); git_patch_free(p); diff --git a/tests/diff/iterator.c b/tests/diff/iterator.c index a2df1c7a7..26f670cfa 100644 --- a/tests/diff/iterator.c +++ b/tests/diff/iterator.c @@ -380,7 +380,7 @@ static void index_iterator_test( if (expected_oids != NULL) { git_oid oid; cl_git_pass(git_oid_fromstr(&oid, expected_oids[count])); - cl_assert_equal_i(git_oid_cmp(&oid, &entry->id), 0); + cl_assert_equal_oid(&oid, &entry->id); } count++; diff --git a/tests/fetchhead/nonetwork.c b/tests/fetchhead/nonetwork.c index e7ff2ca30..7b64a6339 100644 --- a/tests/fetchhead/nonetwork.c +++ b/tests/fetchhead/nonetwork.c @@ -120,7 +120,7 @@ static int fetchhead_ref_cb(const char *name, const char *url, expected = git_vector_get(cb_data->fetchhead_vector, cb_data->idx); - cl_assert(git_oid_cmp(&expected->oid, oid) == 0); + cl_assert_equal_oid(&expected->oid, oid); cl_assert(expected->is_merge == is_merge); if (expected->ref_name) @@ -174,7 +174,7 @@ static int read_old_style_cb(const char *name, const char *url, cl_assert(name == NULL); cl_assert(url == NULL); - cl_assert(git_oid_cmp(&expected, oid) == 0); + cl_assert_equal_oid(&expected, oid); cl_assert(is_merge == 1); return 0; @@ -201,7 +201,7 @@ static int read_type_missing(const char *ref_name, const char *remote_url, cl_assert_equal_s("name", ref_name); cl_assert_equal_s("remote_url", remote_url); - cl_assert(git_oid_cmp(&expected, oid) == 0); + cl_assert_equal_oid(&expected, oid); cl_assert(is_merge == 0); return 0; @@ -228,7 +228,7 @@ static int read_name_missing(const char *ref_name, const char *remote_url, cl_assert(ref_name == NULL); cl_assert_equal_s("remote_url", remote_url); - cl_assert(git_oid_cmp(&expected, oid) == 0); + cl_assert_equal_oid(&expected, oid); cl_assert(is_merge == 0); return 0; diff --git a/tests/index/conflicts.c b/tests/index/conflicts.c index 90aaa442d..427351693 100644 --- a/tests/index/conflicts.c +++ b/tests/index/conflicts.c @@ -107,13 +107,13 @@ void test_index_conflicts__get(void) cl_assert_equal_s("conflicts-one.txt", conflict_entry[0]->path); git_oid_fromstr(&oid, CONFLICTS_ONE_ANCESTOR_OID); - cl_assert(git_oid_cmp(&conflict_entry[0]->id, &oid) == 0); + cl_assert_equal_oid(&oid, &conflict_entry[0]->id); git_oid_fromstr(&oid, CONFLICTS_ONE_OUR_OID); - cl_assert(git_oid_cmp(&conflict_entry[1]->id, &oid) == 0); + cl_assert_equal_oid(&oid, &conflict_entry[1]->id); git_oid_fromstr(&oid, CONFLICTS_ONE_THEIR_OID); - cl_assert(git_oid_cmp(&conflict_entry[2]->id, &oid) == 0); + cl_assert_equal_oid(&oid, &conflict_entry[2]->id); cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], repo_index, "conflicts-two.txt")); @@ -121,13 +121,13 @@ void test_index_conflicts__get(void) cl_assert_equal_s("conflicts-two.txt", conflict_entry[0]->path); git_oid_fromstr(&oid, CONFLICTS_TWO_ANCESTOR_OID); - cl_assert(git_oid_cmp(&conflict_entry[0]->id, &oid) == 0); + cl_assert_equal_oid(&oid, &conflict_entry[0]->id); git_oid_fromstr(&oid, CONFLICTS_TWO_OUR_OID); - cl_assert(git_oid_cmp(&conflict_entry[1]->id, &oid) == 0); + cl_assert_equal_oid(&oid, &conflict_entry[1]->id); git_oid_fromstr(&oid, CONFLICTS_TWO_THEIR_OID); - cl_assert(git_oid_cmp(&conflict_entry[2]->id, &oid) == 0); + cl_assert_equal_oid(&oid, &conflict_entry[2]->id); } void test_index_conflicts__iterate(void) @@ -141,29 +141,29 @@ void test_index_conflicts__iterate(void) cl_git_pass(git_index_conflict_next(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], iterator)); git_oid_fromstr(&oid, CONFLICTS_ONE_ANCESTOR_OID); - cl_assert(git_oid_cmp(&conflict_entry[0]->id, &oid) == 0); + cl_assert_equal_oid(&oid, &conflict_entry[0]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-one.txt") == 0); git_oid_fromstr(&oid, CONFLICTS_ONE_OUR_OID); - cl_assert(git_oid_cmp(&conflict_entry[1]->id, &oid) == 0); + cl_assert_equal_oid(&oid, &conflict_entry[1]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-one.txt") == 0); git_oid_fromstr(&oid, CONFLICTS_ONE_THEIR_OID); - cl_assert(git_oid_cmp(&conflict_entry[2]->id, &oid) == 0); + cl_assert_equal_oid(&oid, &conflict_entry[2]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-one.txt") == 0); cl_git_pass(git_index_conflict_next(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], iterator)); git_oid_fromstr(&oid, CONFLICTS_TWO_ANCESTOR_OID); - cl_assert(git_oid_cmp(&conflict_entry[0]->id, &oid) == 0); + cl_assert_equal_oid(&oid, &conflict_entry[0]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-two.txt") == 0); git_oid_fromstr(&oid, CONFLICTS_TWO_OUR_OID); - cl_assert(git_oid_cmp(&conflict_entry[1]->id, &oid) == 0); + cl_assert_equal_oid(&oid, &conflict_entry[1]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-two.txt") == 0); git_oid_fromstr(&oid, CONFLICTS_TWO_THEIR_OID); - cl_assert(git_oid_cmp(&conflict_entry[2]->id, &oid) == 0); + cl_assert_equal_oid(&oid, &conflict_entry[2]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-two.txt") == 0); cl_assert(git_index_conflict_next(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], iterator) == GIT_ITEROVER); @@ -281,7 +281,7 @@ void test_index_conflicts__partial(void) cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], repo_index, "test-one.txt")); - cl_assert(git_oid_cmp(&ancestor_entry.id, &conflict_entry[0]->id) == 0); + cl_assert_equal_oid(&ancestor_entry.id, &conflict_entry[0]->id); cl_assert(conflict_entry[1] == NULL); cl_assert(conflict_entry[2] == NULL); } diff --git a/tests/index/crlf.c b/tests/index/crlf.c index 7babd5939..23f47932f 100644 --- a/tests/index/crlf.c +++ b/tests/index/crlf.c @@ -41,7 +41,7 @@ void test_index_crlf__autocrlf_false_no_attrs(void) cl_git_pass(git_oid_fromstr(&oid, (GIT_EOL_NATIVE == GIT_EOL_CRLF) ? FILE_OID_CRLF : FILE_OID_LF)); - cl_assert(git_oid_cmp(&oid, &entry->id) == 0); + cl_assert_equal_oid(&oid, &entry->id); } void test_index_crlf__autocrlf_true_no_attrs(void) @@ -58,7 +58,7 @@ void test_index_crlf__autocrlf_true_no_attrs(void) entry = git_index_get_bypath(g_index, "newfile.txt", 0); cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF)); - cl_assert(git_oid_cmp(&oid, &entry->id) == 0); + cl_assert_equal_oid(&oid, &entry->id); } void test_index_crlf__autocrlf_input_no_attrs(void) @@ -75,7 +75,7 @@ void test_index_crlf__autocrlf_input_no_attrs(void) entry = git_index_get_bypath(g_index, "newfile.txt", 0); cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF)); - cl_assert(git_oid_cmp(&oid, &entry->id) == 0); + cl_assert_equal_oid(&oid, &entry->id); } void test_index_crlf__autocrlf_false_text_auto_attr(void) @@ -94,7 +94,7 @@ void test_index_crlf__autocrlf_false_text_auto_attr(void) entry = git_index_get_bypath(g_index, "newfile.txt", 0); cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF)); - cl_assert(git_oid_cmp(&oid, &entry->id) == 0); + cl_assert_equal_oid(&oid, &entry->id); } void test_index_crlf__autocrlf_true_text_auto_attr(void) @@ -113,7 +113,7 @@ void test_index_crlf__autocrlf_true_text_auto_attr(void) entry = git_index_get_bypath(g_index, "newfile.txt", 0); cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF)); - cl_assert(git_oid_cmp(&oid, &entry->id) == 0); + cl_assert_equal_oid(&oid, &entry->id); } void test_index_crlf__autocrlf_input_text_auto_attr(void) @@ -132,7 +132,7 @@ void test_index_crlf__autocrlf_input_text_auto_attr(void) entry = git_index_get_bypath(g_index, "newfile.txt", 0); cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF)); - cl_assert(git_oid_cmp(&oid, &entry->id) == 0); + cl_assert_equal_oid(&oid, &entry->id); } void test_index_crlf__safecrlf_true_no_attrs(void) diff --git a/tests/index/read_tree.c b/tests/index/read_tree.c index 6c6b40121..0e1882818 100644 --- a/tests/index/read_tree.c +++ b/tests/index/read_tree.c @@ -37,7 +37,7 @@ void test_index_read_tree__read_write_involution(void) git_tree_free(tree); cl_git_pass(git_index_write_tree(&tree_oid, index)); - cl_assert(git_oid_cmp(&expected, &tree_oid) == 0); + cl_assert_equal_oid(&expected, &tree_oid); git_index_free(index); git_repository_free(repo); diff --git a/tests/index/rename.c b/tests/index/rename.c index b6fb61d10..dd3cfa732 100644 --- a/tests/index/rename.c +++ b/tests/index/rename.c @@ -27,7 +27,7 @@ void test_index_rename__single_file(void) cl_assert(!git_index_find(&position, index, "lame.name.txt")); entry = git_index_get_byindex(index, position); - cl_assert(git_oid_cmp(&expected, &entry->id) == 0); + cl_assert_equal_oid(&expected, &entry->id); /* This removes the entry from the index, but not from the object database */ cl_git_pass(git_index_remove(index, "lame.name.txt", 0)); @@ -41,7 +41,7 @@ void test_index_rename__single_file(void) cl_assert(!git_index_find(&position, index, "fancy.name.txt")); entry = git_index_get_byindex(index, position); - cl_assert(git_oid_cmp(&expected, &entry->id) == 0); + cl_assert_equal_oid(&expected, &entry->id); git_index_free(index); git_repository_free(repo); diff --git a/tests/index/reuc.c b/tests/index/reuc.c index 27240a30f..0b4d71a6a 100644 --- a/tests/index/reuc.c +++ b/tests/index/reuc.c @@ -53,9 +53,9 @@ void test_index_reuc__add(void) cl_assert(reuc->mode[0] == 0100644); cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); - cl_assert(git_oid_cmp(&reuc->oid[0], &ancestor_oid) == 0); - cl_assert(git_oid_cmp(&reuc->oid[1], &our_oid) == 0); - cl_assert(git_oid_cmp(&reuc->oid[2], &their_oid) == 0); + cl_assert_equal_oid(&reuc->oid[0], &ancestor_oid); + cl_assert_equal_oid(&reuc->oid[1], &our_oid); + cl_assert_equal_oid(&reuc->oid[2], &their_oid); } void test_index_reuc__add_no_ancestor(void) @@ -78,9 +78,9 @@ void test_index_reuc__add_no_ancestor(void) cl_assert(reuc->mode[0] == 0); cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); - cl_assert(git_oid_cmp(&reuc->oid[0], &ancestor_oid) == 0); - cl_assert(git_oid_cmp(&reuc->oid[1], &our_oid) == 0); - cl_assert(git_oid_cmp(&reuc->oid[2], &their_oid) == 0); + cl_assert_equal_oid(&reuc->oid[0], &ancestor_oid); + cl_assert_equal_oid(&reuc->oid[1], &our_oid); + cl_assert_equal_oid(&reuc->oid[2], &their_oid); } void test_index_reuc__read_bypath(void) @@ -97,11 +97,11 @@ void test_index_reuc__read_bypath(void) cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); git_oid_fromstr(&oid, TWO_ANCESTOR_OID); - cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[0], &oid); git_oid_fromstr(&oid, TWO_OUR_OID); - cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[1], &oid); git_oid_fromstr(&oid, TWO_THEIR_OID); - cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[2], &oid); cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "one.txt")); @@ -110,11 +110,11 @@ void test_index_reuc__read_bypath(void) cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); git_oid_fromstr(&oid, ONE_ANCESTOR_OID); - cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[0], &oid); git_oid_fromstr(&oid, ONE_OUR_OID); - cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[1], &oid); git_oid_fromstr(&oid, ONE_THEIR_OID); - cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[2], &oid); } void test_index_reuc__ignore_case(void) @@ -142,11 +142,11 @@ void test_index_reuc__ignore_case(void) cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); git_oid_fromstr(&oid, TWO_ANCESTOR_OID); - cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[0], &oid); git_oid_fromstr(&oid, TWO_OUR_OID); - cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[1], &oid); git_oid_fromstr(&oid, TWO_THEIR_OID); - cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[2], &oid); } void test_index_reuc__read_byindex(void) @@ -163,11 +163,11 @@ void test_index_reuc__read_byindex(void) cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); git_oid_fromstr(&oid, ONE_ANCESTOR_OID); - cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[0], &oid); git_oid_fromstr(&oid, ONE_OUR_OID); - cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[1], &oid); git_oid_fromstr(&oid, ONE_THEIR_OID); - cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[2], &oid); cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 1)); @@ -176,11 +176,11 @@ void test_index_reuc__read_byindex(void) cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); git_oid_fromstr(&oid, TWO_ANCESTOR_OID); - cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[0], &oid); git_oid_fromstr(&oid, TWO_OUR_OID); - cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[1], &oid); git_oid_fromstr(&oid, TWO_THEIR_OID); - cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[2], &oid); } void test_index_reuc__updates_existing(void) @@ -216,11 +216,11 @@ void test_index_reuc__updates_existing(void) cl_assert_equal_s("TWO.txt", reuc->path); git_oid_fromstr(&oid, TWO_OUR_OID); - cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[0], &oid); git_oid_fromstr(&oid, TWO_THEIR_OID); - cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[1], &oid); git_oid_fromstr(&oid, TWO_ANCESTOR_OID); - cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[2], &oid); } void test_index_reuc__remove(void) @@ -242,11 +242,11 @@ void test_index_reuc__remove(void) cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); git_oid_fromstr(&oid, TWO_ANCESTOR_OID); - cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[0], &oid); git_oid_fromstr(&oid, TWO_OUR_OID); - cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[1], &oid); git_oid_fromstr(&oid, TWO_THEIR_OID); - cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0); + cl_assert_equal_oid(&reuc->oid[2], &oid); } void test_index_reuc__write(void) diff --git a/tests/index/tests.c b/tests/index/tests.c index fa5c0bb1a..373889912 100644 --- a/tests/index/tests.c +++ b/tests/index/tests.c @@ -243,11 +243,11 @@ void test_index_tests__add(void) entry = git_index_get_byindex(index, 0); /* And the built-in hashing mechanism worked as expected */ - cl_assert(git_oid_cmp(&id1, &entry->id) == 0); + cl_assert_equal_oid(&id1, &entry->id); /* Test access by path instead of index */ cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL); - cl_assert(git_oid_cmp(&id1, &entry->id) == 0); + cl_assert_equal_oid(&id1, &entry->id); git_index_free(index); git_repository_free(repo); @@ -283,14 +283,14 @@ void test_index_tests__add_issue_1397(void) /* Make sure the initial SHA-1 is correct */ cl_assert((entry = git_index_get_bypath(index, "crlf_file.txt", 0)) != NULL); - cl_assert_(git_oid_cmp(&id1, &entry->id) == 0, "first oid check"); + cl_assert_equal_oid(&id1, &entry->id); /* Update the index */ cl_git_pass(git_index_add_bypath(index, "crlf_file.txt")); /* Check the new SHA-1 */ cl_assert((entry = git_index_get_bypath(index, "crlf_file.txt", 0)) != NULL); - cl_assert_(git_oid_cmp(&id1, &entry->id) == 0, "second oid check"); + cl_assert_equal_oid(&id1, &entry->id); git_index_free(index); } diff --git a/tests/merge/trees/trivial.c b/tests/merge/trees/trivial.c index 62a4574b8..55f38248f 100644 --- a/tests/merge/trees/trivial.c +++ b/tests/merge/trees/trivial.c @@ -259,7 +259,7 @@ void test_merge_trees_trivial__13(void) cl_assert(entry = git_index_get_bypath(result, "modified-in-13.txt", 0)); cl_git_pass(git_oid_fromstr(&expected_oid, "1cff9ec6a47a537380dedfdd17c9e76d74259a2b")); - cl_assert(git_oid_cmp(&entry->id, &expected_oid) == 0); + cl_assert_equal_oid(&expected_oid, &entry->id); cl_assert(git_index_reuc_entrycount(result) == 0); cl_assert(merge_trivial_conflict_entrycount(result) == 0); diff --git a/tests/merge/workdir/dirty.c b/tests/merge/workdir/dirty.c index 776e4ea69..2f776853e 100644 --- a/tests/merge/workdir/dirty.c +++ b/tests/merge/workdir/dirty.c @@ -97,7 +97,7 @@ static int merge_branch(void) cl_git_pass(git_oid_fromstr(&their_oids[0], MERGE_BRANCH_OID)); cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &their_oids[0])); - checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_ALLOW_CONFLICTS; + checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE; error = git_merge(repo, (const git_merge_head **)their_heads, 1, &merge_opts, &checkout_opts); git_merge_head_free(their_heads[0]); diff --git a/tests/network/fetchlocal.c b/tests/network/fetchlocal.c index 0d23bef48..8809f427d 100644 --- a/tests/network/fetchlocal.c +++ b/tests/network/fetchlocal.c @@ -87,28 +87,43 @@ void test_network_fetchlocal__partial(void) git_remote_free(origin); } -void test_network_fetchlocal__clone_into_mirror(void) +static int remote_mirror_cb(git_remote **out, git_repository *repo, + const char *name, const char *url, void *payload) { - git_buf path = GIT_BUF_INIT; - git_repository *repo; + int error; git_remote *remote; - git_reference *head; - cl_git_pass(git_repository_init(&repo, "./foo.git", true)); - cl_git_pass(git_remote_create(&remote, repo, "origin", cl_git_fixture_url("testrepo.git"))); + GIT_UNUSED(payload); + + if ((error = git_remote_create(&remote, repo, name, url)) < 0) + return error; git_remote_clear_refspecs(remote); - cl_git_pass(git_remote_add_fetch(remote, "+refs/*:refs/*")); - cl_git_pass(git_clone_into(repo, remote, NULL, NULL, NULL)); + if ((error = git_remote_add_fetch(remote, "+refs/*:refs/*")) < 0) { + git_remote_free(remote); + return error; + } + + *out = remote; + return 0; +} + +void test_network_fetchlocal__clone_into_mirror(void) +{ + git_clone_options opts = GIT_CLONE_OPTIONS_INIT; + git_repository *repo; + git_reference *head; + + opts.bare = true; + opts.remote_cb = remote_mirror_cb; + cl_git_pass(git_clone(&repo, cl_git_fixture_url("testrepo.git"), "./foo.git", &opts)); cl_git_pass(git_reference_lookup(&head, repo, "HEAD")); cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head)); cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head)); - git_remote_free(remote); git_reference_free(head); git_repository_free(repo); - git_buf_free(&path); cl_fixture_cleanup("./foo.git"); } diff --git a/tests/network/refspecs.c b/tests/network/refspecs.c index 676a1fa99..aa9b36e58 100644 --- a/tests/network/refspecs.c +++ b/tests/network/refspecs.c @@ -84,4 +84,27 @@ void test_network_refspecs__parsing(void) assert_refspec(GIT_DIRECTION_FETCH, "master", true); assert_refspec(GIT_DIRECTION_PUSH, "master", true); + + assert_refspec(GIT_DIRECTION_FETCH, "refs/pull/*/head:refs/remotes/origin/pr/*", true); +} + +void assert_transform(const char *refspec, const char *name, const char *result) +{ + git_refspec spec; + git_buf buf = GIT_BUF_INIT; + + git_refspec__parse(&spec, refspec, true); + cl_git_pass(git_refspec_transform(&buf, &spec, name)); + cl_assert_equal_s(result, buf.ptr); + + git_buf_free(&buf); + git_refspec__free(&spec); +} + +void test_network_refspecs__transform_mid_star(void) +{ + assert_transform("refs/pull/*/head:refs/remotes/origin/pr/*", "refs/pull/23/head", "refs/remotes/origin/pr/23"); + assert_transform("refs/heads/*:refs/remotes/origin/*", "refs/heads/master", "refs/remotes/origin/master"); + assert_transform("refs/heads/*:refs/heads/*", "refs/heads/master", "refs/heads/master"); + assert_transform("refs/*:refs/*", "refs/heads/master", "refs/heads/master"); } diff --git a/tests/network/remote/remotes.c b/tests/network/remote/remotes.c index 333b52a5b..21c57119a 100644 --- a/tests/network/remote/remotes.c +++ b/tests/network/remote/remotes.c @@ -72,18 +72,17 @@ void test_network_remote_remotes__error_when_not_found(void) void test_network_remote_remotes__error_when_no_push_available(void) { git_remote *r; - git_transport *t; git_push *p; cl_git_pass(git_remote_create_anonymous(&r, _repo, cl_fixture("testrepo.git"), NULL)); - cl_git_pass(git_transport_local(&t,r,NULL)); + cl_git_pass(git_remote_set_transport(r, git_transport_local, NULL)); + + cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH)); /* Make sure that push is really not available */ - t->push = NULL; - cl_git_pass(git_remote_set_transport(r, t)); + r->transport->push = NULL; - cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH)); cl_git_pass(git_push_new(&p, r)); cl_git_pass(git_push_add_refspec(p, "refs/heads/master")); cl_git_fail_with(git_push_finish(p), GIT_ERROR); @@ -438,27 +437,6 @@ void test_network_remote_remotes__returns_ENOTFOUND_when_neither_url_nor_pushurl git_remote_load(&remote, _repo, "no-remote-url"), GIT_ENOTFOUND); } -void test_network_remote_remotes__check_structure_version(void) -{ - git_transport transport = GIT_TRANSPORT_INIT; - const git_error *err; - - git_remote_free(_remote); - _remote = NULL; - cl_git_pass(git_remote_create_anonymous(&_remote, _repo, "test-protocol://localhost", NULL)); - - transport.version = 0; - cl_git_fail(git_remote_set_transport(_remote, &transport)); - err = giterr_last(); - cl_assert_equal_i(GITERR_INVALID, err->klass); - - giterr_clear(); - transport.version = 1024; - cl_git_fail(git_remote_set_transport(_remote, &transport)); - err = giterr_last(); - cl_assert_equal_i(GITERR_INVALID, err->klass); -} - void assert_cannot_create_remote(const char *name, int expected_error) { git_remote *remote = NULL; diff --git a/tests/network/urlparse.c b/tests/network/urlparse.c index 2a9c2f69f..b3ac8ae60 100644 --- a/tests/network/urlparse.c +++ b/tests/network/urlparse.c @@ -33,6 +33,24 @@ void test_network_urlparse__trivial(void) cl_assert_equal_p(pass, NULL); } +void test_network_urlparse__root(void) +{ + cl_git_pass(gitno_extract_url_parts(&host, &port, &path, &user, &pass, + "http://example.com/", "8080")); + cl_assert_equal_s(host, "example.com"); + cl_assert_equal_s(port, "8080"); + cl_assert_equal_s(path, "/"); + cl_assert_equal_p(user, NULL); + cl_assert_equal_p(pass, NULL); +} + +void test_network_urlparse__just_hostname(void) +{ + cl_git_fail_with(GIT_EINVALIDSPEC, + gitno_extract_url_parts(&host, &port, &path, &user, &pass, + "http://example.com", "8080")); +} + void test_network_urlparse__encoded_password(void) { cl_git_pass(gitno_extract_url_parts(&host, &port, &path, &user, &pass, diff --git a/tests/notes/notes.c b/tests/notes/notes.c index e48d9df0e..8b1b57866 100644 --- a/tests/notes/notes.c +++ b/tests/notes/notes.c @@ -21,7 +21,7 @@ static void assert_note_equal(git_note *note, char *message, git_oid *note_oid) git_blob *blob; cl_assert_equal_s(git_note_message(note), message); - cl_assert(!git_oid_cmp(git_note_id(note), note_oid)); + cl_assert_equal_oid(git_note_id(note), note_oid); cl_git_pass(git_blob_lookup(&blob, _repo, note_oid)); cl_assert_equal_s(git_note_message(note), (const char *)git_blob_rawcontent(blob)); @@ -61,10 +61,10 @@ static int note_list_cb( cl_assert(*count < EXPECTATIONS_COUNT); cl_git_pass(git_oid_fromstr(&expected_note_oid, list_expectations[*count].note_sha)); - cl_assert(git_oid_cmp(&expected_note_oid, blob_id) == 0); + cl_assert_equal_oid(&expected_note_oid, blob_id); cl_git_pass(git_oid_fromstr(&expected_target_oid, list_expectations[*count].annotated_object_sha)); - cl_assert(git_oid_cmp(&expected_target_oid, annotated_obj_id) == 0); + cl_assert_equal_oid(&expected_target_oid, annotated_obj_id); (*count)++; @@ -290,7 +290,7 @@ void test_notes_notes__can_read_a_note_in_an_existing_fanout(void) cl_git_pass(git_note_read(¬e, _repo, "refs/notes/fanout", &target_oid)); cl_git_pass(git_oid_fromstr(¬e_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); - cl_assert(!git_oid_cmp(git_note_id(note), ¬e_oid)); + cl_assert_equal_oid(git_note_id(note), ¬e_oid); git_note_free(note); } diff --git a/tests/notes/notesref.c b/tests/notes/notesref.c index a33141979..a59af209c 100644 --- a/tests/notes/notesref.c +++ b/tests/notes/notesref.c @@ -46,13 +46,13 @@ void test_notes_notesref__config_corenotesref(void) cl_git_pass(git_note_read(&_note, _repo, NULL, &oid)); cl_assert_equal_s("test123test\n", git_note_message(_note)); - cl_assert(!git_oid_cmp(git_note_id(_note), ¬e_oid)); + cl_assert_equal_oid(git_note_id(_note), ¬e_oid); git_note_free(_note); cl_git_pass(git_note_read(&_note, _repo, "refs/notes/mydefaultnotesref", &oid)); cl_assert_equal_s("test123test\n", git_note_message(_note)); - cl_assert(!git_oid_cmp(git_note_id(_note), ¬e_oid)); + cl_assert_equal_oid(git_note_id(_note), ¬e_oid); cl_git_pass(git_note_default_ref(&default_ref, _repo)); cl_assert_equal_s("refs/notes/mydefaultnotesref", default_ref); diff --git a/tests/object/lookupbypath.c b/tests/object/lookupbypath.c index 31aac7647..13cd6a128 100644 --- a/tests/object/lookupbypath.c +++ b/tests/object/lookupbypath.c @@ -52,16 +52,16 @@ void test_object_lookupbypath__from_root_tree(void) { cl_git_pass(git_object_lookup_bypath(&g_actualobject, (git_object*)g_root_tree, "subdir/subdir_test2.txt", GIT_OBJ_BLOB)); - cl_assert_equal_i(0, git_oid_cmp(git_object_id(g_expectedobject), - git_object_id(g_actualobject))); + cl_assert_equal_oid(git_object_id(g_expectedobject), + git_object_id(g_actualobject)); } void test_object_lookupbypath__from_head_commit(void) { cl_git_pass(git_object_lookup_bypath(&g_actualobject, (git_object*)g_head_commit, "subdir/subdir_test2.txt", GIT_OBJ_BLOB)); - cl_assert_equal_i(0, git_oid_cmp(git_object_id(g_expectedobject), - git_object_id(g_actualobject))); + cl_assert_equal_oid(git_object_id(g_expectedobject), + git_object_id(g_actualobject)); } void test_object_lookupbypath__from_subdir_tree(void) @@ -74,8 +74,8 @@ void test_object_lookupbypath__from_subdir_tree(void) cl_git_pass(git_object_lookup_bypath(&g_actualobject, (git_object*)tree, "subdir_test2.txt", GIT_OBJ_BLOB)); - cl_assert_equal_i(0, git_oid_cmp(git_object_id(g_expectedobject), - git_object_id(g_actualobject))); + cl_assert_equal_oid(git_object_id(g_expectedobject), + git_object_id(g_actualobject)); git_tree_entry_free(entry); git_tree_free(tree); diff --git a/tests/object/peel.c b/tests/object/peel.c index b6c9c7a3b..6310388c4 100644 --- a/tests/object/peel.c +++ b/tests/object/peel.c @@ -29,7 +29,7 @@ static void assert_peel( cl_git_pass(git_object_peel(&peeled, obj, requested_type)); cl_git_pass(git_oid_fromstr(&expected_oid, expected_sha)); - cl_assert_equal_i(0, git_oid_cmp(&expected_oid, git_object_id(peeled))); + cl_assert_equal_oid(&expected_oid, git_object_id(peeled)); cl_assert_equal_i(expected_type, git_object_type(peeled)); diff --git a/tests/object/tree/write.c b/tests/object/tree/write.c index 45356e807..ddb62e278 100644 --- a/tests/object/tree/write.c +++ b/tests/object/tree/write.c @@ -104,6 +104,7 @@ void test_object_tree_write__subtree(void) void test_object_tree_write__sorted_subtrees(void) { git_treebuilder *builder; + git_tree *tree; unsigned int i; int position_c = -1, position_cake = -1, position_config = -1; @@ -143,8 +144,9 @@ void test_object_tree_write__sorted_subtrees(void) cl_git_pass(git_treebuilder_write(&tree_oid, g_repo, builder)); - for (i = 0; i < builder->entries.length; ++i) { - git_tree_entry *entry = git_vector_get(&builder->entries, i); + cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_oid)); + for (i = 0; i < git_tree_entrycount(tree); i++) { + const git_tree_entry *entry = git_tree_entry_byindex(tree, i); if (strcmp(entry->filename, "c") == 0) position_c = i; @@ -156,6 +158,8 @@ void test_object_tree_write__sorted_subtrees(void) position_config = i; } + git_tree_free(tree); + cl_assert(position_c != -1); cl_assert(position_cake != -1); cl_assert(position_config != -1); diff --git a/tests/odb/mixed.c b/tests/odb/mixed.c index ceba4ec81..2dad4b64e 100644 --- a/tests/odb/mixed.c +++ b/tests/odb/mixed.c @@ -58,7 +58,7 @@ void test_odb_mixed__dup_oid_prefix_0(void) { cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); cl_git_pass(git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); - cl_assert(git_oid_equal(&found, git_odb_object_id(obj))); + cl_assert_equal_oid(&found, git_odb_object_id(obj)); git_odb_object_free(obj); strncpy(hex, "dea509d0b", sizeof(hex)); @@ -79,7 +79,7 @@ void test_odb_mixed__dup_oid_prefix_0(void) { cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); cl_git_pass(git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); - cl_assert(git_oid_equal(&found, git_odb_object_id(obj))); + cl_assert_equal_oid(&found, git_odb_object_id(obj)); git_odb_object_free(obj); strncpy(hex, "81b5bff5f", sizeof(hex)); @@ -100,7 +100,7 @@ void test_odb_mixed__dup_oid_prefix_0(void) { cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); cl_git_pass(git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); - cl_assert(git_oid_equal(&found, git_odb_object_id(obj))); + cl_assert_equal_oid(&found, git_odb_object_id(obj)); git_odb_object_free(obj); strncpy(hex, "0ddeadede", sizeof(hex)); diff --git a/tests/online/clone.c b/tests/online/clone.c index 4f4312a8c..b672a099a 100644 --- a/tests/online/clone.c +++ b/tests/online/clone.c @@ -124,65 +124,49 @@ void test_online_clone__can_checkout_a_cloned_repo(void) git_buf_free(&path); } -void test_online_clone__clone_into(void) +static int remote_mirror_cb(git_remote **out, git_repository *repo, + const char *name, const char *url, void *payload) { - git_buf path = GIT_BUF_INIT; + int error; git_remote *remote; - git_reference *head; - git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT; - git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; - - bool checkout_progress_cb_was_called = false, - fetch_progress_cb_was_called = false; + git_remote_callbacks *callbacks = (git_remote_callbacks *) payload; - checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; - checkout_opts.progress_cb = &checkout_progress; - checkout_opts.progress_payload = &checkout_progress_cb_was_called; - cl_git_pass(git_repository_init(&g_repo, "./foo", false)); - cl_git_pass(git_remote_create(&remote, g_repo, "origin", LIVE_REPO_URL)); + if ((error = git_remote_create(&remote, repo, name, url)) < 0) + return error; - callbacks.transfer_progress = &fetch_progress; - callbacks.payload = &fetch_progress_cb_was_called; - git_remote_set_callbacks(remote, &callbacks); - - cl_git_pass(git_clone_into(g_repo, remote, &checkout_opts, NULL, NULL)); - - cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt")); - cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&path))); + if ((error = git_remote_set_callbacks(remote, callbacks)) < 0) { + git_remote_free(remote); + return error; + } - cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD")); - cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head)); - cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head)); + git_remote_clear_refspecs(remote); - cl_assert_equal_i(true, checkout_progress_cb_was_called); - cl_assert_equal_i(true, fetch_progress_cb_was_called); + if ((error = git_remote_add_fetch(remote, "+refs/*:refs/*")) < 0) { + git_remote_free(remote); + return error; + } - git_remote_free(remote); - git_reference_free(head); - git_buf_free(&path); + *out = remote; + return 0; } void test_online_clone__clone_mirror(void) { - git_buf path = GIT_BUF_INIT; - git_remote *remote; + git_clone_options opts = GIT_CLONE_OPTIONS_INIT; git_reference *head; git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; bool fetch_progress_cb_was_called = false; - cl_git_pass(git_repository_init(&g_repo, "./foo.git", true)); - cl_git_pass(git_remote_create(&remote, g_repo, "origin", LIVE_REPO_URL)); - callbacks.transfer_progress = &fetch_progress; callbacks.payload = &fetch_progress_cb_was_called; - git_remote_set_callbacks(remote, &callbacks); - git_remote_clear_refspecs(remote); - cl_git_pass(git_remote_add_fetch(remote, "+refs/*:refs/*")); + opts.bare = true; + opts.remote_cb = remote_mirror_cb; + opts.remote_cb_payload = &callbacks; - cl_git_pass(git_clone_into(g_repo, remote, NULL, NULL, NULL)); + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo.git", &opts)); cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD")); cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head)); @@ -190,9 +174,7 @@ void test_online_clone__clone_mirror(void) cl_assert_equal_i(true, fetch_progress_cb_was_called); - git_remote_free(remote); git_reference_free(head); - git_buf_free(&path); git_repository_free(g_repo); g_repo = NULL; @@ -306,8 +288,73 @@ void test_online_clone__can_cancel(void) git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options), 4321); } +static int cred_cb(git_cred **cred, const char *url, const char *user_from_url, + unsigned int allowed_types, void *payload) +{ + const char *remote_user = cl_getenv("GITTEST_REMOTE_USER"); + const char *pubkey = cl_getenv("GITTEST_REMOTE_SSH_PUBKEY"); + const char *privkey = cl_getenv("GITTEST_REMOTE_SSH_KEY"); + const char *passphrase = cl_getenv("GITTEST_REMOTE_SSH_PASSPHRASE"); + + GIT_UNUSED(url); GIT_UNUSED(user_from_url); GIT_UNUSED(payload); + + if (allowed_types & GIT_CREDTYPE_SSH_KEY) + return git_cred_ssh_key_new(cred, remote_user, pubkey, privkey, passphrase); + + giterr_set(GITERR_NET, "unexpected cred type"); + return -1; +} + +static int custom_remote_ssh_with_paths( + git_remote **out, + git_repository *repo, + const char *name, + const char *url, + void *payload) +{ + int error; + + git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; + + if ((error = git_remote_create(out, repo, name, url)) < 0) + return error; + + if ((error = git_remote_set_transport(*out, git_transport_ssh_with_paths, payload)) < 0) + return error; + + callbacks.credentials = cred_cb; + git_remote_set_callbacks(*out, &callbacks); + + return 0; +} + +void test_online_clone__ssh_with_paths(void) +{ + char *bad_paths[] = { + "/bin/yes", + "/bin/false", + }; + char *good_paths[] = { + "/usr/bin/git-upload-pack", + "/usr/bin/git-receive-pack", + }; + git_strarray arr = { + bad_paths, + 2, + }; + const char *remote_url = cl_getenv("GITTEST_REMOTE_URL"); + const char *remote_user = cl_getenv("GITTEST_REMOTE_USER"); + if (!remote_url || !remote_user) + clar__skip(); + g_options.remote_cb = custom_remote_ssh_with_paths; + g_options.remote_cb_payload = &arr; + cl_git_fail(git_clone(&g_repo, remote_url, "./foo", &g_options)); + + arr.strings = good_paths; + cl_git_pass(git_clone(&g_repo, remote_url, "./foo", &g_options)); +} diff --git a/tests/pack/indexer.c b/tests/pack/indexer.c index 084f8e666..49a106d98 100644 --- a/tests/pack/indexer.c +++ b/tests/pack/indexer.c @@ -74,7 +74,7 @@ void test_pack_indexer__fix_thin(void) /* Store the missing base into your ODB so the indexer can fix the pack */ cl_git_pass(git_odb_write(&id, odb, base_obj, base_obj_len, GIT_OBJ_BLOB)); git_oid_fromstr(&should_id, "e68fe8129b546b101aee9510c5328e7f21ca1d18"); - cl_assert(!git_oid_cmp(&id, &should_id)); + cl_assert_equal_oid(&should_id, &id); cl_git_pass(git_indexer_new(&idx, ".", 0, odb, NULL, NULL)); cl_git_pass(git_indexer_append(idx, thin_pack, thin_pack_len, &stats)); @@ -86,7 +86,7 @@ void test_pack_indexer__fix_thin(void) cl_assert_equal_i(stats.local_objects, 1); git_oid_fromstr(&should_id, "11f0f69b334728fdd8bc86b80499f22f29d85b15"); - cl_assert(!git_oid_cmp(git_indexer_hash(idx), &should_id)); + cl_assert_equal_oid(&should_id, git_indexer_hash(idx)); git_indexer_free(idx); git_odb_free(odb); diff --git a/tests/pack/sharing.c b/tests/pack/sharing.c new file mode 100644 index 000000000..a67d65588 --- /dev/null +++ b/tests/pack/sharing.c @@ -0,0 +1,42 @@ +#include "clar_libgit2.h" +#include <git2.h> +#include "strmap.h" +#include "mwindow.h" +#include "pack.h" + +extern git_strmap *git__pack_cache; + +void test_pack_sharing__open_two_repos(void) +{ + git_repository *repo1, *repo2; + git_object *obj1, *obj2; + git_oid id; + git_strmap_iter pos; + void *data; + int error; + + cl_git_pass(git_repository_open(&repo1, cl_fixture("testrepo.git"))); + cl_git_pass(git_repository_open(&repo2, cl_fixture("testrepo.git"))); + + git_oid_fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + + cl_git_pass(git_object_lookup(&obj1, repo1, &id, GIT_OBJ_ANY)); + cl_git_pass(git_object_lookup(&obj2, repo2, &id, GIT_OBJ_ANY)); + + pos = 0; + while ((error = git_strmap_next(&data, &pos, git__pack_cache)) == 0) { + struct git_pack_file *pack = (struct git_pack_file *) data; + + cl_assert_equal_i(2, pack->refcount.val); + } + + cl_assert_equal_i(3, git_strmap_num_entries(git__pack_cache)); + + git_object_free(obj1); + git_object_free(obj2); + git_repository_free(repo1); + git_repository_free(repo2); + + /* we don't want to keep the packs open after the repos go away */ + cl_assert_equal_i(0, git_strmap_num_entries(git__pack_cache)); +} diff --git a/tests/refs/create.c b/tests/refs/create.c index 50b8e84f8..8e4d8d70b 100644 --- a/tests/refs/create.c +++ b/tests/refs/create.c @@ -45,7 +45,7 @@ void test_refs_create__symbolic(void) cl_assert(git_reference_type(resolved_ref) == GIT_REF_OID); /* ...and that it points to the current master tip */ - cl_assert(git_oid_cmp(&id, git_reference_target(resolved_ref)) == 0); + cl_assert_equal_oid(&id, git_reference_target(resolved_ref)); git_reference_free(looked_up_ref); git_reference_free(resolved_ref); @@ -54,7 +54,7 @@ void test_refs_create__symbolic(void) cl_git_pass(git_reference_lookup(&looked_up_ref, repo2, new_head_tracker)); cl_git_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); - cl_assert(git_oid_cmp(&id, git_reference_target(resolved_ref)) == 0); + cl_assert_equal_oid(&id, git_reference_target(resolved_ref)); git_repository_free(repo2); @@ -76,7 +76,7 @@ void test_refs_create__deep_symbolic(void) cl_git_pass(git_reference_symbolic_create(&new_reference, g_repo, new_head_tracker, current_head_target, 0, NULL, NULL)); cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head_tracker)); cl_git_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); - cl_assert(git_oid_cmp(&id, git_reference_target(resolved_ref)) == 0); + cl_assert_equal_oid(&id, git_reference_target(resolved_ref)); git_reference_free(new_reference); git_reference_free(looked_up_ref); @@ -104,14 +104,14 @@ void test_refs_create__oid(void) cl_assert_equal_s(looked_up_ref->name, new_head); /* ...and that it points to the current master tip */ - cl_assert(git_oid_cmp(&id, git_reference_target(looked_up_ref)) == 0); + cl_assert_equal_oid(&id, git_reference_target(looked_up_ref)); git_reference_free(looked_up_ref); /* Similar test with a fresh new repository */ cl_git_pass(git_repository_open(&repo2, "testrepo")); cl_git_pass(git_reference_lookup(&looked_up_ref, repo2, new_head)); - cl_assert(git_oid_cmp(&id, git_reference_target(looked_up_ref)) == 0); + cl_assert_equal_oid(&id, git_reference_target(looked_up_ref)); git_repository_free(repo2); diff --git a/tests/refs/createwithlog.c b/tests/refs/createwithlog.c index 026ff6d6a..ab13d7d15 100644 --- a/tests/refs/createwithlog.c +++ b/tests/refs/createwithlog.c @@ -42,7 +42,7 @@ void test_refs_createwithlog__creating_a_direct_reference_adds_a_reflog_entry(vo entry = git_reflog_entry_byindex(reflog, 0); cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0); - cl_assert(git_oid_cmp(&id, &entry->oid_cur) == 0); + cl_assert_equal_oid(&id, &entry->oid_cur); cl_assert_equal_s(message, entry->msg); git_reflog_free(reflog); diff --git a/tests/refs/lookup.c b/tests/refs/lookup.c index 2e31cf0f6..d076e491f 100644 --- a/tests/refs/lookup.c +++ b/tests/refs/lookup.c @@ -44,7 +44,7 @@ void test_refs_lookup__oid(void) cl_git_pass(git_reference_name_to_id(&tag, g_repo, "refs/tags/point_to_blob")); cl_git_pass(git_oid_fromstr(&expected, "1385f264afb75a56a5bec74243be9b367ba4ca08")); - cl_assert(git_oid_cmp(&tag, &expected) == 0); + cl_assert_equal_oid(&expected, &tag); } void test_refs_lookup__namespace(void) diff --git a/tests/refs/overwrite.c b/tests/refs/overwrite.c index 78ce4ace7..c237d76f4 100644 --- a/tests/refs/overwrite.c +++ b/tests/refs/overwrite.c @@ -78,7 +78,7 @@ void test_refs_overwrite__object_id(void) /* Ensure it has been overwritten */ cl_git_pass(git_reference_lookup(&ref, g_repo, ref_name)); - cl_assert(!git_oid_cmp(&id, git_reference_target(ref))); + cl_assert_equal_oid(&id, git_reference_target(ref)); git_reference_free(ref); } @@ -130,7 +130,7 @@ void test_refs_overwrite__symbolic_with_object_id(void) /* Ensure it points to the right place */ cl_git_pass(git_reference_lookup(&ref, g_repo, ref_name)); cl_assert(git_reference_type(ref) & GIT_REF_OID); - cl_assert(!git_oid_cmp(git_reference_target(ref), &id)); + cl_assert_equal_oid(&id, git_reference_target(ref)); git_reference_free(ref); } diff --git a/tests/refs/peel.c b/tests/refs/peel.c index f2fb6e259..542694c47 100644 --- a/tests/refs/peel.c +++ b/tests/refs/peel.c @@ -33,7 +33,7 @@ static void assert_peel_generic( cl_git_pass(git_reference_peel(&peeled, ref, requested_type)); cl_git_pass(git_oid_fromstr(&expected_oid, expected_sha)); - cl_assert_equal_i(0, git_oid_cmp(&expected_oid, git_object_id(peeled))); + cl_assert_equal_oid(&expected_oid, git_object_id(peeled)); cl_assert_equal_i(expected_type, git_object_type(peeled)); diff --git a/tests/refs/read.c b/tests/refs/read.c index 52c307eb0..cb42a568b 100644 --- a/tests/refs/read.c +++ b/tests/refs/read.c @@ -83,7 +83,7 @@ void test_refs_read__symbolic(void) cl_assert(git_object_type(object) == GIT_OBJ_COMMIT); git_oid_fromstr(&id, current_master_tip); - cl_assert(git_oid_cmp(&id, git_object_id(object)) == 0); + cl_assert_equal_oid(&id, git_object_id(object)); git_object_free(object); @@ -111,7 +111,7 @@ void test_refs_read__nested_symbolic(void) cl_assert(git_object_type(object) == GIT_OBJ_COMMIT); git_oid_fromstr(&id, current_master_tip); - cl_assert(git_oid_cmp(&id, git_object_id(object)) == 0); + cl_assert_equal_oid(&id, git_object_id(object)); git_object_free(object); @@ -130,13 +130,13 @@ void test_refs_read__head_then_master(void) cl_git_pass(git_reference_lookup(&reference, g_repo, GIT_HEAD_FILE)); cl_git_pass(git_reference_resolve(&resolved_ref, reference)); - cl_git_pass(git_oid_cmp(git_reference_target(comp_base_ref), git_reference_target(resolved_ref))); + cl_assert_equal_oid(git_reference_target(comp_base_ref), git_reference_target(resolved_ref)); git_reference_free(reference); git_reference_free(resolved_ref); cl_git_pass(git_reference_lookup(&reference, g_repo, current_head_target)); cl_git_pass(git_reference_resolve(&resolved_ref, reference)); - cl_git_pass(git_oid_cmp(git_reference_target(comp_base_ref), git_reference_target(resolved_ref))); + cl_assert_equal_oid(git_reference_target(comp_base_ref), git_reference_target(resolved_ref)); git_reference_free(reference); git_reference_free(resolved_ref); @@ -152,7 +152,7 @@ void test_refs_read__master_then_head(void) cl_git_pass(git_reference_lookup(&reference, g_repo, GIT_HEAD_FILE)); cl_git_pass(git_reference_resolve(&resolved_ref, reference)); - cl_git_pass(git_oid_cmp(git_reference_target(master_ref), git_reference_target(resolved_ref))); + cl_assert_equal_oid(git_reference_target(master_ref), git_reference_target(resolved_ref)); git_reference_free(reference); git_reference_free(resolved_ref); @@ -201,7 +201,7 @@ void test_refs_read__chomped(void) cl_git_pass(git_reference_lookup(&test, g_repo, "refs/heads/test")); cl_git_pass(git_reference_lookup(&chomped, g_repo, "refs/heads/chomped")); - cl_git_pass(git_oid_cmp(git_reference_target(test), git_reference_target(chomped))); + cl_assert_equal_oid(git_reference_target(test), git_reference_target(chomped)); git_reference_free(test); git_reference_free(chomped); @@ -213,7 +213,7 @@ void test_refs_read__trailing(void) cl_git_pass(git_reference_lookup(&test, g_repo, "refs/heads/test")); cl_git_pass(git_reference_lookup(&trailing, g_repo, "refs/heads/trailing")); - cl_git_pass(git_oid_cmp(git_reference_target(test), git_reference_target(trailing))); + cl_assert_equal_oid(git_reference_target(test), git_reference_target(trailing)); git_reference_free(trailing); cl_git_pass(git_reference_lookup(&trailing, g_repo, "FETCH_HEAD")); diff --git a/tests/refs/rename.c b/tests/refs/rename.c index 88f0afd9c..c7901bd8b 100644 --- a/tests/refs/rename.c +++ b/tests/refs/rename.c @@ -220,7 +220,7 @@ void test_refs_rename__force_loose_packed(void) /* Check we actually renamed it */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_test_head_name)); cl_assert_equal_s(looked_up_ref->name, packed_test_head_name); - cl_assert(!git_oid_cmp(&oid, git_reference_target(looked_up_ref))); + cl_assert_equal_oid(&oid, git_reference_target(looked_up_ref)); git_reference_free(looked_up_ref); /* And that the previous one doesn't exist any longer */ @@ -245,7 +245,7 @@ void test_refs_rename__force_loose(void) /* Check we actually renamed it */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, "refs/heads/test")); cl_assert_equal_s(looked_up_ref->name, "refs/heads/test"); - cl_assert(!git_oid_cmp(&oid, git_reference_target(looked_up_ref))); + cl_assert_equal_oid(&oid, git_reference_target(looked_up_ref)); git_reference_free(looked_up_ref); /* And that the previous one doesn't exist any longer */ diff --git a/tests/refs/settargetwithlog.c b/tests/refs/settargetwithlog.c index 524ce771c..3a3378186 100644 --- a/tests/refs/settargetwithlog.c +++ b/tests/refs/settargetwithlog.c @@ -44,8 +44,8 @@ void test_refs_settargetwithlog__updating_a_direct_reference_adds_a_reflog_entry cl_git_pass(git_reflog_read(&reflog, g_repo, br2_name)); entry = git_reflog_entry_byindex(reflog, 0); - cl_assert(git_oid_cmp(¤t_id, &entry->oid_old) == 0); - cl_assert(git_oid_cmp(&target_id, &entry->oid_cur) == 0); + cl_assert_equal_oid(¤t_id, &entry->oid_old); + cl_assert_equal_oid(&target_id, &entry->oid_cur); cl_assert_equal_s(message, entry->msg); git_reflog_free(reflog); diff --git a/tests/refs/setter.c b/tests/refs/setter.c index 9a945db00..a5d073a56 100644 --- a/tests/refs/setter.c +++ b/tests/refs/setter.c @@ -41,7 +41,7 @@ void test_refs_setter__update_direct(void) cl_git_pass(git_reference_lookup(&test_ref, g_repo, ref_test_name)); cl_assert(git_reference_type(test_ref) == GIT_REF_OID); - cl_assert(git_oid_cmp(&id, git_reference_target(test_ref)) == 0); + cl_assert_equal_oid(&id, git_reference_target(test_ref)); git_reference_free(test_ref); } diff --git a/tests/refs/unicode.c b/tests/refs/unicode.c index 471b0b8d3..9c7527cd7 100644 --- a/tests/refs/unicode.c +++ b/tests/refs/unicode.c @@ -32,8 +32,7 @@ void test_refs_unicode__create_and_lookup(void) cl_git_pass(git_repository_open(&repo2, "testrepo.git")); cl_git_pass(git_reference_lookup(&ref2, repo2, REFNAME)); - cl_assert_equal_i( - 0, git_oid_cmp(git_reference_target(ref1), git_reference_target(ref2))); + cl_assert_equal_oid(git_reference_target(ref1), git_reference_target(ref2)); cl_assert_equal_s(REFNAME, git_reference_name(ref2)); git_reference_free(ref2); @@ -43,8 +42,7 @@ void test_refs_unicode__create_and_lookup(void) #define REFNAME_DECOMPOSED "refs/heads/" "A" "\314\212" "ngstro" "\314\210" "m" cl_git_pass(git_reference_lookup(&ref2, repo2, REFNAME_DECOMPOSED)); - cl_assert_equal_i( - 0, git_oid_cmp(git_reference_target(ref1), git_reference_target(ref2))); + cl_assert_equal_oid(git_reference_target(ref1), git_reference_target(ref2)); cl_assert_equal_s(REFNAME, git_reference_name(ref2)); git_reference_free(ref2); #endif diff --git a/tests/repo/hashfile.c b/tests/repo/hashfile.c index 4cc9f18b4..ae8e122f6 100644 --- a/tests/repo/hashfile.c +++ b/tests/repo/hashfile.c @@ -22,14 +22,14 @@ void test_repo_hashfile__simple(void) /* hash with repo relative path */ cl_git_pass(git_odb_hashfile(&a, "status/current_file", GIT_OBJ_BLOB)); cl_git_pass(git_repository_hashfile(&b, _repo, "current_file", GIT_OBJ_BLOB, NULL)); - cl_assert(git_oid_equal(&a, &b)); + cl_assert_equal_oid(&a, &b); cl_git_pass(git_buf_joinpath(&full, git_repository_workdir(_repo), "current_file")); /* hash with full path */ cl_git_pass(git_odb_hashfile(&a, full.ptr, GIT_OBJ_BLOB)); cl_git_pass(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJ_BLOB, NULL)); - cl_assert(git_oid_equal(&a, &b)); + cl_assert_equal_oid(&a, &b); /* hash with invalid type */ cl_git_fail(git_odb_hashfile(&a, full.ptr, GIT_OBJ_ANY)); @@ -58,12 +58,12 @@ void test_repo_hashfile__filtered(void) /* equal hashes because filter is binary */ cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJ_BLOB)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJ_BLOB, NULL)); - cl_assert(git_oid_equal(&a, &b)); + cl_assert_equal_oid(&a, &b); /* equal hashes when 'as_file' points to binary filtering */ cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJ_BLOB)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_BLOB, "foo.bin")); - cl_assert(git_oid_equal(&a, &b)); + cl_assert_equal_oid(&a, &b); /* not equal hashes when 'as_file' points to text filtering */ cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJ_BLOB)); @@ -73,11 +73,11 @@ void test_repo_hashfile__filtered(void) /* equal hashes when 'as_file' is empty and turns off filtering */ cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJ_BLOB)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_BLOB, "")); - cl_assert(git_oid_equal(&a, &b)); + cl_assert_equal_oid(&a, &b); cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJ_BLOB)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJ_BLOB, "")); - cl_assert(git_oid_equal(&a, &b)); + cl_assert_equal_oid(&a, &b); /* some hash type failures */ cl_git_fail(git_odb_hashfile(&a, "status/testfile.txt", 0)); diff --git a/tests/repo/head.c b/tests/repo/head.c index 79892a3ea..d678e150e 100644 --- a/tests/repo/head.c +++ b/tests/repo/head.c @@ -229,13 +229,13 @@ static void test_reflog(git_repository *repo, size_t idx, if (old_spec) { git_object *obj; cl_git_pass(git_revparse_single(&obj, repo, old_spec)); - cl_assert_equal_i(0, git_oid_cmp(git_object_id(obj), git_reflog_entry_id_old(entry))); + cl_assert_equal_oid(git_object_id(obj), git_reflog_entry_id_old(entry)); git_object_free(obj); } if (new_spec) { git_object *obj; cl_git_pass(git_revparse_single(&obj, repo, new_spec)); - cl_assert_equal_i(0, git_oid_cmp(git_object_id(obj), git_reflog_entry_id_new(entry))); + cl_assert_equal_oid(git_object_id(obj), git_reflog_entry_id_new(entry)); git_object_free(obj); } diff --git a/tests/revwalk/hidecb.c b/tests/revwalk/hidecb.c index 26ff183fa..14cf39afd 100644 --- a/tests/revwalk/hidecb.c +++ b/tests/revwalk/hidecb.c @@ -69,21 +69,15 @@ static int hide_commit_cb(const git_oid *commit_id, void *data) GIT_UNUSED(commit_id); GIT_UNUSED(data); - if (0 == git_oid_cmp(commit_id, &commit_ids[5])) - return 1; - else - return 0; - + return (git_oid_cmp(commit_id, &commit_ids[5]) == 0); } /* In payload data, pointer to a commit id is passed */ static int hide_commit_use_payload_cb(const git_oid *commit_id, void *data) { git_oid *hide_commit_id = data; - if (git_oid_cmp(commit_id, hide_commit_id) == 0) - return 1; - else - return 0; + + return (git_oid_cmp(commit_id, hide_commit_id) == 0); } void test_revwalk_hidecb__hide_all_cb(void) @@ -170,7 +164,7 @@ void test_revwalk_hidecb__hide_some_commits(void) i = 0; while ((error = git_revwalk_next(&id, walk)) == 0) { - cl_assert_equal_i(git_oid_cmp(&id, &commit_ids[i]), 0); + cl_assert_equal_oid(&commit_ids[i], &id); i++; } @@ -194,7 +188,7 @@ void test_revwalk_hidecb__test_payload(void) i = 0; while ((error = git_revwalk_next(&id, walk)) == 0) { - cl_assert_equal_i(git_oid_cmp(&id, &commit_ids[i]), 0); + cl_assert_equal_oid(&commit_ids[i], &id); i++; } diff --git a/tests/revwalk/mergebase.c b/tests/revwalk/mergebase.c index 97663502c..2c7184fc7 100644 --- a/tests/revwalk/mergebase.c +++ b/tests/revwalk/mergebase.c @@ -30,7 +30,7 @@ void test_revwalk_mergebase__single1(void) cl_git_pass(git_oid_fromstr(&expected, "5b5b025afb0b4c913b4c338a42934a3863bf3644")); cl_git_pass(git_merge_base(&result, _repo, &one, &two)); - cl_assert(git_oid_cmp(&result, &expected) == 0); + cl_assert_equal_oid(&expected, &result); cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &one, &two)); cl_assert_equal_sz(ahead, 2); @@ -51,7 +51,7 @@ void test_revwalk_mergebase__single2(void) cl_git_pass(git_oid_fromstr(&expected, "c47800c7266a2be04c571c04d5a6614691ea99bd")); cl_git_pass(git_merge_base(&result, _repo, &one, &two)); - cl_assert(git_oid_cmp(&result, &expected) == 0); + cl_assert_equal_oid(&expected, &result); cl_git_pass(git_graph_ahead_behind( &ahead, &behind, _repo, &one, &two)); cl_assert_equal_sz(ahead, 4); @@ -72,10 +72,10 @@ void test_revwalk_mergebase__merged_branch(void) cl_git_pass(git_oid_fromstr(&expected, "9fd738e8f7967c078dceed8190330fc8648ee56a")); cl_git_pass(git_merge_base(&result, _repo, &one, &two)); - cl_assert(git_oid_cmp(&result, &expected) == 0); + cl_assert_equal_oid(&expected, &result); cl_git_pass(git_merge_base(&result, _repo, &two, &one)); - cl_assert(git_oid_cmp(&result, &expected) == 0); + cl_assert_equal_oid(&expected, &result); cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &one, &two)); cl_assert_equal_sz(ahead, 0); @@ -132,7 +132,7 @@ void test_revwalk_mergebase__prefer_youngest_merge_base(void) cl_git_pass(git_oid_fromstr(&expected, "c47800c7266a2be04c571c04d5a6614691ea99bd")); cl_git_pass(git_merge_base(&result, _repo, &one, &two)); - cl_assert(git_oid_cmp(&result, &expected) == 0); + cl_assert_equal_oid(&expected, &result); } void test_revwalk_mergebase__no_off_by_one_missing(void) @@ -177,7 +177,7 @@ static void assert_mergebase_many(const char *expected_sha, int count, ...) cl_git_pass(git_merge_base_many(&oid, _repo, count, oids)); cl_git_pass(git_oid_fromstr(&expected, expected_sha)); - cl_assert(git_oid_cmp(&expected, &oid) == 0); + cl_assert_equal_oid(&expected, &oid); } git__free(oids); @@ -241,7 +241,7 @@ static void assert_mergebase_octopus(const char *expected_sha, int count, ...) cl_git_pass(git_merge_base_octopus(&oid, _repo, count, oids)); cl_git_pass(git_oid_fromstr(&expected, expected_sha)); - cl_assert(git_oid_cmp(&expected, &oid) == 0); + cl_assert_equal_oid(&expected, &oid); } git__free(oids); diff --git a/tests/revwalk/simplify.c b/tests/revwalk/simplify.c index 81c19d366..f65ce6c59 100644 --- a/tests/revwalk/simplify.c +++ b/tests/revwalk/simplify.c @@ -20,8 +20,8 @@ static const char *commit_head = "a4a7dce85cf63874e984719f4fdd239f5145052f"; static const char *expected_str[] = { "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */ "c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */ - "8496071c1b46c854b31185ea97743be6a8774479", /* 4 */ - "5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */ + "5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 4 */ + "8496071c1b46c854b31185ea97743be6a8774479", /* 5 */ }; void test_revwalk_simplify__first_parent(void) @@ -44,7 +44,7 @@ void test_revwalk_simplify__first_parent(void) i = 0; while ((error = git_revwalk_next(&id, walk)) == 0) { - git_oid_cmp(&id, &expected[i]); + cl_assert_equal_oid(&expected[i], &id); i++; } diff --git a/tests/stash/drop.c b/tests/stash/drop.c index 63ff0377c..89a0ade72 100644 --- a/tests/stash/drop.c +++ b/tests/stash/drop.c @@ -115,7 +115,7 @@ void test_stash_drop__dropping_an_entry_rewrites_reflog_history(void) cl_git_pass(git_reflog_read(&reflog, repo, GIT_REFS_STASH_FILE)); entry = git_reflog_entry_byindex(reflog, 0); - cl_assert_equal_i(0, git_oid_cmp(&oid, git_reflog_entry_id_old(entry))); + cl_assert_equal_oid(&oid, git_reflog_entry_id_old(entry)); cl_assert_equal_sz(count - 1, git_reflog_entrycount(reflog)); git_reflog_free(reflog); @@ -147,7 +147,7 @@ void retrieve_top_stash_id(git_oid *out) cl_git_pass(git_revparse_single(&top_stash, repo, "stash@{0}")); cl_git_pass(git_reference_name_to_id(out, repo, GIT_REFS_STASH_FILE)); - cl_assert_equal_i(true, git_oid_cmp(out, git_object_id(top_stash)) == 0); + cl_assert_equal_oid(out, git_object_id(top_stash)); git_object_free(top_stash); } @@ -162,13 +162,13 @@ void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void) retrieve_top_stash_id(&oid); cl_git_pass(git_revparse_single(&next_top_stash, repo, "stash@{1}")); - cl_assert(git_oid_cmp(&oid, git_object_id(next_top_stash)) != 0); + cl_assert(git_oid_cmp(&oid, git_object_id(next_top_stash))); cl_git_pass(git_stash_drop(repo, 0)); retrieve_top_stash_id(&oid); - cl_git_pass(git_oid_cmp(&oid, git_object_id(next_top_stash))); + cl_assert_equal_oid(&oid, git_object_id(next_top_stash)); git_object_free(next_top_stash); } diff --git a/tests/status/single.c b/tests/status/single.c index 292c9120a..6efaab294 100644 --- a/tests/status/single.c +++ b/tests/status/single.c @@ -22,7 +22,7 @@ void test_status_single__hash_single_file(void) cl_set_cleanup(&cleanup__remove_file, (void *)file_name); cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJ_BLOB)); - cl_assert(git_oid_cmp(&expected_id, &actual_id) == 0); + cl_assert_equal_oid(&expected_id, &actual_id); } /* test retrieving OID from an empty file apart from the ODB */ @@ -40,6 +40,6 @@ void test_status_single__hash_single_empty_file(void) cl_set_cleanup(&cleanup__remove_file, (void *)file_name); cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJ_BLOB)); - cl_assert(git_oid_cmp(&expected_id, &actual_id) == 0); + cl_assert_equal_oid(&expected_id, &actual_id); } diff --git a/tests/threads/diff.c b/tests/threads/diff.c index 79b85800b..c32811469 100644 --- a/tests/threads/diff.c +++ b/tests/threads/diff.c @@ -1,6 +1,20 @@ #include "clar_libgit2.h" #include "thread_helpers.h" +#ifdef GIT_THREADS + +# if defined(GIT_WIN32) +# define git_thread_yield() Sleep(0) +# elif defined(__FreeBSD__) || defined(__MidnightBSD__) || defined(__DragonFly__) +# define git_thread_yield() pthread_yield() +# else +# define git_thread_yield() sched_yield() +# endif + +#else +# define git_thread_yield() (void)0 +#endif + static git_repository *_repo; static git_tree *_a, *_b; static git_atomic _counts[4]; |