summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-10-07 12:04:07 +0200
committernulltoken <emeric.fermas@gmail.com>2012-10-08 00:44:19 +0200
commitebecf1e7d8e1b2f6c73c7b1de0a6371e65f27285 (patch)
tree383cd55d036dd1c5a4feb9b9681eb27e75e9c06e
parentd280c71b8e6b4df3d8d134b14740e1ec7d885565 (diff)
downloadlibgit2-ebecf1e7d8e1b2f6c73c7b1de0a6371e65f27285.tar.gz
clone: reorganize tests
-rw-r--r--tests-clar/clone/clone.c57
1 files changed, 36 insertions, 21 deletions
diff --git a/tests-clar/clone/clone.c b/tests-clar/clone/clone.c
index 237e607dd..661094310 100644
--- a/tests-clar/clone/clone.c
+++ b/tests-clar/clone/clone.c
@@ -15,12 +15,11 @@ void test_clone_clone__initialize(void)
g_repo = NULL;
}
-void test_clone_clone__cleanup(void)
+static void cleanup_repository(void *path)
{
- if (g_repo) {
+ if (g_repo)
git_repository_free(g_repo);
- g_repo = NULL;
- }
+ cl_fixture_cleanup((const char *)path);
}
// TODO: This is copy/pasted from network/remotelocal.c.
@@ -63,7 +62,6 @@ static void build_local_file_url(git_buf *out, const char *fixture)
git_buf_free(&path_buf);
}
-
void test_clone_clone__bad_url(void)
{
/* Clone should clean up the mess if the URL isn't a git repository */
@@ -73,33 +71,44 @@ void test_clone_clone__bad_url(void)
cl_assert(!git_path_exists("./foo.git"));
}
-
void test_clone_clone__local(void)
{
git_buf src = GIT_BUF_INIT;
build_local_file_url(&src, cl_fixture("testrepo.git"));
#if DO_LOCAL_TEST
+ cl_set_cleanup(&cleanup_repository, "./local");
+
cl_git_pass(git_clone(&g_repo, git_buf_cstr(&src), "./local", NULL, NULL, NULL));
- git_repository_free(g_repo);
- git_futils_rmdir_r("./local", GIT_DIRREMOVAL_FILES_AND_DIRS);
- cl_git_pass(git_clone_bare(&g_repo, git_buf_cstr(&src), "./local.git", NULL));
- git_futils_rmdir_r("./local.git", GIT_DIRREMOVAL_FILES_AND_DIRS);
#endif
git_buf_free(&src);
}
+void test_clone_clone__local_bare(void)
+{
+ git_buf src = GIT_BUF_INIT;
+ build_local_file_url(&src, cl_fixture("testrepo.git"));
+
+#if DO_LOCAL_TEST
+ cl_set_cleanup(&cleanup_repository, "./local.git");
+
+ cl_git_pass(git_clone_bare(&g_repo, git_buf_cstr(&src), "./local.git", NULL));
+#endif
+
+ git_buf_free(&src);
+}
void test_clone_clone__network_full(void)
{
#if DO_LIVE_NETWORK_TESTS
git_remote *origin;
+ cl_set_cleanup(&cleanup_repository, "./test2");
+
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./test2", NULL, NULL, NULL));
cl_assert(!git_repository_is_bare(g_repo));
cl_git_pass(git_remote_load(&origin, g_repo, "origin"));
- git_futils_rmdir_r("./test2", GIT_DIRREMOVAL_FILES_AND_DIRS);
#endif
}
@@ -108,32 +117,38 @@ void test_clone_clone__network_bare(void)
#if DO_LIVE_NETWORK_TESTS
git_remote *origin;
- cl_git_pass(git_clone_bare(&g_repo, LIVE_REPO_URL, "test", NULL));
+ cl_set_cleanup(&cleanup_repository, "./test");
+
+ cl_git_pass(git_clone_bare(&g_repo, LIVE_REPO_URL, "./test", NULL));
cl_assert(git_repository_is_bare(g_repo));
cl_git_pass(git_remote_load(&origin, g_repo, "origin"));
- git_futils_rmdir_r("./test", GIT_DIRREMOVAL_FILES_AND_DIRS);
#endif
}
-
-void test_clone_clone__already_exists(void)
+void test_clone_clone__cope_with_already_existing_directory(void)
{
#if DO_LIVE_NETWORK_TESTS
- /* Should pass with existing-but-empty dir */
+ cl_set_cleanup(&cleanup_repository, "./foo");
+
p_mkdir("./foo", GIT_DIR_MODE);
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL));
git_repository_free(g_repo); g_repo = NULL;
- git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS);
#endif
+}
+
+void test_clone_clone__fail_when_the_target_is_a_file(void)
+{
+ cl_set_cleanup(&cleanup_repository, "./foo");
- /* Should fail with a file */
cl_git_mkfile("./foo", "Bar!");
cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL));
- git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS);
+}
+
+void test_clone_clone__fail_with_already_existing_but_non_empty_directory(void)
+{
+ cl_set_cleanup(&cleanup_repository, "./foo");
- /* Should fail with existing-and-nonempty dir */
p_mkdir("./foo", GIT_DIR_MODE);
cl_git_mkfile("./foo/bar", "Baz!");
cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL));
- git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS);
}