Move test cleanup into cleanup functions
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
diff --git a/tests-clar/config/read.c b/tests-clar/config/read.c
index d2ad0de..b603acb 100644
--- a/tests-clar/config/read.c
+++ b/tests-clar/config/read.c
@@ -1,5 +1,10 @@
#include "clar_libgit2.h"
+void test_config_read__cleanup(void)
+{
+ cl_fixture_cleanup("./empty");
+}
+
void test_config_read__simple_read(void)
{
git_config *cfg;
@@ -441,7 +446,6 @@ void test_config_read__can_load_and_parse_an_empty_config_file(void)
cl_assert_equal_i(GIT_ENOTFOUND, git_config_get_int32(&i, cfg, "nope.neither"));
git_config_free(cfg);
- cl_fixture_cleanup("./empty");
}
void test_config_read__cannot_load_a_non_existing_config_file(void)
diff --git a/tests-clar/core/env.c b/tests-clar/core/env.c
index d1d9888..27e52ec 100644
--- a/tests-clar/core/env.c
+++ b/tests-clar/core/env.c
@@ -14,6 +14,18 @@ static const char *env_vars[NUM_VARS] = { "HOME" };
static char *env_save[NUM_VARS];
+static char *home_values[] = {
+ "fake_home",
+ "fáke_hõme", /* all in latin-1 supplement */
+ "fĀke_Ĥome", /* latin extended */
+ "fακε_hοmέ", /* having fun with greek */
+ "faงe_นome", /* now I have no idea, but thai characters */
+ "f\xe1\x9cx80ke_\xe1\x9c\x91ome", /* tagalog characters */
+ "\xe1\xb8\x9fẢke_hoṁe", /* latin extended additional */
+ "\xf0\x9f\x98\x98\xf0\x9f\x98\x82", /* emoticons */
+ NULL
+};
+
void test_core_env__initialize(void)
{
int i;
@@ -24,6 +36,8 @@ void test_core_env__initialize(void)
void test_core_env__cleanup(void)
{
int i;
+ char **val;
+
for (i = 0; i < NUM_VARS; ++i) {
cl_setenv(env_vars[i], env_save[i]);
#ifdef GIT_WIN32
@@ -31,11 +45,16 @@ void test_core_env__cleanup(void)
#endif
env_save[i] = NULL;
}
+
+ for (val = home_values; *val != NULL; val++) {
+ cl_fixture_cleanup(*val);
+ }
}
static void setenv_and_check(const char *name, const char *value)
{
char *check;
+
cl_git_pass(cl_setenv(name, value));
check = cl_getenv(name);
cl_assert_equal_s(value, check);
@@ -46,17 +65,6 @@ static void setenv_and_check(const char *name, const char *value)
void test_core_env__0(void)
{
- static char *home_values[] = {
- "fake_home",
- "fáke_hõme", /* all in latin-1 supplement */
- "fĀke_Ĥome", /* latin extended */
- "fακε_hοmέ", /* having fun with greek */
- "faงe_นome", /* now I have no idea, but thai characters */
- "f\xe1\x9cx80ke_\xe1\x9c\x91ome", /* tagalog characters */
- "\xe1\xb8\x9fẢke_hoṁe", /* latin extended additional */
- "\xf0\x9f\x98\x98\xf0\x9f\x98\x82", /* emoticons */
- NULL
- };
git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT;
char testfile[16], tidx = '0';
char **val;
@@ -122,8 +130,6 @@ void test_core_env__0(void)
}
}
#endif
-
- cl_fixture_cleanup(*val);
}
git_buf_free(&path);
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index 8359ce0..d2ad71c 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -24,6 +24,7 @@ static struct test_entry test_entries[] = {
{48, "src/revobject.h", 1448, 0x4C3F7FE2}
};
+static char *path_to_cleanup = NULL;
// Helpers
static void copy_file(const char *src, const char *dst)
@@ -74,6 +75,9 @@ void test_index_tests__initialize(void)
void test_index_tests__cleanup(void)
{
+ if (path_to_cleanup)
+ cl_fixture_cleanup(path_to_cleanup);
+ path_to_cleanup = NULL;
}
@@ -246,7 +250,7 @@ void test_index_tests__add(void)
git_index_free(index);
git_repository_free(repo);
- cl_fixture_cleanup("myrepo");
+ path_to_cleanup = "myrepo";
}
void test_index_tests__add_from_workdir_to_a_bare_repository_returns_EBAREPO(void)
diff --git a/tests-clar/network/fetchlocal.c b/tests-clar/network/fetchlocal.c
index 48f30e7..9ffbedb 100644
--- a/tests-clar/network/fetchlocal.c
+++ b/tests-clar/network/fetchlocal.c
@@ -11,6 +11,11 @@ static void transfer_cb(const git_transfer_progress *stats, void *payload)
(*callcount)++;
}
+void test_network_fetchlocal__cleanup(void)
+{
+ cl_fixture_cleanup("foo");
+}
+
void test_network_fetchlocal__complete(void)
{
git_repository *repo;
@@ -33,7 +38,6 @@ void test_network_fetchlocal__complete(void)
git_strarray_free(&refnames);
git_remote_free(origin);
git_repository_free(repo);
- cl_fixture_cleanup("foo");
}
void test_network_fetchlocal__partial(void)
diff --git a/tests-clar/pack/packbuilder.c b/tests-clar/pack/packbuilder.c
index 31823ea..c36b720 100644
--- a/tests-clar/pack/packbuilder.c
+++ b/tests-clar/pack/packbuilder.c
@@ -9,6 +9,26 @@ 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)
{
@@ -43,6 +63,12 @@ void test_pack_packbuilder__cleanup(void)
git_repository_free(_repo);
_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)
@@ -73,24 +99,10 @@ static void seed_packbuilder(void)
}
}
-static void cleanup_pack(const git_oid *oid)
-{
- char *hash, path[1024] = {0};
-
- 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);
-}
-
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"));
@@ -98,9 +110,8 @@ 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));
- cl_fixture_cleanup("testpack.pack");
- cleanup_pack(git_indexer_hash(_indexer));
}
static git_transfer_progress stats;
@@ -116,13 +127,11 @@ static int foreach_cb(void *buf, size_t len, void *payload)
void test_pack_packbuilder__foreach(void)
{
git_indexer_stream *idx;
- git_oid oid;
seed_packbuilder();
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, git_indexer_stream_hash(idx));
+ git_oid_cpy(&oid_to_cleanup, git_indexer_stream_hash(idx));
git_indexer_stream_free(idx);
- cleanup_pack(&oid);
}
diff --git a/tests-clar/stash/save.c b/tests-clar/stash/save.c
index 2302ebb..e6033e1 100644
--- a/tests-clar/stash/save.c
+++ b/tests-clar/stash/save.c
@@ -32,6 +32,7 @@ void test_stash_save__cleanup(void)
repo = NULL;
cl_git_pass(git_futils_rmdir_r("stash", NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_fixture_cleanup("sorry-it-is-a-non-bare-only-party");
}
static void assert_object_oid(const char* revision, const char* expected_oid, git_otype type)
@@ -211,7 +212,6 @@ void test_stash_save__cannot_stash_against_a_bare_repository(void)
git_stash_save(&stash_tip_oid, local, signature, NULL, GIT_STASH_DEFAULT));
git_repository_free(local);
- cl_fixture_cleanup("sorry-it-is-a-non-bare-only-party");
}
void test_stash_save__can_stash_against_a_detached_head(void)
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index 70fbca9..85363a9 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -6,6 +6,8 @@
#include "util.h"
#include "path.h"
+static char *path_to_cleanup = NULL;
+
/**
* Initializer
*
@@ -25,6 +27,10 @@ void test_status_worktree__initialize(void)
void test_status_worktree__cleanup(void)
{
cl_git_sandbox_cleanup();
+
+ if (path_to_cleanup)
+ cl_fixture_cleanup(path_to_cleanup);
+ path_to_cleanup = NULL;
}
/**
@@ -446,7 +452,7 @@ void test_status_worktree__first_commit_in_progress(void)
git_index_free(index);
git_repository_free(repo);
- cl_fixture_cleanup("getting_started");
+ path_to_cleanup = "getting_started";
}
@@ -596,7 +602,7 @@ void test_status_worktree__bracket_in_filename(void)
git_index_free(index);
git_repository_free(repo);
- cl_fixture_cleanup("with_bracket");
+ path_to_cleanup = "with_bracket";
}
void test_status_worktree__space_in_filename(void)
@@ -661,7 +667,7 @@ void test_status_worktree__space_in_filename(void)
git_index_free(index);
git_repository_free(repo);
- cl_fixture_cleanup("with_space");
+ path_to_cleanup = "with_space";
}
static const char *filemode_paths[] = {
@@ -772,7 +778,7 @@ void test_status_worktree__disable_pathspec_match(void)
);
git_repository_free(repo);
- cl_fixture_cleanup("pathspec");
+ path_to_cleanup = "pathspec";
}
@@ -825,7 +831,7 @@ void test_status_worktree__new_staged_file_must_handle_crlf(void)
git_config_free(config);
git_index_free(index);
git_repository_free(repo);
- cl_fixture_cleanup("getting_started");
+ path_to_cleanup = "getting_started";
}
void test_status_worktree__line_endings_dont_count_as_changes_with_autocrlf(void)