diff options
| author | Vicent Martà <vicent@github.com> | 2012-11-23 15:19:47 -0800 |
|---|---|---|
| committer | Vicent Martà <vicent@github.com> | 2012-11-23 15:19:47 -0800 |
| commit | c4d8df27bc4d3c0ef5ea46f4953614955fc4bdc2 (patch) | |
| tree | 62a1d39f547c562d71558309e6548783202d62dc /tests-clar | |
| parent | 28de452a4b7915f1bb0c6913c23c04d412b281c7 (diff) | |
| parent | 5cec896a3b7b85190a7862fb09f8ba20b2241f76 (diff) | |
| download | libgit2-c4d8df27bc4d3c0ef5ea46f4953614955fc4bdc2.tar.gz | |
Merge pull request #1097 from nulltoken/topic/head_tree_error
Make `git_repository_head_tree()` return error codes
Diffstat (limited to 'tests-clar')
| -rw-r--r-- | tests-clar/repo/head.c | 6 | ||||
| -rw-r--r-- | tests-clar/repo/headtree.c | 53 |
2 files changed, 56 insertions, 3 deletions
diff --git a/tests-clar/repo/head.c b/tests-clar/repo/head.c index 23d14d619..1c1e905c4 100644 --- a/tests-clar/repo/head.c +++ b/tests-clar/repo/head.c @@ -19,9 +19,9 @@ void test_repo_head__head_detached(void) { git_reference *ref; - cl_assert(git_repository_head_detached(repo) == 0); + cl_git_pass(git_repository_head_detached(repo)); - git_repository_detach_head(repo); + cl_git_pass(git_repository_detach_head(repo)); cl_assert_equal_i(true, git_repository_head_detached(repo)); @@ -36,7 +36,7 @@ void test_repo_head__head_orphan(void) { git_reference *ref; - cl_assert(git_repository_head_orphan(repo) == 0); + cl_git_pass(git_repository_head_detached(repo)); make_head_orphaned(repo, NON_EXISTING_HEAD); diff --git a/tests-clar/repo/headtree.c b/tests-clar/repo/headtree.c new file mode 100644 index 000000000..0e7fe93e5 --- /dev/null +++ b/tests-clar/repo/headtree.c @@ -0,0 +1,53 @@ +#include "clar_libgit2.h" +#include "repository.h" +#include "repo_helpers.h" +#include "posix.h" + +static git_repository *repo; +static git_tree *tree; + +void test_repo_headtree__initialize(void) +{ + repo = cl_git_sandbox_init("testrepo.git"); + tree = NULL; +} + +void test_repo_headtree__cleanup(void) +{ + git_tree_free(tree); + cl_git_sandbox_cleanup(); +} + +void test_repo_headtree__can_retrieve_the_root_tree_from_a_detached_head(void) +{ + cl_git_pass(git_repository_detach_head(repo)); + + cl_git_pass(git_repository_head_tree(&tree, repo)); + + cl_assert(git_oid_streq(git_tree_id(tree), "az")); +} + +void test_repo_headtree__can_retrieve_the_root_tree_from_a_non_detached_head(void) +{ + cl_assert_equal_i(false, git_repository_head_detached(repo)); + + cl_git_pass(git_repository_head_tree(&tree, repo)); + + cl_assert(git_oid_streq(git_tree_id(tree), "az")); +} + +void test_repo_headtree__when_head_is_orphaned_returns_EORPHANEDHEAD(void) +{ + make_head_orphaned(repo, NON_EXISTING_HEAD); + + cl_assert_equal_i(true, git_repository_head_orphan(repo)); + + cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_head_tree(&tree, repo)); +} + +void test_repo_headtree__when_head_is_missing_returns_ENOTFOUND(void) +{ + delete_head(repo); + + cl_assert_equal_i(GIT_ENOTFOUND, git_repository_head_tree(&tree, repo)); +} |
