Rearrange clar submodule cleanup code
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
diff --git a/tests-clar/diff/submodules.c b/tests-clar/diff/submodules.c
index 9dcf819..167dedf 100644
--- a/tests-clar/diff/submodules.c
+++ b/tests-clar/diff/submodules.c
@@ -11,7 +11,6 @@ void test_diff_submodules__initialize(void)
void test_diff_submodules__cleanup(void)
{
- cleanup_fixture_submodules();
}
static void check_diff_patches_at_line(
diff --git a/tests-clar/status/submodules.c b/tests-clar/status/submodules.c
index 7bfef50..ef2888f 100644
--- a/tests-clar/status/submodules.c
+++ b/tests-clar/status/submodules.c
@@ -13,7 +13,6 @@ void test_status_submodules__initialize(void)
void test_status_submodules__cleanup(void)
{
- cleanup_fixture_submodules();
}
void test_status_submodules__api(void)
diff --git a/tests-clar/submodule/status.c b/tests-clar/submodule/status.c
index 7b29ac2..f1227a5 100644
--- a/tests-clar/submodule/status.c
+++ b/tests-clar/submodule/status.c
@@ -14,7 +14,6 @@ void test_submodule_status__initialize(void)
void test_submodule_status__cleanup(void)
{
- cleanup_fixture_submodules();
}
void test_submodule_status__unchanged(void)
diff --git a/tests-clar/submodule/submodule_helpers.c b/tests-clar/submodule/submodule_helpers.c
index a780752..3e79c77 100644
--- a/tests-clar/submodule/submodule_helpers.c
+++ b/tests-clar/submodule/submodule_helpers.c
@@ -83,6 +83,14 @@ void rewrite_gitmodules(const char *workdir)
git_buf_free(&path);
}
+static void cleanup_fixture_submodules(void *payload)
+{
+ cl_git_sandbox_cleanup(); /* either "submodules" or "submod2" */
+
+ if (payload)
+ cl_fixture_cleanup(payload);
+}
+
git_repository *setup_fixture_submodules(void)
{
git_repository *repo = cl_git_sandbox_init("submodules");
@@ -92,6 +100,8 @@ git_repository *setup_fixture_submodules(void)
rewrite_gitmodules(git_repository_workdir(repo));
p_rename("submodules/testrepo/.gitted", "submodules/testrepo/.git");
+ cl_set_cleanup(cleanup_fixture_submodules, "testrepo.git");
+
return repo;
}
@@ -106,14 +116,7 @@ git_repository *setup_fixture_submod2(void)
p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
p_rename("submod2/not/.gitted", "submod2/not/.git");
- return repo;
-}
+ cl_set_cleanup(cleanup_fixture_submodules, "submod2_target");
-void cleanup_fixture_submodules(void)
-{
- cl_git_sandbox_cleanup();
-
- /* just try to clean up both possible extras */
- cl_fixture_cleanup("testrepo.git");
- cl_fixture_cleanup("submod2_target");
+ return repo;
}
diff --git a/tests-clar/submodule/submodule_helpers.h b/tests-clar/submodule/submodule_helpers.h
index 1de15ca..610c407 100644
--- a/tests-clar/submodule/submodule_helpers.h
+++ b/tests-clar/submodule/submodule_helpers.h
@@ -1,5 +1,5 @@
extern void rewrite_gitmodules(const char *workdir);
+/* these will automatically set a cleanup callback */
extern git_repository *setup_fixture_submodules(void);
extern git_repository *setup_fixture_submod2(void);
-extern void cleanup_fixture_submodules(void);