clone: reorganize tests
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
diff --git a/tests-clar/clone/clone.c b/tests-clar/clone/clone.c
index 237e607..6610943 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);
}