More filesystem iterator tests Refactors the helper function that builds a directory hierarchy and then made use of it to try more variations on filesystem iterator tests.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
diff --git a/tests-clar/repo/iterator.c b/tests-clar/repo/iterator.c
index ef9bfc3..2e53c48 100644
--- a/tests-clar/repo/iterator.c
+++ b/tests-clar/repo/iterator.c
@@ -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);
}