diff options
Diffstat (limited to 'tests-clay/index')
| -rw-r--r-- | tests-clay/index/read_tree.c | 46 | ||||
| -rw-r--r-- | tests-clay/index/rename.c | 11 |
2 files changed, 47 insertions, 10 deletions
diff --git a/tests-clay/index/read_tree.c b/tests-clay/index/read_tree.c new file mode 100644 index 000000000..d884c8d51 --- /dev/null +++ b/tests-clay/index/read_tree.c @@ -0,0 +1,46 @@ +#include "clay_libgit2.h" +#include "testlib.h" +#include "posix.h" + +/* Test that reading and writing a tree is a no-op */ +void test_index_read_tree__read_write_involution(void) +{ + git_repository *repo; + git_index *index; + git_oid tree_oid; + git_tree *tree; + git_oid expected; + + p_mkdir("read_tree", 0700); + + cl_git_pass(git_repository_init(&repo, "./read_tree", 0)); + cl_git_pass(git_repository_index(&index, repo)); + + cl_assert(git_index_entrycount(index) == 0); + + p_mkdir("./read_tree/abc", 0700); + + /* Sort order: '-' < '/' < '_' */ + file_create("./read_tree/abc-d", NULL); + file_create("./read_tree/abc/d", NULL); + file_create("./read_tree/abc_d", NULL); + + cl_git_pass(git_index_add(index, "abc-d", 0)); + cl_git_pass(git_index_add(index, "abc_d", 0)); + cl_git_pass(git_index_add(index, "abc/d", 0)); + + /* write-tree */ + cl_git_pass(git_tree_create_fromindex(&expected, index)); + + /* read-tree */ + git_tree_lookup(&tree, repo, &expected); + cl_git_pass(git_index_read_tree(index, tree)); + + cl_git_pass(git_tree_create_fromindex(&tree_oid, index)); + cl_assert(git_oid_cmp(&expected, &tree_oid) == 0); + + git_index_free(index); + git_repository_free(repo); + + cl_fixture_cleanup("read_tree"); +} diff --git a/tests-clay/index/rename.c b/tests-clay/index/rename.c index f81125434..c949fa7f2 100644 --- a/tests-clay/index/rename.c +++ b/tests-clay/index/rename.c @@ -1,16 +1,7 @@ #include "clay_libgit2.h" +#include "testlib.h" #include "posix.h" -static void file_create(const char *filename, const char *content) -{ - int fd; - - fd = p_creat(filename, 0666); - cl_assert(fd != 0); - cl_git_pass(p_write(fd, content, strlen(content))); - cl_git_pass(p_close(fd)); -} - void test_index_rename__single_file(void) { git_repository *repo; |
