diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-08-01 11:49:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-01 11:49:50 +0200 |
commit | eea128b5509e333abf80d44ccef2312e5bf89708 (patch) | |
tree | 1b1178c7e4a45c705f90893b7a4fbf235a18f88d | |
parent | e8f6341105c7221e1358a5f6fda23e57c17eadc5 (diff) | |
parent | fdd10839acb334419deba34f4716f9db9f3c4850 (diff) | |
download | libgit2-eea128b5509e333abf80d44ccef2312e5bf89708.tar.gz |
Merge pull request #5135 from j143-bot/jdev01
Include ahead_behind in the test suite
-rw-r--r-- | tests/graph/ahead_behind.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/graph/ahead_behind.c b/tests/graph/ahead_behind.c new file mode 100644 index 000000000..77d7768af --- /dev/null +++ b/tests/graph/ahead_behind.c @@ -0,0 +1,58 @@ +#include "clar_libgit2.h" + +static git_repository *_repo; +static git_commit *commit; +static size_t ahead; +static size_t behind; + +void test_graph_ahead_behind__initialize(void) +{ + git_oid oid; + cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git"))); + + cl_git_pass(git_oid_fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); + cl_git_pass(git_commit_lookup(&commit, _repo, &oid)); +} + +void test_graph_ahead_behind__cleanup(void) +{ + git_commit_free(commit); + commit = NULL; + + git_repository_free(_repo); + _repo = NULL; +} + +void test_graph_ahead_behind__returns_correct_result(void) +{ + git_oid oid; + git_oid oid2; + git_commit *other; + + cl_git_pass(git_oid_fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d")); + cl_git_pass(git_oid_fromstr(&oid2, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); + + cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &oid, &oid2)); + cl_assert_equal_sz(2, ahead); + cl_assert_equal_sz(6, behind); + + cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(commit), git_commit_id(commit))); + cl_assert_equal_sz(ahead, behind); + cl_git_pass(git_commit_nth_gen_ancestor(&other, commit, 1)); + + cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(commit), git_commit_id(other))); + cl_assert_equal_sz(ahead, behind + 2); + cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(other), git_commit_id(commit))); + cl_assert_equal_sz(ahead + 2, behind); + + git_commit_free(other); + + cl_git_pass(git_commit_nth_gen_ancestor(&other, commit, 3)); + + cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(commit), git_commit_id(other))); + cl_assert_equal_sz(ahead, behind + 4); + cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(other), git_commit_id(commit))); + cl_assert_equal_sz(ahead + 4, behind); + + git_commit_free(other); +} |