summaryrefslogtreecommitdiff
path: root/tests/t12-repo.c
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/t12-repo.c
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/t12-repo.c')
-rw-r--r--tests/t12-repo.c72
1 files changed, 45 insertions, 27 deletions
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;
-}