diff options
author | Edward Thomson <ethomson@github.com> | 2016-03-17 15:09:38 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@github.com> | 2016-03-23 17:17:02 -0400 |
commit | 6cd9573f54f0054618f23da585e0d8661b882e34 (patch) | |
tree | 6ea3edf31d6c8c5115d8db1a2538fcd134d11651 | |
parent | b6204260066843a00a271a11c2730a3069756d09 (diff) | |
download | libgit2-6cd9573f54f0054618f23da585e0d8661b882e34.tar.gz |
iterator: test that we can `advance_into` empty dirs
Prior iterator implementations returned `GIT_ENOTFOUND` when
trying to advance into empty directories. Ensure that we no longer
do that and simply handle them gracefully.
-rw-r--r-- | tests/repo/iterator.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/repo/iterator.c b/tests/repo/iterator.c index 158a6e453..b6017dae5 100644 --- a/tests/repo/iterator.c +++ b/tests/repo/iterator.c @@ -2041,6 +2041,65 @@ void test_repo_iterator__workdir_advance_over_with_pathlist(void) git_vector_free(&pathlist); } +static void expect_advance_into( + git_iterator *i, + const char *expected_path) +{ + const git_index_entry *entry; + int error; + + cl_git_pass(git_iterator_current(&entry, i)); + cl_assert_equal_s(expected_path, entry->path); + + if (S_ISDIR(entry->mode)) + error = git_iterator_advance_into(&entry, i); + else + error = git_iterator_advance(&entry, i); + + cl_assert(!error || error == GIT_ITEROVER); +} + +void test_repo_iterator__workdir_advance_into(void) +{ + git_iterator *i; + git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT; + + g_repo = cl_git_sandbox_init("icase"); + + i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE | + GIT_ITERATOR_DONT_AUTOEXPAND; + + cl_must_pass(p_mkdir("icase/Empty", 0777)); + + cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts)); + expect_advance_into(i, "B"); + expect_advance_into(i, "D"); + expect_advance_into(i, "Empty/"); + expect_advance_into(i, "F"); + expect_advance_into(i, "H"); + expect_advance_into(i, "J"); + expect_advance_into(i, "L/"); + expect_advance_into(i, "L/1"); + expect_advance_into(i, "L/B"); + expect_advance_into(i, "L/D"); + expect_advance_into(i, "L/a"); + expect_advance_into(i, "L/c"); + expect_advance_into(i, "a"); + expect_advance_into(i, "c"); + expect_advance_into(i, "e"); + expect_advance_into(i, "g"); + expect_advance_into(i, "i"); + expect_advance_into(i, "k/"); + expect_advance_into(i, "k/1"); + expect_advance_into(i, "k/B"); + expect_advance_into(i, "k/D"); + expect_advance_into(i, "k/a"); + expect_advance_into(i, "k/c"); + + cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i)); + git_iterator_free(i); +} + void test_repo_iterator__workdir_filelist_with_directory(void) { git_iterator *i; |