Commit 4cee9b86 by Russell Belfer

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.
parent 989710d9
...@@ -98,27 +98,46 @@ static int test_walk(git_revwalk *walk, const git_oid *root, ...@@ -98,27 +98,46 @@ static int test_walk(git_revwalk *walk, const git_oid *root,
return test_walk_only(walk, possible_results, results_count); return test_walk_only(walk, possible_results, results_count);
} }
static git_repository *_repo; static git_repository *_repo = NULL;
static git_revwalk *_walk; static git_revwalk *_walk = NULL;
static const char *_fixture = NULL;
void test_revwalk_basic__initialize(void) 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) void test_revwalk_basic__cleanup(void)
{ {
git_revwalk_free(_walk); 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; _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) void test_revwalk_basic__sorting_modes(void)
{ {
git_oid id; git_oid id;
revwalk_basic_setup_walk(NULL);
git_oid_fromstr(&id, commit_head); git_oid_fromstr(&id, commit_head);
cl_git_pass(test_walk(_walk, &id, GIT_SORT_TIME, commit_sorting_time, 1)); 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) ...@@ -132,6 +151,8 @@ void test_revwalk_basic__glob_heads(void)
int i = 0; int i = 0;
git_oid oid; git_oid oid;
revwalk_basic_setup_walk(NULL);
cl_git_pass(git_revwalk_push_glob(_walk, "heads")); cl_git_pass(git_revwalk_push_glob(_walk, "heads"));
while (git_revwalk_next(&oid, _walk) == 0) { while (git_revwalk_next(&oid, _walk) == 0) {
...@@ -147,12 +168,9 @@ void test_revwalk_basic__glob_heads_with_invalid(void) ...@@ -147,12 +168,9 @@ void test_revwalk_basic__glob_heads_with_invalid(void)
int i; int i;
git_oid oid; 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_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")); cl_git_pass(git_revwalk_push_glob(_walk, "heads"));
for (i = 0; !git_revwalk_next(&oid, _walk); ++i) for (i = 0; !git_revwalk_next(&oid, _walk); ++i)
...@@ -160,8 +178,6 @@ void test_revwalk_basic__glob_heads_with_invalid(void) ...@@ -160,8 +178,6 @@ void test_revwalk_basic__glob_heads_with_invalid(void)
/* git log --branches --oneline | wc -l => 16 */ /* git log --branches --oneline | wc -l => 16 */
cl_assert_equal_i(16, i); cl_assert_equal_i(16, i);
cl_fixture_cleanup("testrepo");
} }
void test_revwalk_basic__push_head(void) void test_revwalk_basic__push_head(void)
...@@ -169,6 +185,8 @@ void test_revwalk_basic__push_head(void) ...@@ -169,6 +185,8 @@ void test_revwalk_basic__push_head(void)
int i = 0; int i = 0;
git_oid oid; git_oid oid;
revwalk_basic_setup_walk(NULL);
cl_git_pass(git_revwalk_push_head(_walk)); cl_git_pass(git_revwalk_push_head(_walk));
while (git_revwalk_next(&oid, _walk) == 0) { while (git_revwalk_next(&oid, _walk) == 0) {
...@@ -184,6 +202,8 @@ void test_revwalk_basic__push_head_hide_ref(void) ...@@ -184,6 +202,8 @@ void test_revwalk_basic__push_head_hide_ref(void)
int i = 0; int i = 0;
git_oid oid; git_oid oid;
revwalk_basic_setup_walk(NULL);
cl_git_pass(git_revwalk_push_head(_walk)); cl_git_pass(git_revwalk_push_head(_walk));
cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed-test")); 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) ...@@ -200,6 +220,8 @@ void test_revwalk_basic__push_head_hide_ref_nobase(void)
int i = 0; int i = 0;
git_oid oid; git_oid oid;
revwalk_basic_setup_walk(NULL);
cl_git_pass(git_revwalk_push_head(_walk)); cl_git_pass(git_revwalk_push_head(_walk));
cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed")); cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed"));
...@@ -215,12 +237,16 @@ void test_revwalk_basic__disallow_non_commit(void) ...@@ -215,12 +237,16 @@ void test_revwalk_basic__disallow_non_commit(void)
{ {
git_oid oid; git_oid oid;
revwalk_basic_setup_walk(NULL);
cl_git_pass(git_oid_fromstr(&oid, "521d87c1ec3aef9824daf6d96cc0ae3710766d91")); cl_git_pass(git_oid_fromstr(&oid, "521d87c1ec3aef9824daf6d96cc0ae3710766d91"));
cl_git_fail(git_revwalk_push(_walk, &oid)); cl_git_fail(git_revwalk_push(_walk, &oid));
} }
void test_revwalk_basic__push_range(void) void test_revwalk_basic__push_range(void)
{ {
revwalk_basic_setup_walk(NULL);
git_revwalk_reset(_walk); git_revwalk_reset(_walk);
git_revwalk_sorting(_walk, 0); git_revwalk_sorting(_walk, 0);
cl_git_pass(git_revwalk_push_range(_walk, "9fd738e~2..9fd738e")); cl_git_pass(git_revwalk_push_range(_walk, "9fd738e~2..9fd738e"));
......
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