Even more cleanups
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
diff --git a/tests-clar/network/fetchlocal.c b/tests-clar/network/fetchlocal.c
index 9ffbedb..ee3bd9d 100644
--- a/tests-clar/network/fetchlocal.c
+++ b/tests-clar/network/fetchlocal.c
@@ -11,9 +11,9 @@ static void transfer_cb(const git_transfer_progress *stats, void *payload)
(*callcount)++;
}
-void test_network_fetchlocal__cleanup(void)
+static void cleanup_local_repo(void *path)
{
- cl_fixture_cleanup("foo");
+ cl_fixture_cleanup((char *)path);
}
void test_network_fetchlocal__complete(void)
@@ -24,6 +24,8 @@ void test_network_fetchlocal__complete(void)
git_strarray refnames = {0};
const char *url = cl_git_fixture_url("testrepo.git");
+
+ cl_set_cleanup(&cleanup_local_repo, "foo");
cl_git_pass(git_repository_init(&repo, "foo", true));
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
@@ -40,6 +42,12 @@ void test_network_fetchlocal__complete(void)
git_repository_free(repo);
}
+static void cleanup_sandbox(void *unused)
+{
+ GIT_UNUSED(unused);
+ cl_git_sandbox_cleanup();
+}
+
void test_network_fetchlocal__partial(void)
{
git_repository *repo = cl_git_sandbox_init("partial-testrepo");
@@ -48,6 +56,7 @@ void test_network_fetchlocal__partial(void)
git_strarray refnames = {0};
const char *url;
+ cl_set_cleanup(&cleanup_sandbox, NULL);
cl_git_pass(git_reference_list(&refnames, repo, GIT_REF_LISTALL));
cl_assert_equal_i(1, (int)refnames.count);
@@ -65,6 +74,4 @@ void test_network_fetchlocal__partial(void)
git_strarray_free(&refnames);
git_remote_free(origin);
-
- cl_git_sandbox_cleanup();
}
diff --git a/tests-clar/odb/alternates.c b/tests-clar/odb/alternates.c
index c4b364b..be7bfa9 100644
--- a/tests-clar/odb/alternates.c
+++ b/tests-clar/odb/alternates.c
@@ -6,7 +6,7 @@ static git_buf destpath, filepath;
static const char *paths[] = {
"A.git", "B.git", "C.git", "D.git", "E.git", "F.git", "G.git"
};
-static git_filebuf file;
+static git_filebuf file;
static git_repository *repo;
void test_odb_alternates__cleanup(void)
@@ -16,7 +16,7 @@ void test_odb_alternates__cleanup(void)
git_buf_free(&destpath);
git_buf_free(&filepath);
- for (i=0; i<ARRAY_SIZE(paths); i++)
+ for (i = 0; i < ARRAY_SIZE(paths); i++)
cl_fixture_cleanup(paths[i]);
}
diff --git a/tests-clar/pack/packbuilder.c b/tests-clar/pack/packbuilder.c
index c36b720..5137787 100644
--- a/tests-clar/pack/packbuilder.c
+++ b/tests-clar/pack/packbuilder.c
@@ -9,30 +9,10 @@ static git_packbuilder *_packbuilder;
static git_indexer *_indexer;
static git_vector _commits;
static int _commits_is_initialized;
-static char *path_to_cleanup = NULL;
-static git_oid oid_to_cleanup = {{0}};
-
-static void cleanup_pack(const git_oid *oid)
-{
- char *hash, path[1024] = {0};
-
- if (git_oid_iszero(&oid_to_cleanup)) return;
-
- hash = git_oid_allocfmt(oid);
-
- sprintf(path, "pack-%s.idx", hash);
- p_unlink(path);
-
- sprintf(path, "pack-%s.pack", hash);
- p_unlink(path);
-
- git__free(hash);
- git_oid_fromstrn(&oid_to_cleanup, "", 0);
-}
void test_pack_packbuilder__initialize(void)
{
- cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
+ _repo = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_revwalk_new(&_revwalker, _repo));
cl_git_pass(git_packbuilder_new(&_packbuilder, _repo));
cl_git_pass(git_vector_init(&_commits, 0, NULL));
@@ -61,14 +41,8 @@ void test_pack_packbuilder__cleanup(void)
git_indexer_free(_indexer);
_indexer = NULL;
- git_repository_free(_repo);
+ cl_git_sandbox_cleanup();
_repo = NULL;
-
- if (path_to_cleanup)
- cl_fixture_cleanup(path_to_cleanup);
- path_to_cleanup = NULL;
-
- cleanup_pack(&oid_to_cleanup);
}
static void seed_packbuilder(void)
@@ -102,7 +76,6 @@ static void seed_packbuilder(void)
void test_pack_packbuilder__create_pack(void)
{
git_transfer_progress stats;
- path_to_cleanup = "testpack.pack";
seed_packbuilder();
cl_git_pass(git_packbuilder_write(_packbuilder, "testpack.pack"));
@@ -110,17 +83,13 @@ void test_pack_packbuilder__create_pack(void)
cl_git_pass(git_indexer_new(&_indexer, "testpack.pack"));
cl_git_pass(git_indexer_run(_indexer, &stats));
cl_git_pass(git_indexer_write(_indexer));
- git_oid_cpy(&oid_to_cleanup, git_indexer_hash(_indexer));
-
}
static git_transfer_progress stats;
static int foreach_cb(void *buf, size_t len, void *payload)
{
git_indexer_stream *idx = (git_indexer_stream *) payload;
-
cl_git_pass(git_indexer_stream_add(idx, buf, len, &stats));
-
return 0;
}
@@ -132,6 +101,5 @@ void test_pack_packbuilder__foreach(void)
cl_git_pass(git_indexer_stream_new(&idx, ".", NULL, NULL));
cl_git_pass(git_packbuilder_foreach(_packbuilder, foreach_cb, idx));
cl_git_pass(git_indexer_stream_finalize(idx, &stats));
- git_oid_cpy(&oid_to_cleanup, git_indexer_stream_hash(idx));
git_indexer_stream_free(idx);
}