]> git.proxmox.com Git - libgit2.git/commitdiff
More filesystem iterator tests
authorRussell Belfer <rb@github.com>
Thu, 18 Apr 2013 21:14:22 +0000 (14:14 -0700)
committerRussell Belfer <rb@github.com>
Thu, 18 Apr 2013 21:59:25 +0000 (14:59 -0700)
Refactors the helper function that builds a directory hierarchy
and then made use of it to try more variations on filesystem
iterator tests.

tests-clar/repo/iterator.c

index ef9bfc33d6c69803d0094152a3d2567928e09fa4..2e53c48d7271c790f67ee81e40d4da19fb08ce11 100644 (file)
@@ -755,47 +755,52 @@ void test_repo_iterator__workdir_icase(void)
        git_iterator_free(i);
 }
 
-void test_repo_iterator__workdir_depth(void)
+static void build_workdir_tree(const char *root, int dirs, int subs)
 {
        int i, j;
-       git_iterator *iter;
-       char buf[64];
-
-       g_repo = cl_git_sandbox_init("icase");
-
-       for (i = 0; i < 10; ++i) {
-               p_snprintf(buf, sizeof(buf), "icase/dir%02d", i);
-               cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH));
+       char buf[64], sub[64];
 
+       for (i = 0; i < dirs; ++i) {
                if (i % 2 == 0) {
-                       p_snprintf(buf, sizeof(buf), "icase/dir%02d/file", i);
+                       p_snprintf(buf, sizeof(buf), "%s/dir%02d", root, i);
+                       cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH));
+
+                       p_snprintf(buf, sizeof(buf), "%s/dir%02d/file", root, i);
                        cl_git_mkfile(buf, buf);
+                       buf[strlen(buf) - 5] = '\0';
+               } else {
+                       p_snprintf(buf, sizeof(buf), "%s/DIR%02d", root, i);
+                       cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH));
                }
 
-               for (j = 0; j < 10; ++j) {
-                       p_snprintf(buf, sizeof(buf), "icase/dir%02d/sub%02d", i, j);
-                       cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH));
+               for (j = 0; j < subs; ++j) {
+                       switch (j % 4) {
+                       case 0: p_snprintf(sub, sizeof(sub), "%s/sub%02d", buf, j); break;
+                       case 1: p_snprintf(sub, sizeof(sub), "%s/sUB%02d", buf, j); break;
+                       case 2: p_snprintf(sub, sizeof(sub), "%s/Sub%02d", buf, j); break;
+                       case 3: p_snprintf(sub, sizeof(sub), "%s/SUB%02d", buf, j); break;
+                       }
+                       cl_git_pass(git_futils_mkdir(sub, NULL, 0775, GIT_MKDIR_PATH));
 
                        if (j % 2 == 0) {
-                               p_snprintf(
-                                       buf, sizeof(buf), "icase/dir%02d/sub%02d/file", i, j);
-                               cl_git_mkfile(buf, buf);
+                               size_t sublen = strlen(sub);
+                               memcpy(&sub[sublen], "/file", sizeof("/file"));
+                               cl_git_mkfile(sub, sub);
+                               sub[sublen] = '\0';
                        }
                }
        }
+}
 
-       for (i = 1; i < 3; ++i) {
-               for (j = 0; j < 50; ++j) {
-                       p_snprintf(buf, sizeof(buf), "icase/dir%02d/sub01/moar%02d", i, j);
-                       cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH));
+void test_repo_iterator__workdir_depth(void)
+{
+       git_iterator *iter;
 
-                       if (j % 2 == 0) {
-                               p_snprintf(buf, sizeof(buf),
-                                       "icase/dir%02d/sub01/moar%02d/file", i, j);
-                               cl_git_mkfile(buf, buf);
-                       }
-               }
-       }
+       g_repo = cl_git_sandbox_init("icase");
+
+       build_workdir_tree("icase", 10, 10);
+       build_workdir_tree("icase/dir01/Sub01", 50, 0);
+       build_workdir_tree("icase/DIR02/Sub01", 50, 0);
 
        /* auto expand with no tree entries */
        cl_git_pass(git_iterator_for_workdir(&iter, g_repo, 0, NULL, NULL));
