summaryrefslogtreecommitdiff
path: root/tests-clar
diff options
context:
space:
mode:
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/diff/iterator.c116
-rw-r--r--tests-clar/repo/iterator.c21
-rw-r--r--tests-clar/submodule/status.c5
3 files changed, 76 insertions, 66 deletions
diff --git a/tests-clar/diff/iterator.c b/tests-clar/diff/iterator.c
index 15b10465a..bbdae8ad1 100644
--- a/tests-clar/diff/iterator.c
+++ b/tests-clar/diff/iterator.c
@@ -31,7 +31,7 @@ static void tree_iterator_test(
git_tree *t;
git_iterator *i;
const git_index_entry *entry;
- int count = 0, count_post_reset = 0;
+ int error, count = 0, count_post_reset = 0;
git_repository *repo = cl_git_sandbox_init(sandbox);
cl_assert(t = resolve_commit_oid_to_tree(repo, treeish));
@@ -39,29 +39,30 @@ static void tree_iterator_test(
&i, t, GIT_ITERATOR_DONT_IGNORE_CASE, start, end));
/* test loop */
- cl_git_pass(git_iterator_current(&entry, i));
- while (entry != NULL) {
+ while (!(error = git_iterator_advance(&entry, i))) {
+ cl_assert(entry);
if (expected_values != NULL)
cl_assert_equal_s(expected_values[count], entry->path);
count++;
- cl_git_pass(git_iterator_advance(&entry, i));
}
+ cl_assert_equal_i(GIT_ITEROVER, error);
+ cl_assert(!entry);
+ cl_assert_equal_i(expected_count, count);
/* test reset */
cl_git_pass(git_iterator_reset(i, NULL, NULL));
- cl_git_pass(git_iterator_current(&entry, i));
- while (entry != NULL) {
+
+ while (!(error = git_iterator_advance(&entry, i))) {
+ cl_assert(entry);
if (expected_values != NULL)
cl_assert_equal_s(expected_values[count_post_reset], entry->path);
count_post_reset++;
- cl_git_pass(git_iterator_advance(&entry, i));
}
-
- git_iterator_free(i);
-
- cl_assert_equal_i(expected_count, count);
+ cl_assert_equal_i(GIT_ITEROVER, error);
+ cl_assert(!entry);
cl_assert_equal_i(count, count_post_reset);
+ git_iterator_free(i);
git_tree_free(t);
}
@@ -298,7 +299,7 @@ void test_diff_iterator__tree_special_functions(void)
git_iterator *i;
const git_index_entry *entry;
git_repository *repo = cl_git_sandbox_init("attr");
- int cases = 0;
+ int error, cases = 0;
const char *rootoid = "ce39a97a7fb1fa90bcf5e711249c1e507476ae0e";
t = resolve_commit_oid_to_tree(
@@ -307,9 +308,10 @@ void test_diff_iterator__tree_special_functions(void)
cl_git_pass(git_iterator_for_tree(
&i, t, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL));
- cl_git_pass(git_iterator_current(&entry, i));
- while (entry != NULL) {
+ while (!(error = git_iterator_advance(&entry, i))) {
+ cl_assert(entry);
+
if (strcmp(entry->path, "sub/file") == 0) {
cases++;
check_tree_entry(
@@ -338,11 +340,11 @@ void test_diff_iterator__tree_special_functions(void)
"2929de282ce999e95183aedac6451d3384559c4b",
rootoid, NULL);
}
-
- cl_git_pass(git_iterator_advance(&entry, i));
}
-
+ cl_assert_equal_i(GIT_ITEROVER, error);
+ cl_assert(!entry);
cl_assert_equal_i(4, cases);
+
git_iterator_free(i);
git_tree_free(t);
}
@@ -360,14 +362,15 @@ static void index_iterator_test(
git_index *index;
git_iterator *i;
const git_index_entry *entry;
- int count = 0;
+ int error, count = 0;
git_repository *repo = cl_git_sandbox_init(sandbox);
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_iterator_for_index(&i, index, 0, start, end));
- cl_git_pass(git_iterator_current(&entry, i));
- while (entry != NULL) {
+ while (!(error = git_iterator_advance(&entry, i))) {
+ cl_assert(entry);
+
if (expected_names != NULL)
cl_assert_equal_s(expected_names[count], entry->path);
@@ -378,13 +381,14 @@ static void index_iterator_test(
}
count++;
- cl_git_pass(git_iterator_advance(&entry, i));
}
+ cl_assert_equal_i(GIT_ITEROVER, error);
+ cl_assert(!entry);
+ cl_assert_equal_i(expected_count, count);
+
git_iterator_free(i);
git_index_free(index);
-
- cl_assert_equal_i(expected_count, count);
}
static const char *expected_index_0[] = {
@@ -535,12 +539,15 @@ static void workdir_iterator_test(
{
git_iterator *i;
const git_index_entry *entry;
- int count = 0, count_all = 0, count_all_post_reset = 0;
+ int error, count = 0, count_all = 0, count_all_post_reset = 0;
git_repository *repo = cl_git_sandbox_init(sandbox);
cl_git_pass(git_iterator_for_workdir(
&i, repo, GIT_ITERATOR_DONT_AUTOEXPAND, start, end));
- cl_git_pass(git_iterator_current(&entry, i));
+
+ error = git_iterator_current(&entry, i);
+ cl_assert((error == 0 && entry != NULL) ||
+ (error == GIT_ITEROVER && entry == NULL));
while (entry != NULL) {
int ignored = git_iterator_current_is_ignored(i);
@@ -560,29 +567,39 @@ static void workdir_iterator_test(
count++;
count_all++;
- cl_git_pass(git_iterator_advance(&entry, i));
+ error = git_iterator_advance(&entry, i);
+
+ cl_assert((error == 0 && entry != NULL) ||
+ (error == GIT_ITEROVER && entry == NULL));
}
+ cl_assert_equal_i(expected_count, count);
+ cl_assert_equal_i(expected_count + expected_ignores, count_all);
+
cl_git_pass(git_iterator_reset(i, NULL, NULL));
- cl_git_pass(git_iterator_current(&entry, i));
+
+ error = git_iterator_current(&entry, i);
+ cl_assert((error == 0 && entry != NULL) ||
+ (error == GIT_ITEROVER && entry == NULL));
while (entry != NULL) {
if (S_ISDIR(entry->mode)) {
cl_git_pass(git_iterator_advance_into(&entry, i));
continue;
}
+
if (expected_names != NULL)
cl_assert_equal_s(
expected_names[count_all_post_reset], entry->path);
count_all_post_reset++;
- cl_git_pass(git_iterator_advance(&entry, i));
- }
- git_iterator_free(i);
+ error = git_iterator_advance(&entry, i);
+ cl_assert(error == 0 || error == GIT_ITEROVER);
+ }
- cl_assert_equal_i(expected_count, count);
- cl_assert_equal_i(expected_count + expected_ignores, count_all);
cl_assert_equal_i(count_all, count_all_post_reset);
+
+ git_iterator_free(i);
}
void test_diff_iterator__workdir_0(void)
@@ -752,8 +769,10 @@ void test_diff_iterator__workdir_builtin_ignores(void)
{
/* it is possible to advance "into" a submodule */
cl_git_pass(git_iterator_advance_into(&entry, i));
- } else
- cl_git_pass(git_iterator_advance(&entry, i));
+ } else {
+ int error = git_iterator_advance(&entry, i);
+ cl_assert(!error || error == GIT_ITEROVER);
+ }
}
cl_assert(expected[idx].path == NULL);
@@ -766,7 +785,7 @@ static void check_wd_first_through_third_range(
{
git_iterator *i;
const git_index_entry *entry;
- int idx;
+ int error, idx;
static const char *expected[] = { "FIRST", "second", "THIRD", NULL };
cl_git_pass(git_iterator_for_workdir(
@@ -776,7 +795,8 @@ static void check_wd_first_through_third_range(
for (idx = 0; entry != NULL; ++idx) {
cl_assert_equal_s(expected[idx], entry->path);
- cl_git_pass(git_iterator_advance(&entry, i));
+ error = git_iterator_advance(&entry, i);
+ cl_assert(!error || error == GIT_ITEROVER);
}
cl_assert(expected[idx] == NULL);
@@ -814,8 +834,7 @@ static void check_tree_range(
{
git_tree *head;
git_iterator *i;
- const git_index_entry *entry;
- int count;
+ int error, count;
cl_git_pass(git_repository_head_tree(&head, repo));
@@ -824,13 +843,10 @@ static void check_tree_range(
ignore_case ? GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE,
start, end));
- cl_git_pass(git_iterator_current(&entry, i));
-
- for (count = 0; entry != NULL; ) {
- ++count;
- cl_git_pass(git_iterator_advance(&entry, i));
- }
+ for (count = 0; !(error = git_iterator_advance(NULL, i)); ++count)
+ /* count em up */;
+ cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert_equal_i(expected_count, count);
git_iterator_free(i);
@@ -872,8 +888,7 @@ static void check_index_range(
{
git_index *index;
git_iterator *i;
- const git_index_entry *entry;
- int count, caps;
+ int error, count, caps;
bool is_ignoring_case;
cl_git_pass(git_repository_index(&index, repo));
@@ -888,13 +903,10 @@ static void check_index_range(
cl_assert(git_iterator_ignore_case(i) == ignore_case);
- cl_git_pass(git_iterator_current(&entry, i));
-
- for (count = 0; entry != NULL; ) {
- ++count;
- cl_git_pass(git_iterator_advance(&entry, i));
- }
+ for (count = 0; !(error = git_iterator_advance(NULL, i)); ++count)
+ /* count em up */;
+ cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert_equal_i(expected_count, count);
git_iterator_free(i);
diff --git a/tests-clar/repo/iterator.c b/tests-clar/repo/iterator.c
index ab460735c..11a7d2a23 100644
--- a/tests-clar/repo/iterator.c
+++ b/tests-clar/repo/iterator.c
@@ -31,12 +31,11 @@ static void expect_iterator_items(
if (expected_flat < 0) { v = true; expected_flat = -expected_flat; }
if (expected_total < 0) { v = true; expected_total = -expected_total; }
- count = 0;
- cl_git_pass(git_iterator_current(&entry, i));
-
if (v) fprintf(stderr, "== %s ==\n", no_trees ? "notrees" : "trees");
- while (entry != NULL) {
+ count = 0;
+
+ while (!git_iterator_advance(&entry, i)) {
if (v) fprintf(stderr, " %s %07o\n", entry->path, (int)entry->mode);
if (no_trees)
@@ -54,8 +53,6 @@ static void expect_iterator_items(
cl_assert(entry->mode != GIT_FILEMODE_TREE);
}
- cl_git_pass(git_iterator_advance(&entry, i));
-
if (++count > expected_flat)
break;
}
@@ -93,10 +90,14 @@ static void expect_iterator_items(
/* could return NOTFOUND if directory is empty */
cl_assert(!error || error == GIT_ENOTFOUND);
- if (error == GIT_ENOTFOUND)
- cl_git_pass(git_iterator_advance(&entry, i));
- } else
- cl_git_pass(git_iterator_advance(&entry, i));
+ if (error == GIT_ENOTFOUND) {
+ error = git_iterator_advance(&entry, i);
+ cl_assert(!error || error == GIT_ITEROVER);
+ }
+ } else {
+ error = git_iterator_advance(&entry, i);
+ cl_assert(!error || error == GIT_ITEROVER);
+ }
if (++count > expected_total)
break;
diff --git a/tests-clar/submodule/status.c b/tests-clar/submodule/status.c
index 88f388052..39c83a0b7 100644
--- a/tests-clar/submodule/status.c
+++ b/tests-clar/submodule/status.c
@@ -370,12 +370,9 @@ void test_submodule_status__iterator(void)
cl_git_pass(git_iterator_for_workdir(&iter, g_repo,
GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
- cl_git_pass(git_iterator_current(&entry, iter));
- for (i = 0; entry; ++i) {
+ for (i = 0; !git_iterator_advance(&entry, iter); ++i)
cl_assert_equal_s(expected[i], entry->path);
- cl_git_pass(git_iterator_advance(&entry, iter));
- }
git_iterator_free(iter);