checkout test: better case-insensitive test on Mac On Mac OS, `realpath` is deficient in determining the actual filename on-disk as it will simply provide the string you gave it if that file exists, instead of returning the filename as it exists. Instead we must read the directory entries for the parent directory to get the canonical filename.
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
diff --git a/tests/checkout/icase.c b/tests/checkout/icase.c
index 82ad01e..510f542 100644
--- a/tests/checkout/icase.c
+++ b/tests/checkout/icase.c
@@ -6,6 +6,8 @@
#ifdef GIT_WIN32
# include <windows.h>
+#else
+# include <dirent.h>
#endif
static git_repository *repo;
@@ -40,7 +42,7 @@ void test_checkout_icase__cleanup(void)
cl_git_sandbox_cleanup();
}
-static char *test_realpath(const char *in)
+static char *get_filename(const char *in)
{
#ifdef GIT_WIN32
HANDLE fh;
@@ -65,7 +67,31 @@ static char *test_realpath(const char *in)
return filename;
#else
- return realpath(in, NULL);
+ char *search_dirname, *search_filename, *filename = NULL;
+ git_buf out = GIT_BUF_INIT;
+ DIR *dir;
+ struct dirent *de;
+
+ cl_assert(search_dirname = git_path_dirname(in));
+ cl_assert(search_filename = git_path_basename(in));
+
+ cl_assert(dir = opendir(search_dirname));
+
+ while ((de = readdir(dir))) {
+ if (strcasecmp(de->d_name, search_filename) == 0) {
+ git_buf_join(&out, '/', search_dirname, de->d_name);
+ filename = git_buf_detach(&out);
+ break;
+ }
+ }
+
+ closedir(dir);
+
+ git__free(search_dirname);
+ git__free(search_filename);
+ git_buf_free(&out);
+
+ return filename;
#endif
}
@@ -74,7 +100,7 @@ static void assert_name_is(const char *expected)
char *actual;
size_t actual_len, expected_len, start;
- cl_assert(actual = test_realpath(expected));
+ cl_assert(actual = get_filename(expected));
expected_len = strlen(expected);
actual_len = strlen(actual);