@@ -812,8 +817,42 @@ void test_repo_iterator__workdir_depth(void)
 void test_repo_iterator__fs(void)
 {
        git_iterator *i;
-       static const char *expect_subdir[] = {
+       static const char *expect_base[] = {
+               "DIR01/Sub02/file",
+               "DIR01/sub00/file",
                "current_file",
+               "dir00/Sub02/file",
+               "dir00/file",
+               "dir00/sub00/file",
+               "modified_file",
+               "new_file",
+               NULL,
+       };
+       static const char *expect_trees[] = {
+               "DIR01/",
+               "DIR01/SUB03/",
+               "DIR01/Sub02/",
+               "DIR01/Sub02/file",
+               "DIR01/sUB01/",
+               "DIR01/sub00/",
+               "DIR01/sub00/file",
+               "current_file",
+               "dir00/",
+               "dir00/SUB03/",
+               "dir00/Sub02/",
+               "dir00/Sub02/file",
+               "dir00/file",
+               "dir00/sUB01/",
+               "dir00/sub00/",
+               "dir00/sub00/file",
+               "modified_file",
+               "new_file",
+               NULL,
+       };
+       static const char *expect_noauto[] = {
+               "DIR01/",
+               "current_file",
+               "dir00/",
                "modified_file",
                "new_file",
                NULL,
@@ -821,16 +860,49 @@ void test_repo_iterator__fs(void)
 
        g_repo = cl_git_sandbox_init("status");
 
+       build_workdir_tree("status/subdir", 2, 4);
+
        cl_git_pass(git_iterator_for_filesystem(
                &i, "status/subdir", 0, NULL, NULL));
-       expect_iterator_items(i, 3, expect_subdir, 3, expect_subdir);
+       expect_iterator_items(i, 8, expect_base, 8, expect_base);
+       git_iterator_free(i);
+
+       cl_git_pass(git_iterator_for_filesystem(
+               &i, "status/subdir", GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+       expect_iterator_items(i, 18, expect_trees, 18, expect_trees);
+       git_iterator_free(i);
+
+       cl_git_pass(git_iterator_for_filesystem(
+               &i, "status/subdir", GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+       expect_iterator_items(i, 5, expect_noauto, 18, expect_trees);
+       git_iterator_free(i);
+
+       git__tsort((void **)expect_base, 8, (git__tsort_cmp)git__strcasecmp);
+       git__tsort((void **)expect_trees, 18, (git__tsort_cmp)git__strcasecmp);
+       git__tsort((void **)expect_noauto, 5, (git__tsort_cmp)git__strcasecmp);
+
+       cl_git_pass(git_iterator_for_filesystem(
+               &i, "status/subdir", GIT_ITERATOR_IGNORE_CASE, NULL, NULL));
+       expect_iterator_items(i, 8, expect_base, 8, expect_base);
+       git_iterator_free(i);
+
+       cl_git_pass(git_iterator_for_filesystem(
+               &i, "status/subdir", GIT_ITERATOR_IGNORE_CASE |
+               GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+       expect_iterator_items(i, 18, expect_trees, 18, expect_trees);
+       git_iterator_free(i);
+
+       cl_git_pass(git_iterator_for_filesystem(
+               &i, "status/subdir", GIT_ITERATOR_IGNORE_CASE |
+               GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+       expect_iterator_items(i, 5, expect_noauto, 18, expect_trees);
        git_iterator_free(i);
 }
 
 void test_repo_iterator__fs2(void)
 {
        git_iterator *i;
-       static const char *expect_subdir[] = {
+       static const char *expect_base[] = {
                "heads/br2",
                "heads/dir",
                "heads/master",
@@ -849,6 +921,6 @@ void test_repo_iterator__fs2(void)
 
        cl_git_pass(git_iterator_for_filesystem(
                &i, "testrepo/.git/refs", 0, NULL, NULL));
-       expect_iterator_items(i, 11, expect_subdir, 11, expect_subdir);
+       expect_iterator_items(i, 11, expect_base, 11, expect_base);
        git_iterator_free(i);
 }