Update init and clean for revwalk::basic tests The new tests don't always want to use the same fixture data as the old ones so this makes it configurable on a per-test basis.
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
diff --git a/tests-clar/revwalk/basic.c b/tests-clar/revwalk/basic.c
index 7c2fc00..cb8fcb9 100644
--- a/tests-clar/revwalk/basic.c
+++ b/tests-clar/revwalk/basic.c
@@ -98,27 +98,46 @@ static int test_walk(git_revwalk *walk, const git_oid *root,
return test_walk_only(walk, possible_results, results_count);
}
-static git_repository *_repo;
-static git_revwalk *_walk;
+static git_repository *_repo = NULL;
+static git_revwalk *_walk = NULL;
+static const char *_fixture = NULL;
void test_revwalk_basic__initialize(void)
{
- cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_revwalk_new(&_walk, _repo));
}
void test_revwalk_basic__cleanup(void)
{
git_revwalk_free(_walk);
- _walk = NULL;
- git_repository_free(_repo);
+
+ if (_fixture)
+ cl_git_sandbox_cleanup();
+ else
+ git_repository_free(_repo);
+
+ _fixture = NULL;
_repo = NULL;
+ _walk = NULL;
+}
+
+static void revwalk_basic_setup_walk(const char *fixture)
+{
+ if (fixture) {
+ _fixture = fixture;
+ _repo = cl_git_sandbox_init(fixture);
+ } else {
+ cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
+ }
+
+ cl_git_pass(git_revwalk_new(&_walk, _repo));
}
void test_revwalk_basic__sorting_modes(void)
{
git_oid id;
+ revwalk_basic_setup_walk(NULL);
+
git_oid_fromstr(&id, commit_head);
cl_git_pass(test_walk(_walk, &id, GIT_SORT_TIME, commit_sorting_time, 1));
@@ -132,6 +151,8 @@ void test_revwalk_basic__glob_heads(void)
int i = 0;
git_oid oid;
+ revwalk_basic_setup_walk(NULL);
+
cl_git_pass(git_revwalk_push_glob(_walk, "heads"));
while (git_revwalk_next(&oid, _walk) == 0) {
@@ -147,12 +168,9 @@ void test_revwalk_basic__glob_heads_with_invalid(void)
int i;
git_oid oid;
- test_revwalk_basic__cleanup();
+ revwalk_basic_setup_walk("testrepo");
- _repo = cl_git_sandbox_init("testrepo");
cl_git_mkfile("testrepo/.git/refs/heads/garbage", "not-a-ref");
-
- cl_git_pass(git_revwalk_new(&_walk, _repo));
cl_git_pass(git_revwalk_push_glob(_walk, "heads"));
for (i = 0; !git_revwalk_next(&oid, _walk); ++i)
@@ -160,8 +178,6 @@ void test_revwalk_basic__glob_heads_with_invalid(void)
/* git log --branches --oneline | wc -l => 16 */
cl_assert_equal_i(16, i);
-
- cl_fixture_cleanup("testrepo");
}
void test_revwalk_basic__push_head(void)
@@ -169,6 +185,8 @@ void test_revwalk_basic__push_head(void)
int i = 0;
git_oid oid;
+ revwalk_basic_setup_walk(NULL);
+
cl_git_pass(git_revwalk_push_head(_walk));
while (git_revwalk_next(&oid, _walk) == 0) {
@@ -184,6 +202,8 @@ void test_revwalk_basic__push_head_hide_ref(void)
int i = 0;
git_oid oid;
+ revwalk_basic_setup_walk(NULL);
+
cl_git_pass(git_revwalk_push_head(_walk));
cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed-test"));
@@ -200,6 +220,8 @@ void test_revwalk_basic__push_head_hide_ref_nobase(void)
int i = 0;
git_oid oid;
+ revwalk_basic_setup_walk(NULL);
+
cl_git_pass(git_revwalk_push_head(_walk));
cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed"));
@@ -215,12 +237,16 @@ void test_revwalk_basic__disallow_non_commit(void)
{
git_oid oid;
+ revwalk_basic_setup_walk(NULL);
+
cl_git_pass(git_oid_fromstr(&oid, "521d87c1ec3aef9824daf6d96cc0ae3710766d91"));
cl_git_fail(git_revwalk_push(_walk, &oid));
}
void test_revwalk_basic__push_range(void)
{
+ revwalk_basic_setup_walk(NULL);
+
git_revwalk_reset(_walk);
git_revwalk_sorting(_walk, 0);
cl_git_pass(git_revwalk_push_range(_walk, "9fd738e~2..9fd738e"));