iterator: test that we're at the end of iteration

Ensure that we have hit the end of iteration; previously we tested
that we saw all the values that we expected to see.  We did not
then ensure that we were at the end of the iteration (and that there
were subsequently values in the iteration that we did *not* expect.)
This commit is contained in:
Edward Thomson 2016-03-16 10:17:20 -04:00
parent 0e0589fcc3
commit 4c88198a85
2 changed files with 16 additions and 1 deletions

View File

@ -437,8 +437,10 @@ GIT_INLINE(bool) iterator_has_started(git_iterator *iter, const char *path)
GIT_INLINE(bool) iterator_has_ended(git_iterator *iter, const char *path) GIT_INLINE(bool) iterator_has_ended(git_iterator *iter, const char *path)
{ {
if (iter->end == NULL || iter->ended == true) if (iter->end == NULL)
return false; return false;
else if (iter->ended)
return true;
iter->ended = (iter->prefixcomp(path, iter->end) > 0); iter->ended = (iter->prefixcomp(path, iter->end) > 0);
return iter->ended; return iter->ended;

View File

@ -16,6 +16,17 @@ void test_repo_iterator__cleanup(void)
g_repo = NULL; g_repo = NULL;
} }
static void assert_at_end(git_iterator *i, bool verbose)
{
const git_index_entry *end;
int error = git_iterator_advance(&end, i);
if (verbose && error != GIT_ITEROVER)
fprintf(stderr, "Expected end of iterator, got '%s'\n", end->path);
cl_git_fail_with(GIT_ITEROVER, error);
}
static void expect_iterator_items( static void expect_iterator_items(
git_iterator *i, git_iterator *i,
int expected_flat, int expected_flat,
@ -57,6 +68,7 @@ static void expect_iterator_items(
break; break;
} }
assert_at_end(i, v);
cl_assert_equal_i(expected_flat, count); cl_assert_equal_i(expected_flat, count);
cl_git_pass(git_iterator_reset(i)); cl_git_pass(git_iterator_reset(i));
@ -103,6 +115,7 @@ static void expect_iterator_items(
break; break;
} }
assert_at_end(i, v);
cl_assert_equal_i(expected_total, count); cl_assert_equal_i(expected_total, count);
} }