diff options
| author | Ben Straub <bs@github.com> | 2013-01-03 09:10:38 -0800 |
|---|---|---|
| committer | Ben Straub <bs@github.com> | 2013-01-03 09:10:38 -0800 |
| commit | 600d8dbf6dccff5a9d86dd5ae01a53de46471796 (patch) | |
| tree | ac1d09e8e3ae38d96c071a8869544f0959cf06ec /tests-clar/pack/packbuilder.c | |
| parent | bffbeebbec2878c5329e63b40ecae3715423eac6 (diff) | |
| download | libgit2-600d8dbf6dccff5a9d86dd5ae01a53de46471796.tar.gz | |
Move test cleanup into cleanup functions
Diffstat (limited to 'tests-clar/pack/packbuilder.c')
| -rw-r--r-- | tests-clar/pack/packbuilder.c | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/tests-clar/pack/packbuilder.c b/tests-clar/pack/packbuilder.c index 31823eac1..c36b720e2 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); } |
