summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-03-03 18:19:05 +0200
committerVicent Marti <tanoku@gmail.com>2011-03-03 20:23:52 +0200
commit3dccfed16382c64370dd0fd88668c9d9accae6ed (patch)
tree21406b78ecda452244d9ceb64e5ac9ea8337ffd9 /tests
parent8fc050961c6f5d3bc8f2bc27799922bebae4b743 (diff)
downloadlibgit2-3dccfed16382c64370dd0fd88668c9d9accae6ed.tar.gz
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/t00-core.c123
-rw-r--r--tests/t01-rawobj.c137
-rw-r--r--tests/t02-data.h19
-rw-r--r--tests/t02-objread.c86
-rw-r--r--tests/t03-objwrite.c38
-rw-r--r--tests/t04-commit.c33
-rw-r--r--tests/t05-revwalk.c17
-rw-r--r--tests/t06-index.c39
-rw-r--r--tests/t07-hashtable.c24
-rw-r--r--tests/t08-tag.c17
-rw-r--r--tests/t09-tree.c24
-rw-r--r--tests/t10-refs.c415
-rw-r--r--tests/t11-sqlite.c38
-rw-r--r--tests/t12-repo.c72
-rw-r--r--tests/test_helpers.c19
-rw-r--r--tests/test_helpers.h12
-rwxr-xr-xtests/test_lib.c74
-rwxr-xr-xtests/test_lib.h39
-rw-r--r--tests/test_main.c86
19 files changed, 622 insertions, 690 deletions
diff --git a/tests/t00-core.c b/tests/t00-core.c
index ad1f34b94..3c1b6219a 100644
--- a/tests/t00-core.c
+++ b/tests/t00-core.c
@@ -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
diff --git a/tests/t01-rawobj.c b/tests/t01-rawobj.c
index 51a794214..cc4641589 100644
--- a/tests/t01-rawobj.c
+++ b/tests/t01-rawobj.c
@@ -27,7 +27,7 @@
#include "hash.h"
-BEGIN_TEST("oid", oid_szs)
+BEGIN_TEST(oid0, "validate size of oid objects")
git_oid out;
must_be_true(20 == GIT_OID_RAWSZ);
must_be_true(40 == GIT_OID_HEXSZ);
@@ -35,12 +35,12 @@ BEGIN_TEST("oid", oid_szs)
must_be_true(sizeof(out.id) == GIT_OID_RAWSZ);
END_TEST
-BEGIN_TEST("oid", empty_string)
+BEGIN_TEST(oid1, "fail when parsing an empty string as oid")
git_oid out;
must_fail(git_oid_mkstr(&out, ""));
END_TEST
-BEGIN_TEST("oid", invalid_string_moo)
+BEGIN_TEST(oid2, "fail when parsing an invalid string as oid")
git_oid out;
must_fail(git_oid_mkstr(&out, "moo"));
END_TEST
@@ -56,7 +56,7 @@ static int from_hex(unsigned int i)
return -1;
}
-BEGIN_TEST("oid", invalid_string_all_chars)
+BEGIN_TEST(oid3, "find all invalid characters when parsing an oid")
git_oid out;
unsigned char exp[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
@@ -80,12 +80,12 @@ BEGIN_TEST("oid", invalid_string_all_chars)
}
END_TEST
-BEGIN_TEST("oid", invalid_string_16a67770b7d8d72317c4b775213c23a8bd74f5ez)
+BEGIN_TEST(oid4, "fail when parsing an invalid oid string")
git_oid out;
must_fail(git_oid_mkstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5ez"));
END_TEST
-BEGIN_TEST("oid", valid_string_16a67770b7d8d72317c4b775213c23a8bd74f5e0)
+BEGIN_TEST(oid5, "succeed when parsing a valid oid string")
git_oid out;
unsigned char exp[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
@@ -101,7 +101,7 @@ BEGIN_TEST("oid", valid_string_16a67770b7d8d72317c4b775213c23a8bd74f5e0)
must_pass(memcmp(out.id, exp, sizeof(out.id)));
END_TEST
-BEGIN_TEST("oid", valid_raw)
+BEGIN_TEST(oid6, "build a valid oid from raw bytes")
git_oid out;
unsigned char exp[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
@@ -114,7 +114,7 @@ BEGIN_TEST("oid", valid_raw)
must_pass(memcmp(out.id, exp, sizeof(out.id)));
END_TEST
-BEGIN_TEST("oid", copy_oid)
+BEGIN_TEST(oid7, "properly copy an oid to another")
git_oid a, b;
unsigned char exp[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
@@ -129,7 +129,7 @@ BEGIN_TEST("oid", copy_oid)
must_pass(memcmp(a.id, exp, sizeof(a.id)));
END_TEST
-BEGIN_TEST("oid", cmp_oid_lt)
+BEGIN_TEST(oid8, "compare two oids (lesser than)")
git_oid a, b;
unsigned char a_in[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
@@ -149,7 +149,7 @@ BEGIN_TEST("oid", cmp_oid_lt)
must_be_true(git_oid_cmp(&a, &b) < 0);
END_TEST
-BEGIN_TEST("oid", cmp_oid_eq)
+BEGIN_TEST(oid9, "compare two oids (equal)")
git_oid a, b;
unsigned char a_in[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
@@ -163,7 +163,7 @@ BEGIN_TEST("oid", cmp_oid_eq)
must_be_true(git_oid_cmp(&a, &b) == 0);
END_TEST
-BEGIN_TEST("oid", cmp_oid_gt)
+BEGIN_TEST(oid10, "compare two oids (greater than)")
git_oid a, b;
unsigned char a_in[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
@@ -183,7 +183,7 @@ BEGIN_TEST("oid", cmp_oid_gt)
must_be_true(git_oid_cmp(&a, &b) > 0);
END_TEST
-BEGIN_TEST("oid", cmp_oid_fmt)
+BEGIN_TEST(oid11, "compare formated oids")
const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char out[GIT_OID_HEXSZ + 1];
@@ -200,7 +200,7 @@ BEGIN_TEST("oid", cmp_oid_fmt)
must_pass(strcmp(exp, out));
END_TEST
-BEGIN_TEST("oid", cmp_oid_allocfmt)
+BEGIN_TEST(oid12, "compare oids (allocate + format)")
const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char *out;
@@ -213,7 +213,7 @@ BEGIN_TEST("oid", cmp_oid_allocfmt)
free(out);
END_TEST
-BEGIN_TEST("oid", cmp_oid_pathfmt)
+BEGIN_TEST(oid13, "compare oids (path format)")
const char *exp1 = "16a0123456789abcdef4b775213c23a8bd74f5e0";
const char *exp2 = "16/a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
@@ -231,7 +231,7 @@ BEGIN_TEST("oid", cmp_oid_pathfmt)
must_pass(strcmp(exp2, out));
END_TEST
-BEGIN_TEST("oid", oid_to_string)
+BEGIN_TEST(oid14, "convert raw oid to string")
const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char out[GIT_OID_HEXSZ + 1];
@@ -275,7 +275,7 @@ BEGIN_TEST("oid", oid_to_string)
must_pass(strcmp(exp, out));
END_TEST
-BEGIN_TEST("oid", oid_to_string_big)
+BEGIN_TEST(oid15, "convert raw oid to string (big)")
const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char big[GIT_OID_HEXSZ + 1 + 3]; /* note + 4 => big buffer */
@@ -306,7 +306,7 @@ static char *hello_text = "hello world\n";
static char *bye_id = "ce08fe4884650f067bd5703b6a59a8b3b3c99a09";
static char *bye_text = "bye world\n";
-BEGIN_TEST("hash", hash_iuf)
+BEGIN_TEST(hash0, "normal hash by blocks")
git_hash_ctx *ctx;
git_oid id1, id2;
@@ -328,7 +328,7 @@ BEGIN_TEST("hash", hash_iuf)
git_hash_free_ctx(ctx);
END_TEST
-BEGIN_TEST("hash", hash_buf)
+BEGIN_TEST(hash1, "hash whole buffer in a single call")
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, hello_id));
@@ -338,7 +338,7 @@ BEGIN_TEST("hash", hash_buf)
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
-BEGIN_TEST("hash", hash_vec)
+BEGIN_TEST(hash2, "hash a vector")
git_oid id1, id2;
git_buf_vec vec[2];
@@ -354,7 +354,7 @@ BEGIN_TEST("hash", hash_vec)
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
-BEGIN_TEST("objtype", type_to_string)
+BEGIN_TEST(objtype0, "convert type to string")
must_be_true(!strcmp(git_object_type2string(GIT_OBJ_BAD), ""));
must_be_true(!strcmp(git_object_type2string(GIT_OBJ__EXT1), ""));
must_be_true(!strcmp(git_object_type2string(GIT_OBJ_COMMIT), "commit"));
@@ -370,7 +370,7 @@ BEGIN_TEST("objtype", type_to_string)
must_be_true(!strcmp(git_object_type2string(1234), ""));
END_TEST
-BEGIN_TEST("objtype", string_to_type)
+BEGIN_TEST(objtype1, "convert string to type")
must_be_true(git_object_string2type(NULL) == GIT_OBJ_BAD);
must_be_true(git_object_string2type("") == GIT_OBJ_BAD);
must_be_true(git_object_string2type("commit") == GIT_OBJ_COMMIT);
@@ -384,7 +384,7 @@ BEGIN_TEST("objtype", string_to_type)
must_be_true(git_object_string2type("hohoho") == GIT_OBJ_BAD);
END_TEST
-BEGIN_TEST("objtype", loose_object)
+BEGIN_TEST(objtype2, "check if an object type is loose")
must_be_true(git_object_typeisloose(GIT_OBJ_BAD) == 0);
must_be_true(git_object_typeisloose(GIT_OBJ__EXT1) == 0);
must_be_true(git_object_typeisloose(GIT_OBJ_COMMIT) == 1);
@@ -400,7 +400,7 @@ BEGIN_TEST("objtype", loose_object)
must_be_true(git_object_typeisloose(1234) == 0);
END_TEST
-BEGIN_TEST("objhash", hash_junk)
+BEGIN_TEST(objhash0, "hash junk data")
git_oid id, id_zero;
must_pass(git_oid_mkstr(&id_zero, zero_id));
@@ -431,7 +431,7 @@ BEGIN_TEST("objhash", hash_junk)
must_fail(git_rawobj_hash(&id, &junk_obj));
END_TEST
-BEGIN_TEST("objhash", hash_commit)
+BEGIN_TEST(objhash1, "hash a commit object")
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, commit_id));
@@ -441,7 +441,7 @@ BEGIN_TEST("objhash", hash_commit)
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
-BEGIN_TEST("objhash", hash_tree)
+BEGIN_TEST(objhash2, "hash a tree object")
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, tree_id));
@@ -451,7 +451,7 @@ BEGIN_TEST("objhash", hash_tree)
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
-BEGIN_TEST("objhash", hash_tag)
+BEGIN_TEST(objhash3, "hash a tag object")
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, tag_id));
@@ -461,7 +461,7 @@ BEGIN_TEST("objhash", hash_tag)
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
-BEGIN_TEST("objhash", hash_zero)
+BEGIN_TEST(objhash4, "hash a zero-length object")
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, zero_id));
@@ -471,7 +471,7 @@ BEGIN_TEST("objhash", hash_zero)
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
-BEGIN_TEST("objhash", hash_one)
+BEGIN_TEST(objhash5, "hash an one-byte long object")
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, one_id));
@@ -481,7 +481,7 @@ BEGIN_TEST("objhash", hash_one)
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
-BEGIN_TEST("objhash", hash_two)
+BEGIN_TEST(objhash6, "hash a two-byte long object")
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, two_id));
@@ -491,7 +491,7 @@ BEGIN_TEST("objhash", hash_two)
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
-BEGIN_TEST("objhash", hash_some)
+BEGIN_TEST(objhash7, "hash an object several bytes long")
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, some_id));
@@ -501,46 +501,39 @@ BEGIN_TEST("objhash", hash_some)
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
-
-git_testsuite *libgit2_suite_rawobjects(void)
-{
- git_testsuite *suite = git_testsuite_new("Raw Objects");
-
- ADD_TEST(suite, "hash", hash_iuf);
- ADD_TEST(suite, "hash", hash_buf);
- ADD_TEST(suite, "hash", hash_vec);
-
- ADD_TEST(suite, "oid", oid_szs);
- ADD_TEST(suite, "oid", empty_string);
- ADD_TEST(suite, "oid", invalid_string_moo);
- ADD_TEST(suite, "oid", invalid_string_all_chars);
- ADD_TEST(suite, "oid", invalid_string_16a67770b7d8d72317c4b775213c23a8bd74f5ez);
- ADD_TEST(suite, "oid", valid_string_16a67770b7d8d72317c4b775213c23a8bd74f5e0);
- ADD_TEST(suite, "oid", valid_raw);
- ADD_TEST(suite, "oid", copy_oid);
- ADD_TEST(suite, "oid", cmp_oid_lt);
- ADD_TEST(suite, "oid", cmp_oid_eq);
- ADD_TEST(suite, "oid", cmp_oid_gt);
- ADD_TEST(suite, "oid", cmp_oid_fmt);
- ADD_TEST(suite, "oid", cmp_oid_allocfmt);
- ADD_TEST(suite, "oid", cmp_oid_pathfmt);
- ADD_TEST(suite, "oid", oid_to_string);
- ADD_TEST(suite, "oid", oid_to_string_big);
-
- ADD_TEST(suite, "objtype", type_to_string);
- ADD_TEST(suite, "objtype", string_to_type);
- ADD_TEST(suite, "objtype", loose_object);
-
- ADD_TEST(suite, "objhash", hash_junk);
- ADD_TEST(suite, "objhash", hash_commit);
- ADD_TEST(suite, "objhash", hash_tree);
- ADD_TEST(suite, "objhash", hash_tag);
- ADD_TEST(suite, "objhash", hash_zero);
- ADD_TEST(suite, "objhash", hash_one);
- ADD_TEST(suite, "objhash", hash_two);
- ADD_TEST(suite, "objhash", hash_some);
-
- return suite;
-}
-
+BEGIN_SUITE(rawobjects)
+ ADD_TEST(oid0);
+ ADD_TEST(oid1);
+ ADD_TEST(oid2);
+ ADD_TEST(oid3);
+ ADD_TEST(oid4);
+ ADD_TEST(oid5);
+ ADD_TEST(oid6);
+ ADD_TEST(oid7);
+ ADD_TEST(oid8);
+ ADD_TEST(oid9);
+ ADD_TEST(oid10);
+ ADD_TEST(oid11);
+ ADD_TEST(oid12);
+ ADD_TEST(oid13);
+ ADD_TEST(oid14);
+ ADD_TEST(oid15);
+
+ ADD_TEST(hash0);
+ ADD_TEST(hash1);
+ ADD_TEST(hash2);
+
+ ADD_TEST(objtype0);
+ ADD_TEST(objtype1);
+ ADD_TEST(objtype2);
+
+ ADD_TEST(objhash0);
+ ADD_TEST(objhash1);
+ ADD_TEST(objhash2);
+ ADD_TEST(objhash3);
+ ADD_TEST(objhash4);
+ ADD_TEST(objhash5);
+ ADD_TEST(objhash6);
+ ADD_TEST(objhash7);
+END_SUITE
diff --git a/tests/t02-data.h b/tests/t02-data.h
index 456be5002..705a2d7af 100644
--- a/tests/t02-data.h
+++ b/tests/t02-data.h
@@ -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,
diff --git a/tests/t02-objread.c b/tests/t02-objread.c
index 1b2e2d56b..2a9d130c4 100644
--- a/tests/t02-objread.c
+++ b/tests/t02-objread.c
@@ -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
diff --git a/tests/t03-objwrite.c b/tests/t03-objwrite.c
index 0b9232534..10c6c7f1a 100644
--- a/tests/t03-objwrite.c
+++ b/tests/t03-objwrite.c
@@ -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
diff --git a/tests/t04-commit.c b/tests/t04-commit.c
index 1e3b45c02..8e62759a8 100644
--- a/tests/t04-commit.c
+++ b/tests/t04-commit.c
@@ -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
diff --git a/tests/t05-revwalk.c b/tests/t05-revwalk.c
index 473ea3350..fd009fac1 100644
--- a/tests/t05-revwalk.c
+++ b/tests/t05-revwalk.c
@@ -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
diff --git a/tests/t06-index.c b/tests/t06-index.c
index ded237076..0c748cc8d 100644
--- a/tests/t06-index.c
+++ b/tests/t06-index.c
@@ -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
diff --git a/tests/t07-hashtable.c b/tests/t07-hashtable.c
index 76eb0d1a1..597136965 100644
--- a/tests/t07-hashtable.c
+++ b/tests/t07-hashtable.c
@@ -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;
-}
diff --git a/tests/t08-tag.c b/tests/t08-tag.c
index 1b7c5fa2b..0afdf719d 100644
--- a/tests/t08-tag.c
+++ b/tests/t08-tag.c
@@ -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
diff --git a/tests/t09-tree.c b/tests/t09-tree.c
index 8c0b5b024..cb127556b 100644
--- a/tests/t09-tree.c
+++ b/tests/t09-tree.c
@@ -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;
-}
diff --git a/tests/t10-refs.c b/tests/t10-refs.c
index 2915c7a05..225b4e0d9 100644
--- a/tests/t10-refs.c
+++ b/tests/t10-refs.c
@@ -30,7 +30,7 @@
static const char *loose_tag_ref_name = "refs/tags/test";
static const char *non_existing_tag_ref_name = "refs/tags/i-do-not-exist";
-BEGIN_TEST("readtag", loose_tag_reference_looking_up)
+BEGIN_TEST(readtag0, "lookup a loose tag reference")
git_repository *repo;
git_reference *reference;
git_object *object;
@@ -49,7 +49,7 @@ BEGIN_TEST("readtag", loose_tag_reference_looking_up)
git_repository_free(repo);
END_TEST
-BEGIN_TEST("readtag", non_existing_tag_reference_looking_up)
+BEGIN_TEST(readtag1, "lookup a loose tag reference that doesn't exist")
git_repository *repo;
git_reference *reference;
@@ -63,7 +63,7 @@ static const char *head_tracker_sym_ref_name = "head-tracker";
static const char *current_head_target = "refs/heads/master";
static const char *current_master_tip = "be3563ae3f795b2b4353bcce3a527ad0a4f7f644";
-BEGIN_TEST("readsymref", symbolic_reference_looking_up)
+BEGIN_TEST(readsym0, "lookup a symbolic reference")
git_repository *repo;
git_reference *reference, *resolved_ref;
git_object *object;
@@ -89,7 +89,7 @@ BEGIN_TEST("readsymref", symbolic_reference_looking_up)
git_repository_free(repo);
END_TEST
-BEGIN_TEST("readsymref", nested_symbolic_reference_looking_up)
+BEGIN_TEST(readsym1, "lookup a nested symbolic reference")
git_repository *repo;
git_reference *reference, *resolved_ref;
git_object *object;
@@ -115,7 +115,7 @@ BEGIN_TEST("readsymref", nested_symbolic_reference_looking_up)
git_repository_free(repo);
END_TEST
-BEGIN_TEST("readsymref", looking_up_head_then_master)
+BEGIN_TEST(readsym2, "lookup the HEAD and resolve the master branch")
git_repository *repo;
git_reference *reference, *resolved_ref, *comp_base_ref;
@@ -136,7 +136,7 @@ BEGIN_TEST("readsymref", looking_up_head_then_master)
git_repository_free(repo);
END_TEST
-BEGIN_TEST("readsymref", looking_up_master_then_head)
+BEGIN_TEST(readsym3, "lookup the master branch and then the HEAD")
git_repository *repo;
git_reference *reference, *master_ref, *resolved_ref;
@@ -154,7 +154,7 @@ END_TEST
static const char *packed_head_name = "refs/heads/packed";
static const char *packed_test_head_name = "refs/heads/packed-test";
-BEGIN_TEST("readpackedref", packed_reference_looking_up)
+BEGIN_TEST(readpacked0, "lookup a packed reference")
git_repository *repo;
git_reference *reference;
git_object *object;
@@ -173,7 +173,7 @@ BEGIN_TEST("readpackedref", packed_reference_looking_up)
git_repository_free(repo);
END_TEST
-BEGIN_TEST("readpackedref", packed_exists_but_more_recent_loose_reference_is_retrieved)
+BEGIN_TEST(readpacked1, "assure that a loose reference is looked up before a packed reference")
git_repository *repo;
git_reference *reference;
@@ -187,7 +187,7 @@ BEGIN_TEST("readpackedref", packed_exists_but_more_recent_loose_reference_is_ret
git_repository_free(repo);
END_TEST
-BEGIN_TEST("createref", create_new_symbolic_ref)
+BEGIN_TEST(create0, "create a new symbolic reference")
git_reference *new_reference, *looked_up_ref, *resolved_ref;
git_repository *repo;
git_oid id;
@@ -232,7 +232,7 @@ BEGIN_TEST("createref", create_new_symbolic_ref)
must_pass(gitfo_unlink(ref_path)); /* TODO: replace with git_reference_delete() when available */
END_TEST
-BEGIN_TEST("createref", create_deep_symbolic_ref)
+BEGIN_TEST(create1, "create a deep symbolic reference")
git_reference *new_reference, *looked_up_ref, *resolved_ref;
git_repository *repo;
git_oid id;
@@ -255,7 +255,7 @@ BEGIN_TEST("createref", create_deep_symbolic_ref)
must_pass(gitfo_unlink(ref_path)); /* TODO: replace with git_reference_delete() when available */
END_TEST
-BEGIN_TEST("createref", create_new_object_id_ref)
+BEGIN_TEST(create2, "create a new OID reference")
git_reference *new_reference, *looked_up_ref;
git_repository *repo;
git_oid id;
@@ -295,37 +295,27 @@ BEGIN_TEST("createref", create_new_object_id_ref)
must_pass(gitfo_unlink(ref_path)); /* TODO: replace with git_reference_delete() when available */
END_TEST
-BEGIN_TEST("packrefs", create_packfile_with_empty_folder)
+BEGIN_TEST(pack0, "create a packfile for an empty folder")
git_repository *repo;
- git_reference *reference;
char temp_path[GIT_PATH_MAX];
- int path_len = 0;
const int mode = 0755; /* or 0777 ? */
- must_pass(copydir_recurs(REPOSITORY_FOLDER, TEMP_DIR));
-
- git__joinpath(temp_path, TEMP_DIR, TEST_REPOSITORY_NAME);
- must_pass(git_repository_open(&repo, temp_path));
+ must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
git__joinpath_n(temp_path, 3, repo->path_repository, GIT_REFS_HEADS_DIR, "empty_dir");
must_pass(gitfo_mkdir_recurs(temp_path, mode));
must_pass(git_reference_packall(repo));
- git_repository_free(repo);
- must_pass(rmdir_recurs(TEMP_DIR));
+ close_temp_repo(repo);
END_TEST
-BEGIN_TEST("packrefs", create_packfile)
+BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo")
git_repository *repo;
git_reference *reference;
char temp_path[GIT_PATH_MAX];
- int path_len = 0;
- must_pass(copydir_recurs(REPOSITORY_FOLDER, TEMP_DIR));
-
- git__joinpath(temp_path, TEMP_DIR, TEST_REPOSITORY_NAME);
- must_pass(git_repository_open(&repo, temp_path));
+ must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure a known loose ref can be looked up */
must_pass(git_repository_lookup_ref(&reference, repo, loose_tag_ref_name));
@@ -347,20 +337,16 @@ BEGIN_TEST("packrefs", create_packfile)
git__joinpath(temp_path, repo->path_repository, loose_tag_ref_name);
must_pass(!gitfo_exists(temp_path));
- git_repository_free(repo);
- must_pass(rmdir_recurs(TEMP_DIR));
+ close_temp_repo(repo);
END_TEST
-BEGIN_TEST("renameref", rename_a_loose_reference)
+BEGIN_TEST(rename0, "rename a loose reference")
git_reference *looked_up_ref, *another_looked_up_ref;
git_repository *repo;
char temp_path[GIT_PATH_MAX];
const char *new_name = "refs/tags/Nemo/knows/refs.kung-fu";
- must_pass(copydir_recurs(REPOSITORY_FOLDER, TEMP_DIR));
-
- git__joinpath(temp_path, TEMP_DIR, TEST_REPOSITORY_NAME);
- must_pass(git_repository_open(&repo, temp_path));
+ must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the ref doesn't exist on the file system */
git__joinpath(temp_path, repo->path_repository, new_name);
@@ -391,21 +377,16 @@ BEGIN_TEST("renameref", rename_a_loose_reference)
git__joinpath(temp_path, repo->path_repository, new_name);
must_pass(gitfo_exists(temp_path));
- git_repository_free(repo);
-
- must_pass(rmdir_recurs(TEMP_DIR));
+ close_temp_repo(repo);
END_TEST
-BEGIN_TEST("renameref", renaming_a_packed_reference_makes_it_loose)
+BEGIN_TEST(rename1, "rename a packed reference (should make it loose)")
git_reference *looked_up_ref, *another_looked_up_ref;
git_repository *repo;
char temp_path[GIT_PATH_MAX];
const char *brand_new_name = "refs/heads/brand_new_name";
- must_pass(copydir_recurs(REPOSITORY_FOLDER, TEMP_DIR));
-
- git__joinpath(temp_path, TEMP_DIR, TEST_REPOSITORY_NAME);
- must_pass(git_repository_open(&repo, temp_path));
+ must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the ref doesn't exist on the file system */
git__joinpath(temp_path, repo->path_repository, packed_head_name);
@@ -436,21 +417,16 @@ BEGIN_TEST("renameref", renaming_a_packed_reference_makes_it_loose)
git__joinpath(temp_path, repo->path_repository, brand_new_name);
must_pass(gitfo_exists(temp_path));
- git_repository_free(repo);
-
- must_pass(rmdir_recurs(TEMP_DIR));
+ close_temp_repo(repo);
END_TEST
-BEGIN_TEST("renameref", renaming_a_packed_reference_does_not_pack_another_reference_which_happens_to_be_in_both_loose_and_pack_state)
+BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference which happens to be in both loose and pack state")
git_reference *looked_up_ref, *another_looked_up_ref;
git_repository *repo;
char temp_path[GIT_PATH_MAX];
const char *brand_new_name = "refs/heads/brand_new_name";
- must_pass(copydir_recurs(REPOSITORY_FOLDER, TEMP_DIR));
-
- git__joinpath(temp_path, TEMP_DIR, TEST_REPOSITORY_NAME);
- must_pass(git_repository_open(&repo, temp_path));
+ must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the other reference exists on the file system */
git__joinpath(temp_path, repo->path_repository, packed_test_head_name);
@@ -480,16 +456,14 @@ BEGIN_TEST("renameref", renaming_a_packed_reference_does_not_pack_another_refere
/* Ensure the other ref still exists on the file system */
must_pass(gitfo_exists(temp_path));
- git_repository_free(repo);
-
- must_pass(rmdir_recurs(TEMP_DIR));
+ close_temp_repo(repo);
END_TEST
-BEGIN_TEST("renameref", can_not_rename_a_reference_with_the_name_of_an_existing_reference)
+BEGIN_TEST(rename3, "can not rename a reference with the name of an existing reference")
git_reference *looked_up_ref;
git_repository *repo;
- must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
+ must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* An existing reference... */
must_pass(git_repository_lookup_ref(&looked_up_ref, repo, packed_head_name));
@@ -501,14 +475,14 @@ BEGIN_TEST("renameref", can_not_rename_a_reference_with_the_name_of_an_existing_
must_pass(git_repository_lookup_ref(&looked_up_ref, repo, packed_head_name));
must_be_true(!strcmp(looked_up_ref->name, packed_head_name));
- git_repository_free(repo);
+ close_temp_repo(repo);
END_TEST
-BEGIN_TEST("renameref", can_not_rename_a_reference_with_an_invalid_name)
+BEGIN_TEST(rename4, "can not rename a reference with an invalid name")
git_reference *looked_up_ref;
git_repository *repo;
- must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
+ must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* An existing oid reference... */
must_pass(git_repository_lookup_ref(&looked_up_ref, repo, packed_test_head_name));
@@ -523,18 +497,15 @@ BEGIN_TEST("renameref", can_not_rename_a_reference_with_an_invalid_name)
must_pass(git_repository_lookup_ref(&looked_up_ref, repo, packed_test_head_name));
must_be_true(!strcmp(looked_up_ref->name, packed_test_head_name));
- git_repository_free(repo);
+ close_temp_repo(repo);
END_TEST
-BEGIN_TEST("deleteref", deleting_a_ref_which_is_both_packed_and_loose_should_remove_both_tracks_in_the_filesystem)
+BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove both tracks in the filesystem")
git_reference *looked_up_ref, *another_looked_up_ref;
git_repository *repo;
char temp_path[GIT_PATH_MAX];
- must_pass(copydir_recurs(REPOSITORY_FOLDER, TEMP_DIR));
-
- git__joinpath(temp_path, TEMP_DIR, TEST_REPOSITORY_NAME);
- must_pass(git_repository_open(&repo, temp_path));
+ must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the loose reference exists on the file system */
git__joinpath(temp_path, repo->path_repository, packed_test_head_name);
@@ -555,9 +526,7 @@ BEGIN_TEST("deleteref", deleting_a_ref_which_is_both_packed_and_loose_should_rem
/* Ensure the loose reference doesn't exist any longer on the file system */
must_pass(!gitfo_exists(temp_path));
- git_repository_free(repo);
-
- must_pass(rmdir_recurs(TEMP_DIR));
+ close_temp_repo(repo);
END_TEST
static int ensure_refname_normalized(int is_oid_ref, const char *input_refname, const char *expected_refname)
@@ -585,7 +554,7 @@ static int ensure_refname_normalized(int is_oid_ref, const char *input_refname,
#define OID_REF 1
#define SYM_REF 0
-BEGIN_TEST("normalizeref", normalize_object_id_ref)
+BEGIN_TEST(normalize0, "normalize a direct (OID) reference name")
must_fail(ensure_refname_normalized(OID_REF, "a", NULL));
must_fail(ensure_refname_normalized(OID_REF, "", NULL));
must_fail(ensure_refname_normalized(OID_REF, "refs/heads/a/", NULL));
@@ -606,7 +575,7 @@ BEGIN_TEST("normalizeref", normalize_object_id_ref)
must_fail(ensure_refname_normalized(OID_REF, "refs/heads/v@{ation", NULL));
END_TEST
-BEGIN_TEST("normalizeref", normalize_symbolic_ref)
+BEGIN_TEST(normalize1, "normalize a symbolic reference name")
must_pass(ensure_refname_normalized(SYM_REF, "a", "a"));
must_pass(ensure_refname_normalized(SYM_REF, "a/b", "a/b"));
must_pass(ensure_refname_normalized(SYM_REF, "refs///heads///a", "refs/heads/a"));
@@ -614,158 +583,162 @@ BEGIN_TEST("normalizeref", normalize_symbolic_ref)
must_fail(ensure_refname_normalized(SYM_REF, "heads\foo", NULL));
END_TEST
-/* Ported from JGit, BSD licence. See https://github.com/spearce/JGit/commit/e4bf8f6957bbb29362575d641d1e77a02d906739 */
-BEGIN_TEST("normalizeref", jgit_tests)
-
- /* EmptyString */
- must_fail(ensure_refname_normalized(SYM_REF, "", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "/", NULL));
-
- /* MustHaveTwoComponents */
- must_fail(ensure_refname_normalized(OID_REF, "master", NULL));
- must_pass(ensure_refname_normalized(SYM_REF, "heads/master", "heads/master"));
-
- /* ValidHead */
-
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/master", "refs/heads/master"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/pu", "refs/heads/pu"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/z", "refs/heads/z"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/FoO", "refs/heads/FoO"));
-
- /* ValidTag */
- must_pass(ensure_refname_normalized(SYM_REF, "refs/tags/v1.0", "refs/tags/v1.0"));
-
- /* NoLockSuffix */
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master.lock", NULL));
-
- /* NoDirectorySuffix */
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master/", NULL));
-
- /* NoSpace */
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/i haz space", NULL));
-
- /* NoAsciiControlCharacters */
- {
- char c;
- char buffer[MAX_GITDIR_TREE_STRUCTURE_PATH_LENGTH];
- for (c = '\1'; c < ' '; c++) {
- strncpy(buffer, "refs/heads/mast", 15);
- strncpy(buffer + 15, (const char *)&c, 1);
- strncpy(buffer + 16, "er", 2);
- buffer[18 - 1] = '\0';
- must_fail(ensure_refname_normalized(SYM_REF, buffer, NULL));
- }
- }
-
- /* NoBareDot */
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/.", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/..", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/./master", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/../master", NULL));
-
- /* NoLeadingOrTrailingDot */
- must_fail(ensure_refname_normalized(SYM_REF, ".", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/.bar", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/..bar", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/bar.", NULL));
-
- /* ContainsDot */
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/m.a.s.t.e.r", "refs/heads/m.a.s.t.e.r"));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master..pu", NULL));
-
- /* NoMagicRefCharacters */
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master^", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/^master", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "^refs/heads/master", NULL));
-
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master~", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/~master", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "~refs/heads/master", NULL));
-
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master:", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/:master", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, ":refs/heads/master", NULL));
-
- /* ShellGlob */
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master?", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/?master", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "?refs/heads/master", NULL));
-
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master[", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/[master", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "[refs/heads/master", NULL));
-
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master*", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/*master", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "*refs/heads/master", NULL));
-
- /* ValidSpecialCharacters */
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/!", "refs/heads/!"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/\"", "refs/heads/\""));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/#", "refs/heads/#"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/$", "refs/heads/$"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/%", "refs/heads/%"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/&", "refs/heads/&"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/'", "refs/heads/'"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/(", "refs/heads/("));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/)", "refs/heads/)"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/+", "refs/heads/+"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/,", "refs/heads/,"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/-", "refs/heads/-"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/;", "refs/heads/;"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/<", "refs/heads/<"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/=", "refs/heads/="));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/>", "refs/heads/>"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/@", "refs/heads/@"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/]", "refs/heads/]"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/_", "refs/heads/_"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/`", "refs/heads/`"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/{", "refs/heads/{"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/|", "refs/heads/|"));
- must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/}", "refs/heads/}"));
-
- // This is valid on UNIX, but not on Windows
- // hence we make in invalid due to non-portability
- //
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/\\", NULL));
-
- /* UnicodeNames */
- /*
- * Currently this fails.
- * must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/\u00e5ngstr\u00f6m", "refs/heads/\u00e5ngstr\u00f6m"));
- */
-
- /* RefLogQueryIsValidRef */
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master@{1}", NULL));
- must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master@{1.hour.ago}", NULL));
+/* Ported from JGit, BSD licence.
+ * See https://github.com/spearce/JGit/commit/e4bf8f6957bbb29362575d641d1e77a02d906739 */
+BEGIN_TEST(normalize2, "tests borrowed from JGit")
+
+/* EmptyString */
+ must_fail(ensure_refname_normalized(SYM_REF, "", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "/", NULL));
+
+/* MustHaveTwoComponents */
+ must_fail(ensure_refname_normalized(OID_REF, "master", NULL));
+ must_pass(ensure_refname_normalized(SYM_REF, "heads/master", "heads/master"));
+
+/* ValidHead */
+
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/master", "refs/heads/master"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/pu", "refs/heads/pu"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/z", "refs/heads/z"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/FoO", "refs/heads/FoO"));
+
+/* ValidTag */
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/tags/v1.0", "refs/tags/v1.0"));
+
+/* NoLockSuffix */
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master.lock", NULL));
+
+/* NoDirectorySuffix */
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master/", NULL));
+
+/* NoSpace */
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/i haz space", NULL));
+
+/* NoAsciiControlCharacters */
+ {
+ char c;
+ char buffer[MAX_GITDIR_TREE_STRUCTURE_PATH_LENGTH];
+ for (c = '\1'; c < ' '; c++) {
+ strncpy(buffer, "refs/heads/mast", 15);
+ strncpy(buffer + 15, (const char *)&c, 1);
+ strncpy(buffer + 16, "er", 2);
+ buffer[18 - 1] = '\0';
+ must_fail(ensure_refname_normalized(SYM_REF, buffer, NULL));
+ }
+ }
+
+/* NoBareDot */
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/.", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/..", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/./master", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/../master", NULL));
+
+/* NoLeadingOrTrailingDot */
+ must_fail(ensure_refname_normalized(SYM_REF, ".", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/.bar", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/..bar", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/bar.", NULL));
+
+/* ContainsDot */
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/m.a.s.t.e.r", "refs/heads/m.a.s.t.e.r"));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master..pu", NULL));
+
+/* NoMagicRefCharacters */
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master^", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/^master", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "^refs/heads/master", NULL));
+
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master~", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/~master", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "~refs/heads/master", NULL));
+
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master:", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/:master", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, ":refs/heads/master", NULL));
+
+/* ShellGlob */
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master?", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/?master", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "?refs/heads/master", NULL));
+
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master[", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/[master", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "[refs/heads/master", NULL));
+
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master*", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/*master", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "*refs/heads/master", NULL));
+
+/* ValidSpecialCharacters */
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/!", "refs/heads/!"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/\"", "refs/heads/\""));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/#", "refs/heads/#"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/$", "refs/heads/$"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/%", "refs/heads/%"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/&", "refs/heads/&"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/'", "refs/heads/'"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/(", "refs/heads/("));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/)", "refs/heads/)"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/+", "refs/heads/+"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/,", "refs/heads/,"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/-", "refs/heads/-"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/;", "refs/heads/;"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/<", "refs/heads/<"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/=", "refs/heads/="));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/>", "refs/heads/>"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/@", "refs/heads/@"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/]", "refs/heads/]"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/_", "refs/heads/_"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/`", "refs/heads/`"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/{", "refs/heads/{"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/|", "refs/heads/|"));
+ must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/}", "refs/heads/}"));
+
+ // This is valid on UNIX, but not on Windows
+ // hence we make in invalid due to non-portability
+ //
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/\\", NULL));
+
+/* UnicodeNames */
+ /*
+ * Currently this fails.
+ * must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/\u00e5ngstr\u00f6m", "refs/heads/\u00e5ngstr\u00f6m"));
+ */
+
+/* RefLogQueryIsValidRef */
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master@{1}", NULL));
+ must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master@{1.hour.ago}", NULL));
END_TEST
-git_testsuite *libgit2_suite_refs(void)
-{
- git_testsuite *suite = git_testsuite_new("References");
-
- ADD_TEST(suite, "readtag", loose_tag_reference_looking_up);
- ADD_TEST(suite, "readtag", non_existing_tag_reference_looking_up);
- ADD_TEST(suite, "readsymref", symbolic_reference_looking_up);
- ADD_TEST(suite, "readsymref", nested_symbolic_reference_looking_up);
- ADD_TEST(suite, "readsymref", looking_up_head_then_master);
- ADD_TEST(suite, "readsymref", looking_up_master_then_head);
- ADD_TEST(suite, "readpackedref", packed_reference_looking_up);
- ADD_TEST(suite, "readpackedref", packed_exists_but_more_recent_loose_reference_is_retrieved);
- ADD_TEST(suite, "createref", create_new_symbolic_ref);
- ADD_TEST(suite, "createref", create_deep_symbolic_ref);
- ADD_TEST(suite, "createref", create_new_object_id_ref);
- ADD_TEST(suite, "normalizeref", normalize_object_id_ref);
- ADD_TEST(suite, "normalizeref", normalize_symbolic_ref);
- ADD_TEST(suite, "normalizeref", jgit_tests);
- ADD_TEST(suite, "packrefs", create_packfile_with_empty_folder);
- ADD_TEST(suite, "packrefs", create_packfile);
- ADD_TEST(suite, "renameref", renaming_a_packed_reference_makes_it_loose);
- ADD_TEST(suite, "renameref", renaming_a_packed_reference_does_not_pack_another_reference_which_happens_to_be_in_both_loose_and_pack_state);
- ADD_TEST(suite, "renameref", rename_a_loose_reference);
- ADD_TEST(suite, "renameref", can_not_rename_a_reference_with_the_name_of_an_existing_reference);
- ADD_TEST(suite, "renameref", can_not_rename_a_reference_with_an_invalid_name);
- ADD_TEST(suite, "deleteref", deleting_a_ref_which_is_both_packed_and_loose_should_remove_both_tracks_in_the_filesystem);
-
- return suite;
-}
+
+BEGIN_SUITE(refs)
+ ADD_TEST(readtag0);
+ ADD_TEST(readtag1);
+
+ ADD_TEST(readsym0);
+ ADD_TEST(readsym1);
+ ADD_TEST(readsym2);
+ ADD_TEST(readsym3);
+
+ ADD_TEST(readpacked0);
+ ADD_TEST(readpacked1);
+
+ ADD_TEST(create0);
+ ADD_TEST(create1);
+ ADD_TEST(create2);
+
+ ADD_TEST(normalize0);
+ ADD_TEST(normalize1);
+ ADD_TEST(normalize2);
+
+ ADD_TEST(pack0);
+ ADD_TEST(pack1);
+
+ ADD_TEST(rename0);
+ ADD_TEST(rename1);
+ ADD_TEST(rename2);
+ ADD_TEST(rename3);
+ ADD_TEST(rename4);
+
+ ADD_TEST(delete0);
+END_SUITE
diff --git a/tests/t11-sqlite.c b/tests/t11-sqlite.c
index 9b8cc6bf8..9e9d1b786 100644
--- a/tests/t11-sqlite.c
+++ b/tests/t11-sqlite.c
@@ -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
diff --git a/tests/t12-repo.c b/tests/t12-repo.c
index 68b366033..644669c8e 100644
--- a/tests/t12-repo.c
+++ b/tests/t12-repo.c
@@ -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;
-}
diff --git a/tests/test_helpers.c b/tests/test_helpers.c
index 4805fdcae..588461135 100644
--- a/tests/test_helpers.c
+++ b/tests/test_helpers.c
@@ -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);
+}
diff --git a/tests/test_helpers.h b/tests/test_helpers.h
index af5a0a908..78538d51c 100644
--- a/tests/test_helpers.h
+++ b/tests/test_helpers.h
@@ -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__ */
diff --git a/tests/test_lib.c b/tests/test_lib.c
index eb13cd8f6..c9c6141c6 100755
--- a/tests/test_lib.c
+++ b/tests/test_lib.c
@@ -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;
}
diff --git a/tests/test_lib.h b/tests/test_lib.h
index ae384ba4d..d0b62c8d4 100755
--- a/tests/test_lib.h
+++ b/tests/test_lib.h
@@ -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
diff --git a/tests/test_main.c b/tests/test_main.c
index 01e7d5123..9308b8d45 100644
--- a/tests/test_main.c
+++ b/tests/test_main.c
@@ -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;
}