Commit 3dccfed1 by Vicent Marti

Cleanup the testing toolkit

Tests are now declared with detailed descriptions and a short test name:

	BEGIN_TEST(the_test0, "this is an example test that does something")
		...
	END_TEST

Modules are declared through a simple macro interface:

	BEGIN_MODULE(mod_name)
		ADD_TEST(the_test0);
		...
	END_MODULE

Error messages when tests fail have been greatly improved.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent 8fc05096
......@@ -27,7 +27,7 @@
#include "vector.h"
#include "fileops.h"
BEGIN_TEST("refcnt", init_inc2_dec2_free)
BEGIN_TEST(refcnt0, "increment refcount twice, decrement twice")
git_refcnt p;
gitrc_init(&p, 0);
......@@ -38,7 +38,7 @@ BEGIN_TEST("refcnt", init_inc2_dec2_free)
gitrc_free(&p);
END_TEST
BEGIN_TEST("strutil", prefix_comparison)
BEGIN_TEST(string0, "compare prefixes")
must_be_true(git__prefixcmp("", "") == 0);
must_be_true(git__prefixcmp("a", "") == 0);
must_be_true(git__prefixcmp("", "a") < 0);
......@@ -49,7 +49,7 @@ BEGIN_TEST("strutil", prefix_comparison)
must_be_true(git__prefixcmp("ab", "aa") > 0);
END_TEST
BEGIN_TEST("strutil", suffix_comparison)
BEGIN_TEST(string1, "compare suffixes")
must_be_true(git__suffixcmp("", "") == 0);
must_be_true(git__suffixcmp("a", "") == 0);
must_be_true(git__suffixcmp("", "a") < 0);
......@@ -60,7 +60,31 @@ BEGIN_TEST("strutil", suffix_comparison)
must_be_true(git__suffixcmp("zaz", "ac") > 0);
END_TEST
BEGIN_TEST("strutil", dirname)
BEGIN_TEST(vector0, "initial size of 1 would cause writing past array bounds")
git_vector x;
int i;
git_vector_init(&x, 1, NULL, NULL);
for (i = 0; i < 10; ++i) {
git_vector_insert(&x, (void*) 0xabc);
}
git_vector_free(&x);
END_TEST
BEGIN_TEST(vector1, "don't read past array bounds on remove()")
git_vector x;
// make initial capacity exact for our insertions.
git_vector_init(&x, 3, NULL, NULL);
git_vector_insert(&x, (void*) 0xabc);
git_vector_insert(&x, (void*) 0xdef);
git_vector_insert(&x, (void*) 0x123);
git_vector_remove(&x, 0); // used to read past array bounds.
git_vector_free(&x);
END_TEST
BEGIN_TEST(path0, "get the dirname of a path")
char dir[64], *dir2;
#define DIRNAME_TEST(A, B) { \
......@@ -89,7 +113,7 @@ BEGIN_TEST("strutil", dirname)
END_TEST
BEGIN_TEST("strutil", basename)
BEGIN_TEST(path1, "get the base name of a path")
char base[64], *base2;
#define BASENAME_TEST(A, B) { \
......@@ -114,7 +138,7 @@ BEGIN_TEST("strutil", basename)
END_TEST
BEGIN_TEST("strutil", topdir)
BEGIN_TEST(path2, "get the latest component in a path")
const char *dir;
#define TOPDIR_TEST(A, B) { \
......@@ -138,32 +162,6 @@ BEGIN_TEST("strutil", topdir)
#undef TOPDIR_TEST
END_TEST
/* Initial size of 1 will cause writing past array bounds prior to fix */
BEGIN_TEST("vector", initial_size_one)
git_vector x;
int i;
git_vector_init(&x, 1, NULL, NULL);
for (i = 0; i < 10; ++i) {
git_vector_insert(&x, (void*) 0xabc);
}
git_vector_free(&x);
END_TEST
/* vector used to read past array bounds on remove() */
BEGIN_TEST("vector", remove)
git_vector x;
// make initial capacity exact for our insertions.
git_vector_init(&x, 3, NULL, NULL);
git_vector_insert(&x, (void*) 0xabc);
git_vector_insert(&x, (void*) 0xdef);
git_vector_insert(&x, (void*) 0x123);
git_vector_remove(&x, 0); // used to read past array bounds.
git_vector_free(&x);
END_TEST
typedef int (normalize_path)(char *, const char *);
static int ensure_normalized(const char *input_path, const char *expected_path, normalize_path normalizer)
......@@ -194,7 +192,7 @@ static int ensure_file_path_normalized(const char *input_path, const char *expec
return ensure_normalized(input_path, expected_path, gitfo_prettify_file_path);
}
BEGIN_TEST("path", file_path_prettifying)
BEGIN_TEST(path3, "prettify and validate a path to a file")
must_pass(ensure_file_path_normalized("a", "a"));
must_pass(ensure_file_path_normalized("./testrepo.git", "testrepo.git"));
must_pass(ensure_file_path_normalized("./.git", ".git"));
......@@ -274,7 +272,7 @@ BEGIN_TEST("path", file_path_prettifying)
must_fail(ensure_file_path_normalized("/d1/.../d2", NULL));
END_TEST
BEGIN_TEST("path", dir_path_prettifying)
BEGIN_TEST(path4, "validate and prettify a path to a folder")
must_pass(ensure_dir_path_normalized("./testrepo.git", "testrepo.git/"));
must_pass(ensure_dir_path_normalized("./.git", ".git/"));
must_pass(ensure_dir_path_normalized("./git.", "git./"));
......@@ -354,7 +352,7 @@ static int ensure_joinpath(const char *path_a, const char *path_b, const char *e
return strcmp(joined_path, expected_path) == 0 ? GIT_SUCCESS : GIT_ERROR;
}
BEGIN_TEST("path", joinpath)
BEGIN_TEST(path5, "properly join path components")
must_pass(ensure_joinpath("", "", ""));
must_pass(ensure_joinpath("", "a", "a"));
must_pass(ensure_joinpath("", "/a", "/a"));
......@@ -376,7 +374,7 @@ static int ensure_joinpath_n(const char *path_a, const char *path_b, const char
return strcmp(joined_path, expected_path) == 0 ? GIT_SUCCESS : GIT_ERROR;
}
BEGIN_TEST("path", joinpath_n)
BEGIN_TEST(path6, "properly join path components for more than one path")
must_pass(ensure_joinpath_n("", "", "", "", ""));
must_pass(ensure_joinpath_n("", "a", "", "", "a/"));
must_pass(ensure_joinpath_n("a", "", "", "", "a/"));
......@@ -506,7 +504,7 @@ static walk_data dot = {
dot_names
};
BEGIN_TEST("dirent", dot)
BEGIN_TEST(dirent0, "make sure that the '.' folder is not traversed")
must_pass(setup(&dot));
......@@ -531,7 +529,7 @@ static walk_data sub = {
sub_names
};
BEGIN_TEST("dirent", sub)
BEGIN_TEST(dirent1, "traverse a subfolder")
must_pass(setup(&sub));
......@@ -550,7 +548,7 @@ static walk_data sub_slash = {
sub_names
};
BEGIN_TEST("dirent", sub_slash)
BEGIN_TEST(dirent2, "traverse a slash-terminated subfolder")
must_pass(setup(&sub_slash));
......@@ -579,7 +577,7 @@ static int dont_call_me(void *GIT_UNUSED(state), char *GIT_UNUSED(path))
return GIT_ERROR;
}
BEGIN_TEST("dirent", empty)
BEGIN_TEST(dirent3, "make sure that empty folders are not traversed")
must_pass(setup(&empty));
......@@ -612,7 +610,7 @@ static walk_data odd = {
odd_names
};
BEGIN_TEST("dirent", odd)
BEGIN_TEST(dirent4, "make sure that strange looking filenames ('..c') are traversed")
must_pass(setup(&odd));
......@@ -627,31 +625,26 @@ BEGIN_TEST("dirent", odd)
END_TEST
git_testsuite *libgit2_suite_core(void)
{
git_testsuite *suite = git_testsuite_new("Core");
ADD_TEST(suite, "refcnt", init_inc2_dec2_free);
ADD_TEST(suite, "strutil", prefix_comparison);
ADD_TEST(suite, "strutil", suffix_comparison);
ADD_TEST(suite, "strutil", dirname);
ADD_TEST(suite, "strutil", basename);
ADD_TEST(suite, "strutil", topdir);
BEGIN_SUITE(core)
ADD_TEST(refcnt0);
ADD_TEST(suite, "vector", initial_size_one);
ADD_TEST(suite, "vector", remove);
ADD_TEST(string0);
ADD_TEST(string1);
ADD_TEST(suite, "path", file_path_prettifying);
ADD_TEST(suite, "path", dir_path_prettifying);
ADD_TEST(suite, "path", joinpath);
ADD_TEST(suite, "path", joinpath_n);
ADD_TEST(vector0);
ADD_TEST(vector1);
ADD_TEST(suite, "dirent", dot);
ADD_TEST(suite, "dirent", sub);
ADD_TEST(suite, "dirent", sub_slash);
ADD_TEST(suite, "dirent", empty);
ADD_TEST(suite, "dirent", odd);
ADD_TEST(path0);
ADD_TEST(path1);
ADD_TEST(path2);
ADD_TEST(path3);
ADD_TEST(path4);
ADD_TEST(path5);
ADD_TEST(path6);
return suite;
}
ADD_TEST(dirent0);
ADD_TEST(dirent1);
ADD_TEST(dirent2);
ADD_TEST(dirent3);
ADD_TEST(dirent4);
END_SUITE
......@@ -23,25 +23,6 @@ static object_data one = {
};
BEGIN_TEST("existsloose", exists_loose_one)
git_odb *db;
git_oid id, id2;
must_pass(write_object_files(odb_dir, &one));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, one.id));
must_be_true(git_odb_exists(db, &id));
/* Test for a non-existant object */
must_pass(git_oid_mkstr(&id2, "8b137891791fe96927ad78e64b0aad7bded08baa"));
must_be_true(0 == git_odb_exists(db, &id2));
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &one));
END_TEST
/* commit == 3d7f8a6af076c8c3f20071a8935cdbe8228594d1 */
static unsigned char commit_bytes[] = {
0x78, 0x01, 0x85, 0x50, 0xc1, 0x6a, 0xc3, 0x30,
......
......@@ -28,7 +28,26 @@
#include "t02-data.h"
#include "t02-oids.h"
BEGIN_TEST("readloose", read_loose_commit)
BEGIN_TEST(existsloose0, "check if a loose object exists on the odb")
git_odb *db;
git_oid id, id2;
must_pass(write_object_files(odb_dir, &one));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, one.id));
must_be_true(git_odb_exists(db, &id));
/* Test for a non-existant object */
must_pass(git_oid_mkstr(&id2, "8b137891791fe96927ad78e64b0aad7bded08baa"));
must_be_true(0 == git_odb_exists(db, &id2));
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &one));
END_TEST
BEGIN_TEST(readloose0, "read a loose commit")
git_odb *db;
git_oid id;
git_rawobj obj;
......@@ -45,7 +64,7 @@ BEGIN_TEST("readloose", read_loose_commit)
must_pass(remove_object_files(odb_dir, &commit));
END_TEST
BEGIN_TEST("readloose", read_loose_tree)
BEGIN_TEST(readloose1, "read a loose tree")
git_odb *db;
git_oid id;
git_rawobj obj;
......@@ -62,7 +81,7 @@ BEGIN_TEST("readloose", read_loose_tree)
must_pass(remove_object_files(odb_dir, &tree));
END_TEST
BEGIN_TEST("readloose", read_loose_tag)
BEGIN_TEST(readloose2, "read a loose tag")
git_odb *db;
git_oid id;
git_rawobj obj;
......@@ -79,7 +98,7 @@ BEGIN_TEST("readloose", read_loose_tag)
must_pass(remove_object_files(odb_dir, &tag));
END_TEST
BEGIN_TEST("readloose", read_loose_zero)
BEGIN_TEST(readloose3, "read a loose zero-bytes object")
git_odb *db;
git_oid id;
git_rawobj obj;
......@@ -96,7 +115,7 @@ BEGIN_TEST("readloose", read_loose_zero)
must_pass(remove_object_files(odb_dir, &zero));
END_TEST
BEGIN_TEST("readloose", read_loose_one)
BEGIN_TEST(readloose4, "read a one-byte long loose object")
git_odb *db;
git_oid id;
git_rawobj obj;
......@@ -113,7 +132,7 @@ BEGIN_TEST("readloose", read_loose_one)
must_pass(remove_object_files(odb_dir, &one));
END_TEST
BEGIN_TEST("readloose", read_loose_two)
BEGIN_TEST(readloose5, "read a two-bytes long loose object")
git_odb *db;
git_oid id;
git_rawobj obj;
......@@ -130,7 +149,7 @@ BEGIN_TEST("readloose", read_loose_two)
must_pass(remove_object_files(odb_dir, &two));
END_TEST
BEGIN_TEST("readloose", read_loose_some)
BEGIN_TEST(readloose6, "read a loose object which is several bytes long")
git_odb *db;
git_oid id;
git_rawobj obj;
......@@ -147,7 +166,7 @@ BEGIN_TEST("readloose", read_loose_some)
must_pass(remove_object_files(odb_dir, &some));
END_TEST
BEGIN_TEST("readpack", readpacked_test)
BEGIN_TEST(readpack0, "read several packed objects")
unsigned int i;
git_odb *db;
......@@ -167,7 +186,7 @@ BEGIN_TEST("readpack", readpacked_test)
git_odb_close(db);
END_TEST
BEGIN_TEST("readheader", readheader_packed_test)
BEGIN_TEST(readheader0, "read only the header of several packed objects")
unsigned int i;
git_odb *db;
......@@ -191,7 +210,7 @@ BEGIN_TEST("readheader", readheader_packed_test)
git_odb_close(db);
END_TEST
BEGIN_TEST("readheader", readheader_loose_test)
BEGIN_TEST(readheader1, "read only the header of several loose objects")
unsigned int i;
git_odb *db;
......@@ -217,36 +236,29 @@ BEGIN_TEST("readheader", readheader_loose_test)
git_odb_close(db);
END_TEST
git_testsuite *libgit2_suite_objread(void)
{
git_testsuite *suite = git_testsuite_new("Object Read");
ADD_TEST(suite, "existsloose", exists_loose_one);
BEGIN_SUITE(objread)
ADD_TEST(existsloose0);
ADD_TEST(suite, "readloose", read_loose_commit);
ADD_TEST(suite, "readloose", read_loose_tree);
ADD_TEST(suite, "readloose", read_loose_tag);
ADD_TEST(suite, "readloose", read_loose_zero);
ADD_TEST(suite, "readloose", read_loose_one);
ADD_TEST(suite, "readloose", read_loose_two);
ADD_TEST(suite, "readloose", read_loose_some);
ADD_TEST(readloose0);
ADD_TEST(readloose1);
ADD_TEST(readloose2);
ADD_TEST(readloose3);
ADD_TEST(readloose4);
ADD_TEST(readloose5);
ADD_TEST(readloose6);
/* TODO: import these (naming conflicts) */
/*
ADD_TEST(suite, "readloose", read_loose_commit_enc);
ADD_TEST(suite, "readloose", read_loose_tree_enc);
ADD_TEST(suite, "readloose", read_loose_tag_enc);
ADD_TEST(suite, "readloose", read_loose_zero_enc);
ADD_TEST(suite, "readloose", read_loose_one_enc);
ADD_TEST(suite, "readloose", read_loose_two_enc);
ADD_TEST(suite, "readloose", read_loose_some_enc);
ADD_TEST(readloose_enc0);
ADD_TEST(readloose_enc1);
ADD_TEST(readloose_enc2);
ADD_TEST(readloose_enc3);
ADD_TEST(readloose_enc4);
ADD_TEST(readloose_enc5);
ADD_TEST(readloose_enc6);
*/
ADD_TEST(suite, "readpack", readpacked_test);
ADD_TEST(suite, "readheader", readheader_packed_test);
ADD_TEST(suite, "readheader", readheader_loose_test);
ADD_TEST(readpack0);
return suite;
}
ADD_TEST(readheader0);
ADD_TEST(readheader1);
END_SUITE
......@@ -80,7 +80,7 @@ static int remove_object_files(object_data *d)
return 0;
}
BEGIN_TEST("write", write_commit)
BEGIN_TEST(write0, "write loose commit object")
git_odb *db;
git_oid id1, id2;
git_rawobj obj;
......@@ -101,7 +101,7 @@ BEGIN_TEST("write", write_commit)
must_pass(remove_object_files(&commit));
END_TEST
BEGIN_TEST("write", write_tree)
BEGIN_TEST(write1, "write loose tree object")
git_odb *db;
git_oid id1, id2;
git_rawobj obj;
......@@ -122,7 +122,7 @@ BEGIN_TEST("write", write_tree)
must_pass(remove_object_files(&tree));
END_TEST
BEGIN_TEST("write", write_tag)
BEGIN_TEST(write2, "write loose tag object")
git_odb *db;
git_oid id1, id2;
git_rawobj obj;
......@@ -143,7 +143,7 @@ BEGIN_TEST("write", write_tag)
must_pass(remove_object_files(&tag));
END_TEST
BEGIN_TEST("write", write_zero)
BEGIN_TEST(write3, "write zero-length object")
git_odb *db;
git_oid id1, id2;
git_rawobj obj;
......@@ -164,7 +164,7 @@ BEGIN_TEST("write", write_zero)
must_pass(remove_object_files(&zero));
END_TEST
BEGIN_TEST("write", write_one)
BEGIN_TEST(write4, "write one-byte long object")
git_odb *db;
git_oid id1, id2;
git_rawobj obj;
......@@ -185,7 +185,7 @@ BEGIN_TEST("write", write_one)
must_pass(remove_object_files(&one));
END_TEST
BEGIN_TEST("write", write_two)
BEGIN_TEST(write5, "write two-byte long object")
git_odb *db;
git_oid id1, id2;
git_rawobj obj;
......@@ -206,7 +206,7 @@ BEGIN_TEST("write", write_two)
must_pass(remove_object_files(&two));
END_TEST
BEGIN_TEST("write", write_some)
BEGIN_TEST(write6, "write an object which is several bytes long")
git_odb *db;
git_oid id1, id2;
git_rawobj obj;
......@@ -227,18 +227,12 @@ BEGIN_TEST("write", write_some)
must_pass(remove_object_files(&some));
END_TEST
git_testsuite *libgit2_suite_objwrite(void)
{
git_testsuite *suite = git_testsuite_new("Object Write");
ADD_TEST(suite, "write", write_commit);
ADD_TEST(suite, "write", write_tree);
ADD_TEST(suite, "write", write_tag);
ADD_TEST(suite, "write", write_zero);
ADD_TEST(suite, "write", write_one);
ADD_TEST(suite, "write", write_two);
ADD_TEST(suite, "write", write_some);
return suite;
}
BEGIN_SUITE(objwrite)
ADD_TEST(write0);
ADD_TEST(write1);
ADD_TEST(write2);
ADD_TEST(write3);
ADD_TEST(write4);
ADD_TEST(write5);
ADD_TEST(write6);
END_SUITE
......@@ -109,7 +109,7 @@ committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
a simple commit which works\n",
};
BEGIN_TEST("parse", parse_oid_test)
BEGIN_TEST(parse0, "parse the OID line in a commit")
git_oid oid;
......@@ -151,7 +151,7 @@ BEGIN_TEST("parse", parse_oid_test)
END_TEST
BEGIN_TEST("parse", parse_sig_test)
BEGIN_TEST(parse1, "parse the signature line in a commit")
#define TEST_SIGNATURE_PASS(_string, _header, _name, _email, _time, _offset) { \
char *ptr = _string; \
......@@ -285,7 +285,7 @@ END_TEST
/* External declaration for testing the buffer parsing method */
int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int parse_flags);
BEGIN_TEST("parse", parse_buffer_test)
BEGIN_TEST(parse2, "parse a whole commit buffer")
const int broken_commit_count = sizeof(test_commits_broken) / sizeof(*test_commits_broken);
const int working_commit_count = sizeof(test_commits_working) / sizeof(*test_commits_working);
......@@ -352,7 +352,7 @@ static const char *commit_ids[] = {
"5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
};
BEGIN_TEST("details", query_details_test)
BEGIN_TEST(details0, "query the details on a parsed commit")
const size_t commit_count = sizeof(commit_ids) / sizeof(const char *);
unsigned int i;
......@@ -407,7 +407,7 @@ This is a commit created in memory and it will be written back to disk\n"
static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
BEGIN_TEST("write", writenew_test)
BEGIN_TEST(write0, "write a new commit object from memory to disk")
git_repository *repo;
git_commit *commit, *parent;
git_tree *tree;
......@@ -474,7 +474,7 @@ BEGIN_TEST("write", writenew_test)
git_repository_free(repo);
END_TEST
BEGIN_TEST("write", writeback_test)
BEGIN_TEST(write1, "load a commit object, modify it and write it back")
git_repository *repo;
git_oid id;
git_commit *commit, *parent;
......@@ -504,16 +504,11 @@ BEGIN_TEST("write", writeback_test)
END_TEST
git_testsuite *libgit2_suite_commit(void)
{
git_testsuite *suite = git_testsuite_new("Commit");
ADD_TEST(suite, "parse", parse_oid_test);
ADD_TEST(suite, "parse", parse_sig_test);
ADD_TEST(suite, "parse", parse_buffer_test);
ADD_TEST(suite, "details", query_details_test);
ADD_TEST(suite, "write", writenew_test);
ADD_TEST(suite, "write", writeback_test);
return suite;
}
BEGIN_SUITE(commit)
ADD_TEST(parse0);
ADD_TEST(parse1);
ADD_TEST(parse2);
ADD_TEST(details0);
ADD_TEST(write0);
ADD_TEST(write1);
END_SUITE
......@@ -110,7 +110,7 @@ static int test_walk(git_revwalk *walk, git_commit *start_from,
return GIT_ERROR;
}
BEGIN_TEST("walk", simple_walk_test)
BEGIN_TEST(walk0, "do a simple walk on a repo with different sorting modes")
git_oid id;
git_repository *repo;
git_revwalk *walk;
......@@ -145,7 +145,7 @@ BEGIN_TEST("walk", simple_walk_test)
git_repository_free(repo);
END_TEST
BEGIN_TEST("list", list_timesort_test)
BEGIN_TEST(list0, "check that a commit list is properly sorted by time")
git_revwalk_list list;
git_revwalk_listnode *n;
......@@ -210,12 +210,7 @@ BEGIN_TEST("list", list_timesort_test)
END_TEST
git_testsuite *libgit2_suite_revwalk(void)
{
git_testsuite *suite = git_testsuite_new("Revwalk");
ADD_TEST(suite, "walk", simple_walk_test);
ADD_TEST(suite, "list", list_timesort_test);
return suite;
}
BEGIN_SUITE(revwalk)
ADD_TEST(walk0);
ADD_TEST(list0);
END_SUITE
......@@ -45,7 +45,7 @@ struct test_entry TEST_ENTRIES[] = {
{48, "src/revobject.h", 1448, 0x4C3F7FE2}
};
BEGIN_TEST("read", index_loadempty_test)
BEGIN_TEST(read0, "load an empty index")
git_index *index;
must_pass(git_index_open_bare(&index, "in-memory-index"));
......@@ -60,7 +60,7 @@ BEGIN_TEST("read", index_loadempty_test)
git_index_free(index);
END_TEST
BEGIN_TEST("read", index_load_test)
BEGIN_TEST(read1, "load a standard index (default test index)")
git_index *index;
unsigned int i;
git_index_entry **entries;
......@@ -87,7 +87,7 @@ BEGIN_TEST("read", index_load_test)
git_index_free(index);
END_TEST
BEGIN_TEST("read", index2_load_test)
BEGIN_TEST(read2, "load a standard index (git.git index)")
git_index *index;
must_pass(git_index_open_bare(&index, TEST_INDEX2_PATH));
......@@ -103,7 +103,7 @@ BEGIN_TEST("read", index2_load_test)
git_index_free(index);
END_TEST
BEGIN_TEST("read", index_find_test)
BEGIN_TEST(find0, "find an entry on an index")
git_index *index;
unsigned int i;
......@@ -118,7 +118,7 @@ BEGIN_TEST("read", index_find_test)
git_index_free(index);
END_TEST
BEGIN_TEST("read", index_findempty_test)
BEGIN_TEST(find1, "find an entry in an empty index")
git_index *index;
unsigned int i;
......@@ -132,7 +132,7 @@ BEGIN_TEST("read", index_findempty_test)
git_index_free(index);
END_TEST
BEGIN_TEST("write", index_write_test)
BEGIN_TEST(write0, "write an index back to disk")
git_index *index;
must_pass(copy_file(TEST_INDEXBIG_PATH, "index_rewrite"));
......@@ -149,7 +149,7 @@ BEGIN_TEST("write", index_write_test)
gitfo_unlink("index_rewrite");
END_TEST
BEGIN_TEST("sort", index_sort_test)
BEGIN_TEST(sort0, "sort the entires in an index")
/*
* TODO: This no longer applies:
* index sorting in Git uses some specific changes to the way
......@@ -162,7 +162,7 @@ BEGIN_TEST("sort", index_sort_test)
END_TEST
BEGIN_TEST("sort", index_sort_empty_test)
BEGIN_TEST(sort1, "sort the entires in an empty index")
git_index *index;
must_pass(git_index_open_bare(&index, "fake-index"));
......@@ -173,19 +173,16 @@ BEGIN_TEST("sort", index_sort_empty_test)
git_index_free(index);
END_TEST
BEGIN_SUITE(index)
ADD_TEST(read0);
ADD_TEST(read1);
ADD_TEST(read2);
git_testsuite *libgit2_suite_index(void)
{
git_testsuite *suite = git_testsuite_new("Index");
ADD_TEST(find0);
ADD_TEST(find1);
ADD_TEST(suite, "read", index_loadempty_test);
ADD_TEST(suite, "read", index_load_test);
ADD_TEST(suite, "read", index2_load_test);
ADD_TEST(suite, "read", index_find_test);
ADD_TEST(suite, "read", index_findempty_test);
ADD_TEST(suite, "write", index_write_test);
ADD_TEST(suite, "sort", index_sort_test);
ADD_TEST(suite, "sort", index_sort_empty_test);
ADD_TEST(write0);
return suite;
}
ADD_TEST(sort0);
ADD_TEST(sort1);
END_SUITE
......@@ -49,7 +49,7 @@ int hash_cmpkey(const void *a, const void *b)
return git_oid_cmp(a, b);
}
BEGIN_TEST("table", table_create)
BEGIN_TEST(table0, "create a new hashtable")
git_hashtable *table = NULL;
......@@ -61,7 +61,7 @@ BEGIN_TEST("table", table_create)
END_TEST
BEGIN_TEST("table", table_populate)
BEGIN_TEST(table1, "fill the hashtable with random entries")
const int objects_n = 32;
int i;
......@@ -109,7 +109,7 @@ BEGIN_TEST("table", table_populate)
END_TEST
BEGIN_TEST("table", table_resize)
BEGIN_TEST(table2, "make sure the table resizes automatically")
const int objects_n = 64;
int i;
......@@ -150,7 +150,7 @@ BEGIN_TEST("table", table_resize)
END_TEST
BEGIN_TEST("tableit", table_iterator)
BEGIN_TEST(tableit0, "iterate through all the contents of the table")
const int objects_n = 32;
int i;
......@@ -184,14 +184,10 @@ BEGIN_TEST("tableit", table_iterator)
END_TEST
git_testsuite *libgit2_suite_hashtable(void)
{
git_testsuite *suite = git_testsuite_new("Hashtable");
ADD_TEST(suite, "table", table_create);
ADD_TEST(suite, "table", table_populate);
ADD_TEST(suite, "table", table_resize);
ADD_TEST(suite, "tableit", table_iterator);
BEGIN_SUITE(hashtable)
ADD_TEST(table0);
ADD_TEST(table1);
ADD_TEST(table2);
ADD_TEST(tableit0);
END_SUITE
return suite;
}
......@@ -31,7 +31,7 @@ static const char *tag1_id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1";
static const char *tag2_id = "7b4384978d2493e851f9cca7858815fac9b10980";
static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
BEGIN_TEST("readtag", readtag)
BEGIN_TEST(read0, "read and parse a tag from the repository")
git_repository *repo;
git_tag *tag1, *tag2;
git_commit *commit;
......@@ -61,7 +61,7 @@ BEGIN_TEST("readtag", readtag)
git_repository_free(repo);
END_TEST
BEGIN_TEST("write", tag_writeback_test)
BEGIN_TEST(write0, "write back a tag to the repository")
git_oid id;
git_repository *repo;
git_tag *tag;
......@@ -81,12 +81,7 @@ BEGIN_TEST("write", tag_writeback_test)
END_TEST
git_testsuite *libgit2_suite_tag(void)
{
git_testsuite *suite = git_testsuite_new("Tag");
ADD_TEST(suite, "readtag", readtag);
ADD_TEST(suite, "write", tag_writeback_test);
return suite;
}
BEGIN_SUITE(tag)
ADD_TEST(read0);
ADD_TEST(write0);
END_SUITE
......@@ -29,7 +29,7 @@
static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
BEGIN_TEST("readtree", tree_entry_access_test)
BEGIN_TEST(read0, "acces randomly the entries on a loaded tree")
git_oid id;
git_repository *repo;
git_tree *tree;
......@@ -51,7 +51,7 @@ BEGIN_TEST("readtree", tree_entry_access_test)
git_repository_free(repo);
END_TEST
BEGIN_TEST("readtree", tree_read_test)
BEGIN_TEST(read1, "read a tree from the repository")
git_oid id;
git_repository *repo;
git_tree *tree;
......@@ -76,7 +76,7 @@ BEGIN_TEST("readtree", tree_read_test)
git_repository_free(repo);
END_TEST
BEGIN_TEST("modify", tree_in_memory_add_test)
BEGIN_TEST(write0, "add a new entry to a tree and write it back to disk")
const unsigned int entry_count = 128;
git_repository *repo;
......@@ -106,7 +106,7 @@ BEGIN_TEST("modify", tree_in_memory_add_test)
git_repository_free(repo);
END_TEST
BEGIN_TEST("modify", tree_add_entry_test)
BEGIN_TEST(write1, "add several entries in-memory and validate that they exist; write back to disk")
git_oid id;
git_repository *repo;
git_tree *tree;
......@@ -157,14 +157,10 @@ BEGIN_TEST("modify", tree_add_entry_test)
END_TEST
git_testsuite *libgit2_suite_tree(void)
{
git_testsuite *suite = git_testsuite_new("Tree");
BEGIN_SUITE(tree)
ADD_TEST(read0);
ADD_TEST(read1);
ADD_TEST(write0);
ADD_TEST(write1);
END_SUITE
ADD_TEST(suite, "readtree", tree_entry_access_test);
ADD_TEST(suite, "readtree", tree_read_test);
ADD_TEST(suite, "modify", tree_in_memory_add_test);
ADD_TEST(suite, "modify", tree_add_entry_test);
return suite;
}
......@@ -75,49 +75,43 @@ static git_odb *open_sqlite_odb(void)
git_odb_close(db); \
}
BEGIN_TEST("sqlite", sql_write_commit)
BEGIN_TEST(sqlite0, "write a commit, read it back (sqlite backend)")
TEST_WRITE(commit);
END_TEST
BEGIN_TEST("sqlite", sql_write_tree)
BEGIN_TEST(sqlite1, "write a tree, read it back (sqlite backend)")
TEST_WRITE(tree);
END_TEST
BEGIN_TEST("sqlite", sql_write_tag)
BEGIN_TEST(sqlite2, "write a tag, read it back (sqlite backend)")
TEST_WRITE(tag);
END_TEST
BEGIN_TEST("sqlite", sql_write_zero)
BEGIN_TEST(sqlite3, "write a zero-byte entry, read it back (sqlite backend)")
TEST_WRITE(zero);
END_TEST
BEGIN_TEST("sqlite", sql_write_one)
BEGIN_TEST(sqlite4, "write a one-byte entry, read it back (sqlite backend)")
TEST_WRITE(one);
END_TEST
BEGIN_TEST("sqlite", sql_write_two)
BEGIN_TEST(sqlite5, "write a two-byte entry, read it back (sqlite backend)")
TEST_WRITE(two);
END_TEST
BEGIN_TEST("sqlite", sql_write_some)
BEGIN_TEST(sqlite6, "write some bytes in an entry, read it back (sqlite backend)")
TEST_WRITE(some);
END_TEST
git_testsuite *libgit2_suite_sqlite(void)
{
git_testsuite *suite = git_testsuite_new("SQLite Backend");
BEGIN_SUITE(sqlite)
#ifdef GIT2_SQLITE_BACKEND
ADD_TEST(suite, "sqlite", sql_write_commit);
ADD_TEST(suite, "sqlite", sql_write_tree);
ADD_TEST(suite, "sqlite", sql_write_tag);
ADD_TEST(suite, "sqlite", sql_write_zero);
ADD_TEST(suite, "sqlite", sql_write_one);
ADD_TEST(suite, "sqlite", sql_write_two);
ADD_TEST(suite, "sqlite", sql_write_some);
ADD_TEST(sqlite0);
ADD_TEST(sqlite1);
ADD_TEST(sqlite2);
ADD_TEST(sqlite3);
ADD_TEST(sqlite4);
ADD_TEST(sqlite5);
ADD_TEST(sqlite6);
#endif
return suite;
}
END_SUITE
......@@ -64,7 +64,7 @@ int test_backend_sorting(git_odb *odb)
return GIT_SUCCESS;
}
BEGIN_TEST("odb", backend_sorting)
BEGIN_TEST(odb0, "assure that ODB backends are properly sorted")
git_odb *odb;
must_pass(git_odb_new(&odb));
must_pass(git_odb_add_backend(odb, new_backend(0), 5));
......@@ -75,7 +75,7 @@ BEGIN_TEST("odb", backend_sorting)
git_odb_close(odb);
END_TEST
BEGIN_TEST("odb", backend_alternates_sorting)
BEGIN_TEST(odb1, "assure that alternate backends are properly sorted")
git_odb *odb;
must_pass(git_odb_new(&odb));
must_pass(git_odb_add_backend(odb, new_backend(0), 5));
......@@ -94,52 +94,70 @@ END_TEST
#define STANDARD_REPOSITORY 0
#define BARE_REPOSITORY 1
static void ensure_repository_init(git_test *_gittest, char *working_directory, int repository_kind, char *expected_path_index, char *expected_path_repository, char *expected_working_directory)
static int ensure_repository_init(
const char *working_directory,
int repository_kind,
const char *expected_path_index,
const char *expected_path_repository,
const char *expected_working_directory)
{
char path_odb[GIT_PATH_MAX];
git_repository *repo;
must_be_true(gitfo_isdir(working_directory));
if (gitfo_isdir(working_directory) == GIT_SUCCESS)
return GIT_ERROR;
git__joinpath(path_odb, expected_path_repository, GIT_OBJECTS_DIR);
must_pass(git_repository_init(&repo, working_directory, repository_kind));
must_be_true((repo->path_workdir == NULL && expected_working_directory == NULL) || !strcmp(repo->path_workdir, expected_working_directory));
must_be_true(!strcmp(repo->path_odb, path_odb));
must_be_true(!strcmp(repo->path_repository, expected_path_repository));
must_be_true((repo->path_index == NULL && expected_path_index == NULL) || !strcmp(repo->path_index, expected_path_index));
if (git_repository_init(&repo, working_directory, repository_kind) < GIT_SUCCESS)
return GIT_ERROR;
if (repo->path_workdir != NULL || expected_working_directory != NULL) {
if (strcmp(repo->path_workdir, expected_working_directory) != 0)
return GIT_ERROR;
}
if (strcmp(repo->path_odb, path_odb) != 0)
return GIT_ERROR;
if (strcmp(repo->path_repository, expected_path_repository) != 0)
return GIT_ERROR;
if (repo->path_index != NULL || expected_path_index != NULL) {
if (strcmp(repo->path_index, expected_path_index) != 0)
return GIT_ERROR;
}
git_repository_free(repo);
must_pass(rmdir_recurs(working_directory));
rmdir_recurs(working_directory);
return GIT_SUCCESS;
}
BEGIN_TEST("repo_initialization", init_standard_repo)
BEGIN_TEST(init0, "initialize a standard repo")
char path_index[GIT_PATH_MAX], path_repository[GIT_PATH_MAX];
git__joinpath(path_repository, TEMP_DIR, GIT_DIR);
git__joinpath(path_repository, TEMP_REPO_FOLDER, GIT_DIR);
git__joinpath(path_index, path_repository, GIT_INDEX_FILE);
ensure_repository_init(_gittest, TEMP_DIR, STANDARD_REPOSITORY, path_index, path_repository, TEMP_DIR);
ensure_repository_init(_gittest, TEMP_DIR_WITHOUT_TRAILING_SLASH, STANDARD_REPOSITORY, path_index, path_repository, TEMP_DIR);
ensure_repository_init(TEMP_REPO_FOLDER, STANDARD_REPOSITORY, path_index, path_repository, TEMP_REPO_FOLDER);
ensure_repository_init(TEMP_REPO_FOLDER_NS, STANDARD_REPOSITORY, path_index, path_repository, TEMP_REPO_FOLDER);
END_TEST
BEGIN_TEST("repo_initialization", init_bare_repo)
BEGIN_TEST(init1, "initialize a bare repo")
char path_repository[GIT_PATH_MAX];
git__joinpath(path_repository, TEMP_DIR, "");
git__joinpath(path_repository, TEMP_REPO_FOLDER, "");
ensure_repository_init(_gittest, TEMP_DIR, BARE_REPOSITORY, NULL, path_repository, NULL);
ensure_repository_init(_gittest, TEMP_DIR_WITHOUT_TRAILING_SLASH, BARE_REPOSITORY, NULL, path_repository, NULL);
ensure_repository_init(TEMP_REPO_FOLDER, BARE_REPOSITORY, NULL, path_repository, NULL);
ensure_repository_init(TEMP_REPO_FOLDER_NS, BARE_REPOSITORY, NULL, path_repository, NULL);
END_TEST
git_testsuite *libgit2_suite_repository(void)
{
git_testsuite *suite = git_testsuite_new("Repository");
ADD_TEST(suite, "odb", backend_sorting);
ADD_TEST(suite, "odb", backend_alternates_sorting);
ADD_TEST(suite, "repo_initialization", init_standard_repo);
ADD_TEST(suite, "repo_initialization", init_bare_repo);
BEGIN_SUITE(repository)
ADD_TEST(odb0);
ADD_TEST(odb1);
ADD_TEST(init0);
ADD_TEST(init1);
END_SUITE
return suite;
}
......@@ -197,7 +197,7 @@ static int remove_filesystem_element_recurs(void *GIT_UNUSED(nil), char *path)
return gitfo_unlink(path);
}
int rmdir_recurs(char *directory_path)
int rmdir_recurs(const char *directory_path)
{
char buffer[GIT_PATH_MAX];
strcpy(buffer, directory_path);
......@@ -227,7 +227,7 @@ static int copy_filesystem_element_recurs(void *_data, char *source)
return copy_file(source, data->dst);
}
int copydir_recurs(char *source_directory_path, char *destination_directory_path)
int copydir_recurs(const char *source_directory_path, const char *destination_directory_path)
{
char source_buffer[GIT_PATH_MAX];
char dest_buffer[GIT_PATH_MAX];
......@@ -246,3 +246,18 @@ int copydir_recurs(char *source_directory_path, char *destination_directory_path
return copy_filesystem_element_recurs(&data, source_buffer);
}
int open_temp_repo(git_repository **repo, const char *path)
{
int error;
if ((error = copydir_recurs(path, TEMP_REPO_FOLDER)) < GIT_SUCCESS)
return error;
return git_repository_open(repo, TEMP_REPO_FOLDER);
}
void close_temp_repo(git_repository *repo)
{
git_repository_free(repo);
rmdir_recurs(TEMP_REPO_FOLDER);
}
......@@ -36,8 +36,9 @@
#define TEST_INDEX2_PATH (TEST_RESOURCES "/gitgit.index")
#define TEST_INDEXBIG_PATH (TEST_RESOURCES "/big.index")
#define TEMP_DIR_WITHOUT_TRAILING_SLASH TEST_RESOURCES "/temp_working"
#define TEMP_DIR TEMP_DIR_WITHOUT_TRAILING_SLASH "/"
#define TEMP_FOLDER "./"
#define TEMP_REPO_FOLDER TEMP_FOLDER TEST_REPOSITORY_NAME "/"
#define TEMP_REPO_FOLDER_NS TEMP_FOLDER TEST_REPOSITORY_NAME
typedef struct object_data {
unsigned char *bytes; /* (compressed) bytes stored in object store */
......@@ -62,8 +63,11 @@ extern int remove_loose_object(const char *odb_dir, git_object *object);
extern int cmp_files(const char *a, const char *b);
extern int copy_file(const char *source, const char *dest);
extern int rmdir_recurs(char *directory_path);
extern int copydir_recurs(char *source_directory_path, char *destination_directory_path);
extern int rmdir_recurs(const char *directory_path);
extern int copydir_recurs(const char *source_directory_path, const char *destination_directory_path);
extern int open_temp_repo(git_repository **repo, const char *path);
extern void close_temp_repo(git_repository *repo);
#endif
/* INCLUDE_test_helpers_h__ */
......@@ -12,10 +12,12 @@
struct git_test {
char *name;
char *message;
char *failed_pos;
char *description;
git_testfunc function;
int failed;
int ran;
const char *message;
unsigned failed:1, ran:1;
jmp_buf *jump;
};
......@@ -25,25 +27,18 @@ struct git_testsuite {
git_test *list[GIT_MAX_TEST_CASES];
};
static void test_init(git_test *t, const char *name, git_testfunc function)
{
t->name = strdup(name);
t->failed = 0;
t->ran = 0;
t->message = NULL;
t->function = function;
t->jump = NULL;
}
static void test_free(git_test *t)
{
if (t) {
free(t->name);
free(t->description);
free(t->failed_pos);
free(t->message);
free(t);
}
}
void test_run(git_test *tc)
static void test_run(git_test *tc)
{
jmp_buf buf;
tc->jump = &buf;
......@@ -56,11 +51,26 @@ void test_run(git_test *tc)
tc->jump = 0;
}
git_test *git_test_new(const char *name, git_testfunc function)
static git_test *create_test(git_testfunc function)
{
git_test *tc = DO_ALLOC(git_test);
test_init(tc, name, function);
return tc;
git_test *t = DO_ALLOC(git_test);
t->name = NULL;
t->failed = 0;
t->ran = 0;
t->description = NULL;
t->message = NULL;
t->failed_pos = NULL;
t->function = function;
t->jump = NULL;
return t;
}
void git_test__init(git_test *t, const char *name, const char *description)
{
t->name = strdup(name);
t->description = strdup(description);
}
......@@ -72,10 +82,11 @@ static void fail_test(git_test *tc, const char *file, int line, const char *mess
{
char buf[1024];
snprintf(buf, 1024, "%s @ %s:%d", message, file, line);
snprintf(buf, 1024, "%s:%d", file, line);
tc->failed = 1;
tc->message = strdup(buf);
tc->message = strdup(message);
tc->failed_pos = strdup(buf);
if (tc->jump != 0)
longjmp(*(tc->jump), 0);
......@@ -111,7 +122,7 @@ git_testsuite *git_testsuite_new(const char *name)
return ts;
}
void git_testsuite_free(git_testsuite *ts)
static void free_suite(git_testsuite *ts)
{
unsigned int n;
......@@ -122,20 +133,12 @@ void git_testsuite_free(git_testsuite *ts)
free(ts);
}
void git_testsuite_add(git_testsuite *ts, git_test *tc)
void git_testsuite_add(git_testsuite *ts, git_testfunc test)
{
assert(ts->count < GIT_MAX_TEST_CASES);
ts->list[ts->count++] = tc;
ts->list[ts->count++] = create_test(test);
}
void git_testsuite_addsuite(git_testsuite *ts, git_testsuite *ts2)
{
int i;
for (i = 0 ; i < ts2->count ; ++i)
git_testsuite_add(ts, ts2->list[i]);
}
static void print_details(git_testsuite *ts)
{
int i;
......@@ -151,7 +154,8 @@ static void print_details(git_testsuite *ts)
git_test *tc = ts->list[i];
if (tc->failed) {
failCount++;
printf(" %d) %s: %s\n", failCount, tc->name, tc->message);
printf(" %d) \"%s\" [test %s @ %s]\n\t%s\n",
failCount, tc->description, tc->name, tc->failed_pos, tc->message);
}
}
}
......@@ -159,7 +163,7 @@ static void print_details(git_testsuite *ts)
int git_testsuite_run(git_testsuite *ts)
{
int i;
int i, fail_count;
printf("Suite \"%s\": ", ts->name);
......@@ -175,7 +179,9 @@ int git_testsuite_run(git_testsuite *ts)
}
printf("\n ");
print_details(ts);
fail_count = ts->fail_count;
return ts->fail_count;
free_suite(ts);
return fail_count;
}
......@@ -9,13 +9,23 @@
#include "common.h"
#include <git2.h>
#define ADD_TEST(SUITE, MODULE, TEST) \
git_testsuite_add(SUITE, git_test_new(MODULE "::" #TEST, &_gittest__##TEST))
#define BEGIN_TEST(MODULE, TEST) \
void _gittest__##TEST(git_test *_gittest) \
{ \
assert(_gittest);\
#define DECLARE_SUITE(SNAME) extern git_testsuite *libgit2_suite_##SNAME(void)
#define SUITE_NAME(SNAME) libgit2_suite_##SNAME
#define BEGIN_SUITE(SNAME) \
git_testsuite *libgit2_suite_##SNAME(void) {\
git_testsuite *_gitsuite = git_testsuite_new(#SNAME);
#define ADD_TEST(TNAME) \
git_testsuite_add(_gitsuite, _gittest__##TNAME);
#define END_SUITE \
return _gitsuite;\
}
#define BEGIN_TEST(TNAME, DESC) \
static void _gittest__##TNAME(git_test *_gittest) { \
git_test__init(_gittest, #TNAME, DESC); \
{\
#define END_TEST }}
......@@ -23,21 +33,18 @@
typedef struct git_test git_test;
typedef struct git_testsuite git_testsuite;
typedef void (*git_testfunc)(git_test *);
typedef git_testsuite *(*libgit2_suite)(void);
void git_test__init(git_test *t, const char *name, const char *description);
void git_test__fail(git_test *tc, const char *file, int line, const char *message);
void git_test__assert(git_test *tc, const char *file, int line, const char *message, int condition);
#define must_pass(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Method failed, " #expr, (expr) == 0)
#define must_fail(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Expected method to fail, " #expr, (expr) < 0)
#define must_be_true(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Expected " #expr, !!(expr))
#define must_pass(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Method failed: " #expr, (expr) == 0)
#define must_fail(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Expected method to fail: " #expr, (expr) < 0)
#define must_be_true(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Expression is not true: " #expr, !!(expr))
git_testsuite *git_testsuite_new(const char *name);
git_test *git_test_new(const char *name, git_testfunc function);
void git_testsuite_free(git_testsuite *ts);
void git_testsuite_add(git_testsuite *ts, git_test *tc);
void git_testsuite_addsuite(git_testsuite* ts, git_testsuite *ts2);
void git_testsuite_add(git_testsuite *ts, git_testfunc test);
int git_testsuite_run(git_testsuite *ts);
#endif
......
......@@ -29,81 +29,49 @@
#include "test_lib.h"
#include "test_helpers.h"
extern git_testsuite *libgit2_suite_core(void);
extern git_testsuite *libgit2_suite_rawobjects(void);
extern git_testsuite *libgit2_suite_objread(void);
extern git_testsuite *libgit2_suite_objwrite(void);
extern git_testsuite *libgit2_suite_commit(void);
extern git_testsuite *libgit2_suite_revwalk(void);
extern git_testsuite *libgit2_suite_index(void);
extern git_testsuite *libgit2_suite_hashtable(void);
extern git_testsuite *libgit2_suite_tag(void);
extern git_testsuite *libgit2_suite_tree(void);
extern git_testsuite *libgit2_suite_refs(void);
extern git_testsuite *libgit2_suite_sqlite(void);
extern git_testsuite *libgit2_suite_repository(void);
typedef git_testsuite *(*libgit2_suite)(void);
DECLARE_SUITE(core);
DECLARE_SUITE(rawobjects);
DECLARE_SUITE(objread);
DECLARE_SUITE(objwrite);
DECLARE_SUITE(commit);
DECLARE_SUITE(revwalk);
DECLARE_SUITE(index);
DECLARE_SUITE(hashtable);
DECLARE_SUITE(tag);
DECLARE_SUITE(tree);
DECLARE_SUITE(refs);
DECLARE_SUITE(sqlite);
DECLARE_SUITE(repository);
static libgit2_suite suite_methods[]= {
libgit2_suite_core,
libgit2_suite_rawobjects,
libgit2_suite_objread,
libgit2_suite_objwrite,
libgit2_suite_commit,
libgit2_suite_revwalk,
libgit2_suite_index,
libgit2_suite_hashtable,
libgit2_suite_tag,
libgit2_suite_tree,
libgit2_suite_refs,
libgit2_suite_sqlite,
libgit2_suite_repository,
SUITE_NAME(core),
SUITE_NAME(rawobjects),
SUITE_NAME(objread),
SUITE_NAME(objwrite),
SUITE_NAME(commit),
SUITE_NAME(revwalk),
SUITE_NAME(index),
SUITE_NAME(hashtable),
SUITE_NAME(tag),
SUITE_NAME(tree),
SUITE_NAME(refs),
SUITE_NAME(sqlite),
SUITE_NAME(repository),
};
#define GIT_SUITE_COUNT (ARRAY_SIZE(suite_methods))
git_testsuite **libgit2_get_suites()
{
git_testsuite **suites;
unsigned int i;
suites = git__malloc(GIT_SUITE_COUNT * sizeof(void *));
if (suites == NULL)
return NULL;
for (i = 0; i < GIT_SUITE_COUNT; ++i)
suites[i] = suite_methods[i]();
return suites;
}
void libgit2_free_suites(git_testsuite **suites)
{
unsigned int i;
for (i = 0; i < GIT_SUITE_COUNT; ++i)
git_testsuite_free(suites[i]);
free(suites);
}
int main(int GIT_UNUSED(argc), char *GIT_UNUSED(argv[]))
{
unsigned int i, failures;
git_testsuite **suites;
GIT_UNUSED_ARG(argc);
GIT_UNUSED_ARG(argv);
suites = libgit2_get_suites();
failures = 0;
for (i = 0; i < GIT_SUITE_COUNT; ++i)
failures += git_testsuite_run(suites[i]);
libgit2_free_suites(suites);
failures += git_testsuite_run(suite_methods[i]());
return failures ? -1 : 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment