Proper cleanup jeez
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
diff --git a/tests-clar/config/read.c b/tests-clar/config/read.c
index b603acb..9c02307 100644
--- a/tests-clar/config/read.c
+++ b/tests-clar/config/read.c
@@ -1,10 +1,5 @@
#include "clar_libgit2.h"
-void test_config_read__cleanup(void)
-{
- cl_fixture_cleanup("./empty");
-}
-
void test_config_read__simple_read(void)
{
git_config *cfg;
@@ -436,11 +431,18 @@ void test_config_read__simple_read_from_specific_level(void)
git_config_free(cfg);
}
+static void clean_empty_config(void *unused)
+{
+ GIT_UNUSED(unused);
+ cl_fixture_cleanup("./empty");
+}
+
void test_config_read__can_load_and_parse_an_empty_config_file(void)
{
git_config *cfg;
int i;
+ cl_set_cleanup(&clean_empty_config, NULL);
cl_git_mkfile("./empty", "");
cl_git_pass(git_config_open_ondisk(&cfg, "./empty"));
cl_assert_equal_i(GIT_ENOTFOUND, git_config_get_int32(&i, cfg, "nope.neither"));
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index d2ad71c..989734c 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -24,8 +24,6 @@ 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)
{
@@ -73,14 +71,6 @@ 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;
-}
-
-
void test_index_tests__empty_index(void)
{
git_index *index;
@@ -207,50 +197,57 @@ void test_index_tests__sort1(void)
git_index_free(index);
}
+static void cleanup_myrepo(void *opaque)
+{
+ GIT_UNUSED(opaque);
+ cl_fixture_cleanup("myrepo");
+}
+
void test_index_tests__add(void)
{
- git_index *index;
- git_filebuf file = GIT_FILEBUF_INIT;
- git_repository *repo;
- const git_index_entry *entry;
- git_oid id1;
+ git_index *index;
+ git_filebuf file = GIT_FILEBUF_INIT;
+ git_repository *repo;
+ const git_index_entry *entry;
+ git_oid id1;
- /* Intialize a new repository */
- cl_git_pass(git_repository_init(&repo, "./myrepo", 0));
+ cl_set_cleanup(&cleanup_myrepo, NULL);
- /* Ensure we're the only guy in the room */
- cl_git_pass(git_repository_index(&index, repo));
- cl_assert(git_index_entrycount(index) == 0);
+ /* Intialize a new repository */
+ cl_git_pass(git_repository_init(&repo, "./myrepo", 0));
- /* Create a new file in the working directory */
- cl_git_pass(git_futils_mkpath2file("myrepo/test.txt", 0777));
- cl_git_pass(git_filebuf_open(&file, "myrepo/test.txt", 0));
- cl_git_pass(git_filebuf_write(&file, "hey there\n", 10));
- cl_git_pass(git_filebuf_commit(&file, 0666));
+ /* Ensure we're the only guy in the room */
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
- /* Store the expected hash of the file/blob
- * This has been generated by executing the following
- * $ echo "hey there" | git hash-object --stdin
- */
- cl_git_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6"));
+ /* Create a new file in the working directory */
+ cl_git_pass(git_futils_mkpath2file("myrepo/test.txt", 0777));
+ cl_git_pass(git_filebuf_open(&file, "myrepo/test.txt", 0));
+ cl_git_pass(git_filebuf_write(&file, "hey there\n", 10));
+ cl_git_pass(git_filebuf_commit(&file, 0666));
- /* Add the new file to the index */
- cl_git_pass(git_index_add_from_workdir(index, "test.txt"));
+ /* Store the expected hash of the file/blob
+ * This has been generated by executing the following
+ * $ echo "hey there" | git hash-object --stdin
+ */
+ cl_git_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6"));
- /* Wow... it worked! */
- cl_assert(git_index_entrycount(index) == 1);
- entry = git_index_get_byindex(index, 0);
+ /* Add the new file to the index */
+ cl_git_pass(git_index_add_from_workdir(index, "test.txt"));
- /* And the built-in hashing mechanism worked as expected */
- cl_assert(git_oid_cmp(&id1, &entry->oid) == 0);
+ /* Wow... it worked! */
+ cl_assert(git_index_entrycount(index) == 1);
+ entry = git_index_get_byindex(index, 0);
- /* Test access by path instead of index */
- cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
- cl_assert(git_oid_cmp(&id1, &entry->oid) == 0);
+ /* And the built-in hashing mechanism worked as expected */
+ cl_assert(git_oid_cmp(&id1, &entry->oid) == 0);
- git_index_free(index);
- git_repository_free(repo);
- path_to_cleanup = "myrepo";
+ /* Test access by path instead of index */
+ cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
+ cl_assert(git_oid_cmp(&id1, &entry->oid) == 0);
+
+ git_index_free(index);
+ git_repository_free(repo);
}
void test_index_tests__add_from_workdir_to_a_bare_repository_returns_EBAREPO(void)