Commit 4c88198a by Edward Thomson

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.)
parent 0e0589fc
......@@ -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)
{
if (iter->end == NULL || iter->ended == true)
if (iter->end == NULL)
return false;
else if (iter->ended)
return true;
iter->ended = (iter->prefixcomp(path, iter->end) > 0);
return iter->ended;
......
......@@ -16,6 +16,17 @@ void test_repo_iterator__cleanup(void)
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(
git_iterator *i,
int expected_flat,
......@@ -57,6 +68,7 @@ static void expect_iterator_items(
break;
}
assert_at_end(i, v);
cl_assert_equal_i(expected_flat, count);
cl_git_pass(git_iterator_reset(i));
......@@ -103,6 +115,7 @@ static void expect_iterator_items(
break;
}
assert_at_end(i, v);
cl_assert_equal_i(expected_total, count);
}
......
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