diriter: test we can iterate root Ensure that we can iterate the filesystem root and that paths come back well-formed, not with an additional '/'. (eg, when iterating `c:/`, expect that we do not get some path like `c://autoexec.bat`).
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
diff --git a/tests/core/dirent.c b/tests/core/dirent.c
index d95e441..2bd6026 100644
--- a/tests/core/dirent.c
+++ b/tests/core/dirent.c
@@ -275,3 +275,32 @@ void test_core_dirent__diriter_with_fullname(void)
check_counts(&sub);
}
+
+void test_core_dirent__diriter_at_directory_root(void)
+{
+ git_path_diriter diriter = GIT_PATH_DIRITER_INIT;
+ const char *sandbox_path, *path;
+ char *root_path;
+ size_t path_len;
+ int root_offset, error;
+
+ sandbox_path = clar_sandbox_path();
+ cl_assert((root_offset = git_path_root(sandbox_path)) >= 0);
+
+ cl_assert(root_path = git__calloc(1, root_offset + 2));
+ strncpy(root_path, sandbox_path, root_offset + 1);
+
+ cl_git_pass(git_path_diriter_init(&diriter, root_path, 0));
+
+ while ((error = git_path_diriter_next(&diriter)) == 0) {
+ cl_git_pass(git_path_diriter_fullpath(&path, &path_len, &diriter));
+
+ cl_assert(path_len > (size_t)(root_offset + 1));
+ cl_assert(path[root_offset+1] != '/');
+ }
+
+ cl_assert_equal_i(error, GIT_ITEROVER);
+
+ git_path_diriter_free(&diriter);
+ git__free(root_path);
+}