]>
git.proxmox.com Git - libgit2.git/blob - tests/object/tree/frompath.c
86ca47e94ec18425df157b5f83972ee2103c56eb
1 #include "clar_libgit2.h"
3 static git_repository
*repo
;
6 void test_object_tree_frompath__initialize(void)
9 const char *tree_with_subtrees_oid
= "ae90f12eea699729ed24555e40b9fd669da12a12";
11 cl_git_pass(git_repository_open(&repo
, cl_fixture("testrepo.git")));
12 cl_assert(repo
!= NULL
);
14 cl_git_pass(git_oid_fromstr(&id
, tree_with_subtrees_oid
));
15 cl_git_pass(git_tree_lookup(&tree
, repo
, &id
));
16 cl_assert(tree
!= NULL
);
19 void test_object_tree_frompath__cleanup(void)
24 git_repository_free(repo
);
28 static void assert_tree_from_path(
31 const char *expected_entry_name
)
33 git_tree_entry
*entry
;
35 cl_git_pass(git_tree_entry_bypath(&entry
, root
, path
));
36 cl_assert_equal_s(git_tree_entry_name(entry
), expected_entry_name
);
37 git_tree_entry_free(entry
);
40 void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(void)
44 assert_tree_from_path(tree
, "README", "README");
45 assert_tree_from_path(tree
, "ab/de/fgh/1.txt", "1.txt");
46 assert_tree_from_path(tree
, "ab/de/fgh", "fgh");
47 assert_tree_from_path(tree
, "ab/de/fgh/", "fgh");
48 assert_tree_from_path(tree
, "ab/de", "de");
49 assert_tree_from_path(tree
, "ab/", "ab");
50 assert_tree_from_path(tree
, "ab/de/", "de");
52 cl_assert_equal_i(GIT_ENOTFOUND
, git_tree_entry_bypath(&e
, tree
, "i-do-not-exist.txt"));
53 cl_assert_equal_i(GIT_ENOTFOUND
, git_tree_entry_bypath(&e
, tree
, "README/"));
54 cl_assert_equal_i(GIT_ENOTFOUND
, git_tree_entry_bypath(&e
, tree
, "ab/de/fgh/i-do-not-exist.txt"));
55 cl_assert_equal_i(GIT_ENOTFOUND
, git_tree_entry_bypath(&e
, tree
, "nope/de/fgh/1.txt"));
56 cl_assert_equal_i(GIT_ENOTFOUND
, git_tree_entry_bypath(&e
, tree
, "ab/me-neither/fgh/2.txt"));
57 cl_assert_equal_i(GIT_ENOTFOUND
, git_tree_entry_bypath(&e
, tree
, "ab/me-neither/fgh/2.txt/"));
60 void test_object_tree_frompath__fail_when_processing_an_invalid_path(void)
64 cl_must_fail(git_tree_entry_bypath(&e
, tree
, "/"));
65 cl_must_fail(git_tree_entry_bypath(&e
, tree
, "/ab"));
66 cl_must_fail(git_tree_entry_bypath(&e
, tree
, "/ab/de"));
67 cl_must_fail(git_tree_entry_bypath(&e
, tree
, "ab//de"));