diff options
author | Carlos Martín Nieto <cmn@elego.de> | 2011-05-05 16:22:06 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@elego.de> | 2011-05-05 16:22:06 +0200 |
commit | ca8d2dfc0cea0c16e2d6bae16d95d652e292f473 (patch) | |
tree | f98e0c362a388f9a9efe644ac3e38828f5f14807 /tests | |
parent | 094aaaaee92f4fc98a6c3c3af36183cb217948a8 (diff) | |
parent | cc3b82e376e0216c1af4ad46d24327d61e9efd99 (diff) | |
download | libgit2-ca8d2dfc0cea0c16e2d6bae16d95d652e292f473.tar.gz |
Merge remote-tracking branch 'upstream/development' into config
Diffstat (limited to 'tests')
-rw-r--r-- | tests/t04-commit.c | 79 | ||||
-rw-r--r-- | tests/t07-hashtable.c | 2 | ||||
-rw-r--r-- | tests/t08-tag.c | 14 | ||||
-rw-r--r-- | tests/t09-tree.c | 48 | ||||
-rw-r--r-- | tests/t10-refs.c | 50 | ||||
-rwxr-xr-x | tests/test_lib.c | 1 |
6 files changed, 165 insertions, 29 deletions
diff --git a/tests/t04-commit.c b/tests/t04-commit.c index bcc0417c8..36f3e66b5 100644 --- a/tests/t04-commit.c +++ b/tests/t04-commit.c @@ -368,7 +368,7 @@ BEGIN_TEST(details0, "query the details on a parsed commit") const char *message, *message_short; git_time_t commit_time; unsigned int parents, p; - git_commit *parent; + git_commit *parent = NULL, *old_parent = NULL; git_oid_mkstr(&id, commit_ids[i]); @@ -390,11 +390,19 @@ BEGIN_TEST(details0, "query the details on a parsed commit") must_be_true(commit_time > 0); must_be_true(parents <= 2); for (p = 0;p < parents;p++) { + if (old_parent != NULL) + git_commit_close(old_parent); + + old_parent = parent; must_pass(git_commit_parent(&parent, commit, p)); must_be_true(parent != NULL); must_be_true(git_commit_author(parent) != NULL); // is it really a commit? } + git_commit_close(old_parent); + git_commit_close(parent); + must_fail(git_commit_parent(&parent, commit, parents)); + git_commit_close(commit); } git_repository_free(repo); @@ -462,9 +470,76 @@ BEGIN_TEST(write0, "write a new commit object from memory to disk") must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit)); + git_commit_close(commit); git_repository_free(repo); END_TEST +#define ROOT_COMMIT_MESSAGE "This is a root commit\n\ +This is a root commit and should be the only one in this branch\n" + +BEGIN_TEST(root0, "create a root commit") + git_repository *repo; + git_commit *commit; + git_oid tree_id, commit_id; + const git_oid *branch_oid; + const git_signature *author, *committer; + const char *branch_name = "refs/heads/root-commit-branch"; + git_reference *head, *branch; + char *head_old; + + must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); + + git_oid_mkstr(&tree_id, tree_oid); + + /* create signatures */ + committer = git_signature_new(COMMITTER_NAME, COMMITTER_EMAIL, 123456789, 60); + must_be_true(committer != NULL); + + author = git_signature_new(COMMITTER_NAME, COMMITTER_EMAIL, 987654321, 90); + must_be_true(author != NULL); + + /* First we need to update HEAD so it points to our non-existant branch */ + must_pass(git_reference_lookup(&head, repo, "HEAD")); + must_be_true(git_reference_type(head) == GIT_REF_SYMBOLIC); + head_old = git__strdup(git_reference_target(head)); + must_be_true(head_old != NULL); + + must_pass(git_reference_set_target(head, branch_name)); + + must_pass(git_commit_create_v( + &commit_id, /* out id */ + repo, + "HEAD", + author, + committer, + ROOT_COMMIT_MESSAGE, + &tree_id, + 0)); + + git_signature_free((git_signature *)committer); + git_signature_free((git_signature *)author); + + /* + * The fact that creating a commit works has already been + * tested. Here we just make sure it's our commit and that it was + * written as a root commit. + */ + must_pass(git_commit_lookup(&commit, repo, &commit_id)); + must_be_true(git_commit_parentcount(commit) == 0); + must_pass(git_reference_lookup(&branch, repo, branch_name)); + branch_oid = git_reference_oid(branch); + must_pass(git_oid_cmp(branch_oid, &commit_id)); + must_be_true(!strcmp(git_commit_message(commit), ROOT_COMMIT_MESSAGE)); + + /* Remove the data we just added to the repo */ + must_pass(git_reference_lookup(&head, repo, "HEAD")); + must_pass(git_reference_set_target(head, head_old)); + must_pass(git_reference_delete(branch)); + must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit)); + free(head_old); + git_commit_close(commit); + git_repository_free(repo); +END_TEST BEGIN_SUITE(commit) ADD_TEST(parse0); @@ -474,4 +549,6 @@ BEGIN_SUITE(commit) ADD_TEST(write0); //ADD_TEST(write1); + + ADD_TEST(root0); END_SUITE diff --git a/tests/t07-hashtable.c b/tests/t07-hashtable.c index 597136965..0b362cafd 100644 --- a/tests/t07-hashtable.c +++ b/tests/t07-hashtable.c @@ -155,7 +155,7 @@ BEGIN_TEST(tableit0, "iterate through all the contents of the table") const int objects_n = 32; int i; table_item *objects, *ob; - const void *_unused; + const void *GIT_UNUSED(_unused); git_hashtable *table = NULL; diff --git a/tests/t08-tag.c b/tests/t08-tag.c index de67fdd93..fae2e99db 100644 --- a/tests/t08-tag.c +++ b/tests/t08-tag.c @@ -64,6 +64,19 @@ BEGIN_TEST(read0, "read and parse a tag from the repository") git_repository_free(repo); END_TEST +BEGIN_TEST(read1, "list all tag names from the repository") + git_repository *repo; + git_strarray tag_list; + + must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); + must_pass(git_tag_list(&tag_list, repo)); + + must_be_true(tag_list.count == 3); + + git_strarray_free(&tag_list); + git_repository_free(repo); +END_TEST + #define TAGGER_NAME "Vicent Marti" #define TAGGER_EMAIL "vicent@github.com" @@ -227,6 +240,7 @@ END_TEST BEGIN_SUITE(tag) ADD_TEST(read0); + ADD_TEST(read1); ADD_TEST(write0); ADD_TEST(write1); ADD_TEST(write2); diff --git a/tests/t09-tree.c b/tests/t09-tree.c index bd88642fa..af992fdb3 100644 --- a/tests/t09-tree.c +++ b/tests/t09-tree.c @@ -32,6 +32,7 @@ static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd"; static const char *blob_oid = "fa49b077972391ad58037050f2a75f74e3671e92"; static const char *first_tree = "181037049a54a1eb5fab404658a3a250b44335d7"; static const char *second_tree = "f60079018b664e4e79329a7ef9559c8d9e0378d1"; +static const char *third_tree = "eb86d8b81d6adbd5290a935d6c9976882de98488"; #if 0 static int print_tree(git_repository *repo, const git_oid *tree_oid, int depth) @@ -82,6 +83,7 @@ BEGIN_TEST(read0, "acces randomly the entries on a loaded tree") must_be_true(git_tree_entry_byindex(tree, 3) == NULL); must_be_true(git_tree_entry_byindex(tree, -1) == NULL); + git_tree_close(tree); git_repository_free(repo); END_TEST @@ -102,7 +104,9 @@ BEGIN_TEST(read1, "read a tree from the repository") /* GH-86: git_object_lookup() should also check the type if the object comes from the cache */ must_be_true(git_object_lookup(&obj, repo, &id, GIT_OBJ_TREE) == 0); + git_object_close(obj); must_be_true(git_object_lookup(&obj, repo, &id, GIT_OBJ_BLOB) == GIT_EINVALIDTYPE); + git_object_close(obj); entry = git_tree_entry_byname(tree, "README"); must_be_true(entry != NULL); @@ -111,6 +115,8 @@ BEGIN_TEST(read1, "read a tree from the repository") must_pass(git_tree_entry_2object(&obj, repo, entry)); + git_object_close(obj); + git_tree_close(tree); git_repository_free(repo); END_TEST @@ -148,9 +154,50 @@ BEGIN_TEST(write2, "write a tree from a memory") must_pass(git_treebuilder_write(&rid,repo,builder)); must_be_true(git_oid_cmp(&rid, &id2) == 0); + + git_treebuilder_free(builder); + git_tree_close(tree); close_temp_repo(repo); END_TEST +BEGIN_TEST(write3, "write a hierarchical tree from a memory") + git_repository *repo; + git_treebuilder *builder; + git_tree *tree; + git_oid id, bid, subtree_id, id2, id3; + git_oid id_hiearar; + + must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); + git_oid_mkstr(&id, first_tree); + git_oid_mkstr(&id2, second_tree); + git_oid_mkstr(&id3, third_tree); + git_oid_mkstr(&bid, blob_oid); + + //create subtree + must_pass(git_treebuilder_create(&builder, NULL)); + must_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644)); + must_pass(git_treebuilder_write(&subtree_id,repo,builder)); + git_treebuilder_free(builder); + + // create parent tree + must_pass(git_tree_lookup(&tree, repo, &id)); + must_pass(git_treebuilder_create(&builder, tree)); + must_pass(git_treebuilder_insert(NULL,builder,"new",&subtree_id,040000)); + must_pass(git_treebuilder_write(&id_hiearar,repo,builder)); + git_treebuilder_free(builder); + git_tree_close(tree); + + must_be_true(git_oid_cmp(&id_hiearar, &id3) == 0); + + // check data is correct + must_pass(git_tree_lookup(&tree, repo, &id_hiearar)); + must_be_true(2 == git_tree_entrycount(tree)); + git_tree_close(tree); + + close_temp_repo(repo); + +END_TEST + BEGIN_SUITE(tree) //ADD_TEST(print0); ADD_TEST(read0); @@ -158,5 +205,6 @@ BEGIN_SUITE(tree) //ADD_TEST(write0); //ADD_TEST(write1); ADD_TEST(write2); + ADD_TEST(write3); END_SUITE diff --git a/tests/t10-refs.c b/tests/t10-refs.c index a6a560193..db767a107 100644 --- a/tests/t10-refs.c +++ b/tests/t10-refs.c @@ -51,6 +51,7 @@ BEGIN_TEST(readtag0, "lookup a loose tag reference") git__joinpath(ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object)); must_be_true(strcmp(ref_name_from_tag_name, loose_tag_ref_name) == 0); + git_object_close(object); git_repository_free(repo); END_TEST @@ -91,6 +92,7 @@ BEGIN_TEST(readsym0, "lookup a symbolic reference") git_oid_mkstr(&id, current_master_tip); must_be_true(git_oid_cmp(&id, git_object_id(object)) == 0); + git_object_close(object); git_repository_free(repo); END_TEST @@ -117,6 +119,7 @@ BEGIN_TEST(readsym1, "lookup a nested symbolic reference") git_oid_mkstr(&id, current_master_tip); must_be_true(git_oid_cmp(&id, git_object_id(object)) == 0); + git_object_close(object); git_repository_free(repo); END_TEST @@ -175,6 +178,7 @@ BEGIN_TEST(readpacked0, "lookup a packed reference") must_be_true(object != NULL); must_be_true(git_object_type(object) == GIT_OBJ_COMMIT); + git_object_close(object); git_repository_free(repo); END_TEST @@ -194,7 +198,7 @@ END_TEST BEGIN_TEST(create0, "create a new symbolic reference") git_reference *new_reference, *looked_up_ref, *resolved_ref; - git_repository *repo; + git_repository *repo, *repo2; git_oid id; char ref_path[GIT_PATH_MAX]; @@ -202,7 +206,7 @@ BEGIN_TEST(create0, "create a new symbolic reference") git_oid_mkstr(&id, current_master_tip); - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); + must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); /* Retrieve the physical path to the symbolic ref for further cleaning */ git__joinpath(ref_path, repo->path_repository, new_head_tracker); @@ -226,14 +230,13 @@ BEGIN_TEST(create0, "create a new symbolic reference") git_repository_free(repo); /* Similar test with a fresh new repository */ - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); + must_pass(git_repository_open(&repo2, TEMP_REPO_FOLDER)); - must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker)); + must_pass(git_reference_lookup(&looked_up_ref, repo2, new_head_tracker)); must_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); must_be_true(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0); - git_reference_delete(looked_up_ref); - git_repository_free(repo); + close_temp_repo(repo2); END_TEST BEGIN_TEST(create1, "create a deep symbolic reference") @@ -246,7 +249,7 @@ BEGIN_TEST(create1, "create a deep symbolic reference") git_oid_mkstr(&id, current_master_tip); - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); + must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); git__joinpath(ref_path, repo->path_repository, new_head_tracker); must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target)); @@ -254,13 +257,12 @@ BEGIN_TEST(create1, "create a deep symbolic reference") must_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); must_be_true(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0); - git_reference_delete(looked_up_ref); - git_repository_free(repo); + close_temp_repo(repo); END_TEST BEGIN_TEST(create2, "create a new OID reference") git_reference *new_reference, *looked_up_ref; - git_repository *repo; + git_repository *repo, *repo2; git_oid id; char ref_path[GIT_PATH_MAX]; @@ -268,7 +270,7 @@ BEGIN_TEST(create2, "create a new OID reference") git_oid_mkstr(&id, current_master_tip); - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); + must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); /* Retrieve the physical path to the symbolic ref for further cleaning */ git__joinpath(ref_path, repo->path_repository, new_head); @@ -288,13 +290,12 @@ BEGIN_TEST(create2, "create a new OID reference") git_repository_free(repo); /* Similar test with a fresh new repository */ - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); + must_pass(git_repository_open(&repo2, TEMP_REPO_FOLDER)); must_pass(git_reference_lookup(&looked_up_ref, repo, new_head)); must_be_true(git_oid_cmp(&id, git_reference_oid(looked_up_ref)) == 0); - git_reference_delete(looked_up_ref); - git_repository_free(repo); + close_temp_repo(repo2); END_TEST BEGIN_TEST(create3, "Can not create a new OID reference which targets at an unknown id") @@ -325,7 +326,7 @@ BEGIN_TEST(overwrite0, "Overwrite an existing symbolic reference") git_reference *ref, *branch_ref; git_repository *repo; - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); + must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); /* The target needds to exist and we need to check the name has changed */ must_pass(git_reference_create_symbolic(&branch_ref, repo, ref_branch_name, ref_master_name)); @@ -344,9 +345,7 @@ BEGIN_TEST(overwrite0, "Overwrite an existing symbolic reference") must_be_true(git_reference_type(ref) & GIT_REF_SYMBOLIC); must_be_true(!strcmp(git_reference_target(ref), ref_master_name)); - must_pass(git_reference_delete(ref)); - must_pass(git_reference_delete(branch_ref)); - git_repository_free(repo); + close_temp_repo(repo); END_TEST BEGIN_TEST(overwrite1, "Overwrite an existing object id reference") @@ -354,7 +353,7 @@ BEGIN_TEST(overwrite1, "Overwrite an existing object id reference") git_repository *repo; git_oid id; - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); + must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&ref, repo, ref_master_name)); must_be_true(ref->type & GIT_REF_OID); @@ -375,8 +374,7 @@ BEGIN_TEST(overwrite1, "Overwrite an existing object id reference") must_pass(git_reference_lookup(&ref, repo, ref_name)); must_be_true(!git_oid_cmp(&id, git_reference_oid(ref))); - git_reference_delete(ref); - git_repository_free(repo); + close_temp_repo(repo); END_TEST BEGIN_TEST(overwrite2, "Overwrite an existing object id reference with a symbolic one") @@ -384,7 +382,7 @@ BEGIN_TEST(overwrite2, "Overwrite an existing object id reference with a symboli git_repository *repo; git_oid id; - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); + must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&ref, repo, ref_master_name)); must_be_true(ref->type & GIT_REF_OID); @@ -399,8 +397,7 @@ BEGIN_TEST(overwrite2, "Overwrite an existing object id reference with a symboli must_be_true(git_reference_type(ref) & GIT_REF_SYMBOLIC); must_be_true(!strcmp(git_reference_target(ref), ref_master_name)); - git_reference_delete(ref); - git_repository_free(repo); + close_temp_repo(repo); END_TEST BEGIN_TEST(overwrite3, "Overwrite an existing symbolic reference with an object id one") @@ -408,7 +405,7 @@ BEGIN_TEST(overwrite3, "Overwrite an existing symbolic reference with an object git_repository *repo; git_oid id; - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); + must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&ref, repo, ref_master_name)); must_be_true(ref->type & GIT_REF_OID); @@ -425,8 +422,7 @@ BEGIN_TEST(overwrite3, "Overwrite an existing symbolic reference with an object must_be_true(git_reference_type(ref) & GIT_REF_OID); must_be_true(!git_oid_cmp(git_reference_oid(ref), &id)); - git_reference_delete(ref); - git_repository_free(repo); + close_temp_repo(repo); END_TEST BEGIN_TEST(pack0, "create a packfile for an empty folder") diff --git a/tests/test_lib.c b/tests/test_lib.c index c9c6141c6..5778404c1 100755 --- a/tests/test_lib.c +++ b/tests/test_lib.c @@ -130,6 +130,7 @@ static void free_suite(git_testsuite *ts) if (ts->list[n]) test_free(ts->list[n]); + free(ts->name); free(ts); } |