Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests-clar/object/tree/frompath.c')
-rw-r--r--tests-clar/object/tree/frompath.c79
1 files changed, 33 insertions, 46 deletions
diff --git a/tests-clar/object/tree/frompath.c b/tests-clar/object/tree/frompath.c
index 06c69ac08..86ca47e94 100644
--- a/tests-clar/object/tree/frompath.c
+++ b/tests-clar/object/tree/frompath.c
@@ -1,15 +1,14 @@
#include "clar_libgit2.h"
static git_repository *repo;
-const char *tree_with_subtrees_oid = "ae90f12eea699729ed24555e40b9fd669da12a12";
static git_tree *tree;
void test_object_tree_frompath__initialize(void)
{
git_oid id;
+ const char *tree_with_subtrees_oid = "ae90f12eea699729ed24555e40b9fd669da12a12";
- cl_fixture_sandbox("testrepo.git");
- cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_assert(repo != NULL);
cl_git_pass(git_oid_fromstr(&id, tree_with_subtrees_oid));
@@ -20,62 +19,50 @@ void test_object_tree_frompath__initialize(void)
void test_object_tree_frompath__cleanup(void)
{
git_tree_free(tree);
+ tree = NULL;
+
git_repository_free(repo);
- cl_fixture_cleanup("testrepo.git");
+ repo = NULL;
}
-static void assert_tree_from_path(git_tree *root, const char *path, int expected_result, const char *expected_raw_oid)
+static void assert_tree_from_path(
+ git_tree *root,
+ const char *path,
+ const char *expected_entry_name)
{
- git_tree *containing_tree = NULL;
-
- cl_assert(git_tree_get_subtree(&containing_tree, root, path) == expected_result);
-
- if (containing_tree == NULL && expected_result != 0)
- return;
-
- cl_assert(containing_tree != NULL && expected_result == 0);
-
- cl_git_pass(git_oid_streq(git_object_id((const git_object *)containing_tree), expected_raw_oid));
+ git_tree_entry *entry;
- git_tree_free(containing_tree);
-}
-
-static void assert_tree_from_path_klass(git_tree *root, const char *path, int expected_result, const char *expected_raw_oid)
-{
- assert_tree_from_path(root, path, GIT_ERROR, expected_raw_oid);
- cl_assert(giterr_last()->klass == expected_result);
+ cl_git_pass(git_tree_entry_bypath(&entry, root, path));
+ cl_assert_equal_s(git_tree_entry_name(entry), expected_entry_name);
+ git_tree_entry_free(entry);
}
void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(void)
{
- /* Will return self if given a one path segment... */
- assert_tree_from_path(tree, "README", 0, tree_with_subtrees_oid);
-
- /* ...even one that lead to a non existent tree entry. */
- assert_tree_from_path(tree, "i-do-not-exist.txt", 0, tree_with_subtrees_oid);
-
- /* Will return fgh tree oid given this following path... */
- assert_tree_from_path(tree, "ab/de/fgh/1.txt", 0, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54");
-
- /* ... and ab tree oid given this one. */
- assert_tree_from_path(tree, "ab/de", 0, "f1425cef211cc08caa31e7b545ffb232acb098c3");
+ git_tree_entry *e;
- /* Will succeed if given a valid path which leads to a tree entry which doesn't exist */
- assert_tree_from_path(tree, "ab/de/fgh/i-do-not-exist.txt", 0, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54");
-}
+ assert_tree_from_path(tree, "README", "README");
+ assert_tree_from_path(tree, "ab/de/fgh/1.txt", "1.txt");
+ assert_tree_from_path(tree, "ab/de/fgh", "fgh");
+ assert_tree_from_path(tree, "ab/de/fgh/", "fgh");
+ assert_tree_from_path(tree, "ab/de", "de");
+ assert_tree_from_path(tree, "ab/", "ab");
+ assert_tree_from_path(tree, "ab/de/", "de");
-void test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment(void)
-{
- assert_tree_from_path(tree, "nope/de/fgh/1.txt", GIT_ENOTFOUND, NULL);
- assert_tree_from_path(tree, "ab/me-neither/fgh/2.txt", GIT_ENOTFOUND, NULL);
+ cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "i-do-not-exist.txt"));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "README/"));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "ab/de/fgh/i-do-not-exist.txt"));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "nope/de/fgh/1.txt"));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "ab/me-neither/fgh/2.txt"));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "ab/me-neither/fgh/2.txt/"));
}
void test_object_tree_frompath__fail_when_processing_an_invalid_path(void)
{
- assert_tree_from_path_klass(tree, "/", GITERR_INVALID, NULL);
- assert_tree_from_path_klass(tree, "/ab", GITERR_INVALID, NULL);
- assert_tree_from_path_klass(tree, "/ab/de", GITERR_INVALID, NULL);
- assert_tree_from_path_klass(tree, "ab/", GITERR_INVALID, NULL);
- assert_tree_from_path_klass(tree, "ab//de", GITERR_INVALID, NULL);
- assert_tree_from_path_klass(tree, "ab/de/", GITERR_INVALID, NULL);
+ git_tree_entry *e;
+
+ cl_must_fail(git_tree_entry_bypath(&e, tree, "/"));
+ cl_must_fail(git_tree_entry_bypath(&e, tree, "/ab"));
+ cl_must_fail(git_tree_entry_bypath(&e, tree, "/ab/de"));
+ cl_must_fail(git_tree_entry_bypath(&e, tree, "ab//de"));
}