diff options
| author | Vicent Martà <tanoku@gmail.com> | 2012-01-24 20:35:15 -0800 |
|---|---|---|
| committer | Vicent Martà <tanoku@gmail.com> | 2012-01-24 20:35:15 -0800 |
| commit | 3fd1520cd4d8b4d6b6493a7d3dc393ffd9abf1db (patch) | |
| tree | 51b29f5d8ffeb31ba751ab2a099e4f2a32d4be07 /tests-clar/index | |
| parent | a9fe8ae0ee1ddcc289fad53f1a671f02a3e9a88f (diff) | |
| download | libgit2-3fd1520cd4d8b4d6b6493a7d3dc393ffd9abf1db.tar.gz | |
Rename the Clay test suite to Clar
Clay is the name of a programming language on the makings, and we want
to avoid confusions. Sorry for the huge diff!
Diffstat (limited to 'tests-clar/index')
| -rw-r--r-- | tests-clar/index/read_tree.c | 46 | ||||
| -rw-r--r-- | tests-clar/index/rename.c | 50 |
2 files changed, 96 insertions, 0 deletions
diff --git a/tests-clar/index/read_tree.c b/tests-clar/index/read_tree.c new file mode 100644 index 000000000..c657d4f71 --- /dev/null +++ b/tests-clar/index/read_tree.c @@ -0,0 +1,46 @@ +#include "clar_libgit2.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: '-' < '/' < '_' */ + cl_git_mkfile("./read_tree/abc-d", NULL); + cl_git_mkfile("./read_tree/abc/d", NULL); + cl_git_mkfile("./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)); + git_tree_free(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-clar/index/rename.c b/tests-clar/index/rename.c new file mode 100644 index 000000000..eecd257fd --- /dev/null +++ b/tests-clar/index/rename.c @@ -0,0 +1,50 @@ +#include "clar_libgit2.h" +#include "posix.h" + +void test_index_rename__single_file(void) +{ + git_repository *repo; + git_index *index; + int position; + git_oid expected; + git_index_entry *entry; + + p_mkdir("rename", 0700); + + cl_git_pass(git_repository_init(&repo, "./rename", 0)); + cl_git_pass(git_repository_index(&index, repo)); + + cl_assert(git_index_entrycount(index) == 0); + + cl_git_mkfile("./rename/lame.name.txt", "new_file\n"); + + /* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */ + cl_git_pass(git_index_add(index, "lame.name.txt", 0)); + cl_assert(git_index_entrycount(index) == 1); + + cl_git_pass(git_oid_fromstr(&expected, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a")); + + position = git_index_find(index, "lame.name.txt"); + + entry = git_index_get(index, position); + cl_assert(git_oid_cmp(&expected, &entry->oid) == 0); + + /* This removes the entry from the index, but not from the object database */ + cl_git_pass(git_index_remove(index, position)); + cl_assert(git_index_entrycount(index) == 0); + + p_rename("./rename/lame.name.txt", "./rename/fancy.name.txt"); + + cl_git_pass(git_index_add(index, "fancy.name.txt", 0)); + cl_assert(git_index_entrycount(index) == 1); + + position = git_index_find(index, "fancy.name.txt"); + + entry = git_index_get(index, position); + cl_assert(git_oid_cmp(&expected, &entry->oid) == 0); + + git_index_free(index); + git_repository_free(repo); + + cl_fixture_cleanup("rename"); +} |
