Commit 600d8dbf by Ben Straub

Move test cleanup into cleanup functions

parent bffbeebb
#include "clar_libgit2.h" #include "clar_libgit2.h"
void test_config_read__cleanup(void)
{
cl_fixture_cleanup("./empty");
}
void test_config_read__simple_read(void) void test_config_read__simple_read(void)
{ {
git_config *cfg; git_config *cfg;
...@@ -441,7 +446,6 @@ void test_config_read__can_load_and_parse_an_empty_config_file(void) ...@@ -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")); cl_assert_equal_i(GIT_ENOTFOUND, git_config_get_int32(&i, cfg, "nope.neither"));
git_config_free(cfg); git_config_free(cfg);
cl_fixture_cleanup("./empty");
} }
void test_config_read__cannot_load_a_non_existing_config_file(void) void test_config_read__cannot_load_a_non_existing_config_file(void)
......
...@@ -14,6 +14,18 @@ static const char *env_vars[NUM_VARS] = { "HOME" }; ...@@ -14,6 +14,18 @@ static const char *env_vars[NUM_VARS] = { "HOME" };
static char *env_save[NUM_VARS]; 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) void test_core_env__initialize(void)
{ {
int i; int i;
...@@ -24,6 +36,8 @@ void test_core_env__initialize(void) ...@@ -24,6 +36,8 @@ void test_core_env__initialize(void)
void test_core_env__cleanup(void) void test_core_env__cleanup(void)
{ {
int i; int i;
char **val;
for (i = 0; i < NUM_VARS; ++i) { for (i = 0; i < NUM_VARS; ++i) {
cl_setenv(env_vars[i], env_save[i]); cl_setenv(env_vars[i], env_save[i]);
#ifdef GIT_WIN32 #ifdef GIT_WIN32
...@@ -31,11 +45,16 @@ void test_core_env__cleanup(void) ...@@ -31,11 +45,16 @@ void test_core_env__cleanup(void)
#endif #endif
env_save[i] = NULL; 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) static void setenv_and_check(const char *name, const char *value)
{ {
char *check; char *check;
cl_git_pass(cl_setenv(name, value)); cl_git_pass(cl_setenv(name, value));
check = cl_getenv(name); check = cl_getenv(name);
cl_assert_equal_s(value, check); cl_assert_equal_s(value, check);
...@@ -46,17 +65,6 @@ static void setenv_and_check(const char *name, const char *value) ...@@ -46,17 +65,6 @@ static void setenv_and_check(const char *name, const char *value)
void test_core_env__0(void) 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; git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT;
char testfile[16], tidx = '0'; char testfile[16], tidx = '0';
char **val; char **val;
...@@ -122,8 +130,6 @@ void test_core_env__0(void) ...@@ -122,8 +130,6 @@ void test_core_env__0(void)
} }
} }
#endif #endif
cl_fixture_cleanup(*val);
} }
git_buf_free(&path); git_buf_free(&path);
......
...@@ -24,6 +24,7 @@ static struct test_entry test_entries[] = { ...@@ -24,6 +24,7 @@ static struct test_entry test_entries[] = {
{48, "src/revobject.h", 1448, 0x4C3F7FE2} {48, "src/revobject.h", 1448, 0x4C3F7FE2}
}; };
static char *path_to_cleanup = NULL;
// Helpers // Helpers
static void copy_file(const char *src, const char *dst) static void copy_file(const char *src, const char *dst)
...@@ -74,6 +75,9 @@ void test_index_tests__initialize(void) ...@@ -74,6 +75,9 @@ void test_index_tests__initialize(void)
void test_index_tests__cleanup(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) ...@@ -246,7 +250,7 @@ void test_index_tests__add(void)
git_index_free(index); git_index_free(index);
git_repository_free(repo); 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) void test_index_tests__add_from_workdir_to_a_bare_repository_returns_EBAREPO(void)
......
...@@ -11,6 +11,11 @@ static void transfer_cb(const git_transfer_progress *stats, void *payload) ...@@ -11,6 +11,11 @@ static void transfer_cb(const git_transfer_progress *stats, void *payload)
(*callcount)++; (*callcount)++;
} }
void test_network_fetchlocal__cleanup(void)
{
cl_fixture_cleanup("foo");
}
void test_network_fetchlocal__complete(void) void test_network_fetchlocal__complete(void)
{ {
git_repository *repo; git_repository *repo;
...@@ -33,7 +38,6 @@ void test_network_fetchlocal__complete(void) ...@@ -33,7 +38,6 @@ void test_network_fetchlocal__complete(void)
git_strarray_free(&refnames); git_strarray_free(&refnames);
git_remote_free(origin); git_remote_free(origin);
git_repository_free(repo); git_repository_free(repo);
cl_fixture_cleanup("foo");
} }
void test_network_fetchlocal__partial(void) void test_network_fetchlocal__partial(void)
......
...@@ -9,6 +9,26 @@ static git_packbuilder *_packbuilder; ...@@ -9,6 +9,26 @@ static git_packbuilder *_packbuilder;
static git_indexer *_indexer; static git_indexer *_indexer;
static git_vector _commits; static git_vector _commits;
static int _commits_is_initialized; 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) void test_pack_packbuilder__initialize(void)
{ {
...@@ -43,6 +63,12 @@ void test_pack_packbuilder__cleanup(void) ...@@ -43,6 +63,12 @@ void test_pack_packbuilder__cleanup(void)
git_repository_free(_repo); git_repository_free(_repo);
_repo = NULL; _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) static void seed_packbuilder(void)
...@@ -73,24 +99,10 @@ 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) void test_pack_packbuilder__create_pack(void)
{ {
git_transfer_progress stats; git_transfer_progress stats;
path_to_cleanup = "testpack.pack";
seed_packbuilder(); seed_packbuilder();
cl_git_pass(git_packbuilder_write(_packbuilder, "testpack.pack")); cl_git_pass(git_packbuilder_write(_packbuilder, "testpack.pack"));
...@@ -98,9 +110,8 @@ void test_pack_packbuilder__create_pack(void) ...@@ -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_new(&_indexer, "testpack.pack"));
cl_git_pass(git_indexer_run(_indexer, &stats)); cl_git_pass(git_indexer_run(_indexer, &stats));
cl_git_pass(git_indexer_write(_indexer)); 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; static git_transfer_progress stats;
...@@ -116,13 +127,11 @@ static int foreach_cb(void *buf, size_t len, void *payload) ...@@ -116,13 +127,11 @@ static int foreach_cb(void *buf, size_t len, void *payload)
void test_pack_packbuilder__foreach(void) void test_pack_packbuilder__foreach(void)
{ {
git_indexer_stream *idx; git_indexer_stream *idx;
git_oid oid;
seed_packbuilder(); seed_packbuilder();
cl_git_pass(git_indexer_stream_new(&idx, ".", NULL, NULL)); cl_git_pass(git_indexer_stream_new(&idx, ".", NULL, NULL));
cl_git_pass(git_packbuilder_foreach(_packbuilder, foreach_cb, idx)); cl_git_pass(git_packbuilder_foreach(_packbuilder, foreach_cb, idx));
cl_git_pass(git_indexer_stream_finalize(idx, &stats)); 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); git_indexer_stream_free(idx);
cleanup_pack(&oid);
} }
...@@ -32,6 +32,7 @@ void test_stash_save__cleanup(void) ...@@ -32,6 +32,7 @@ void test_stash_save__cleanup(void)
repo = NULL; repo = NULL;
cl_git_pass(git_futils_rmdir_r("stash", NULL, GIT_RMDIR_REMOVE_FILES)); 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) 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) ...@@ -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_stash_save(&stash_tip_oid, local, signature, NULL, GIT_STASH_DEFAULT));
git_repository_free(local); 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) void test_stash_save__can_stash_against_a_detached_head(void)
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "util.h" #include "util.h"
#include "path.h" #include "path.h"
static char *path_to_cleanup = NULL;
/** /**
* Initializer * Initializer
* *
...@@ -25,6 +27,10 @@ void test_status_worktree__initialize(void) ...@@ -25,6 +27,10 @@ void test_status_worktree__initialize(void)
void test_status_worktree__cleanup(void) void test_status_worktree__cleanup(void)
{ {
cl_git_sandbox_cleanup(); 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) ...@@ -446,7 +452,7 @@ void test_status_worktree__first_commit_in_progress(void)
git_index_free(index); git_index_free(index);
git_repository_free(repo); 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) ...@@ -596,7 +602,7 @@ void test_status_worktree__bracket_in_filename(void)
git_index_free(index); git_index_free(index);
git_repository_free(repo); git_repository_free(repo);
cl_fixture_cleanup("with_bracket"); path_to_cleanup = "with_bracket";
} }
void test_status_worktree__space_in_filename(void) void test_status_worktree__space_in_filename(void)
...@@ -661,7 +667,7 @@ 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_index_free(index);
git_repository_free(repo); git_repository_free(repo);
cl_fixture_cleanup("with_space"); path_to_cleanup = "with_space";
} }
static const char *filemode_paths[] = { static const char *filemode_paths[] = {
...@@ -772,7 +778,7 @@ void test_status_worktree__disable_pathspec_match(void) ...@@ -772,7 +778,7 @@ void test_status_worktree__disable_pathspec_match(void)
); );
git_repository_free(repo); 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) ...@@ -825,7 +831,7 @@ void test_status_worktree__new_staged_file_must_handle_crlf(void)
git_config_free(config); git_config_free(config);
git_index_free(index); git_index_free(index);
git_repository_free(repo); 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) void test_status_worktree__line_endings_dont_count_as_changes_with_autocrlf(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment