Commit 628dae8b1c87da412db2a7714fa6b0f3a4b1eea9

Edward Thomson 2018-10-19T03:14:35

tests: provide symlink support helper function

diff --git a/tests/checkout/index.c b/tests/checkout/index.c
index 270059b..4d86ba1 100644
--- a/tests/checkout/index.c
+++ b/tests/checkout/index.c
@@ -136,25 +136,6 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
 #endif
 }
 
-static bool supports_symlinks(const char *dir)
-{
-	git_buf path = GIT_BUF_INIT;
-	struct stat st;
-	bool supports_symlinks = 1;
-
-	cl_git_pass(git_buf_joinpath(&path, dir, "test"));
-
-	/* see if symlinks are supported in the "symlink" directory */
-	if (p_symlink("target", path.ptr) < 0 ||
-	    p_lstat(path.ptr, &st) < 0 ||
-	    ! (S_ISLNK(st.st_mode)))
-		supports_symlinks = 0;
-
-	git_buf_dispose(&path);
-
-	return supports_symlinks;
-}
-
 void test_checkout_index__honor_coresymlinks_default(void)
 {
 	git_repository *repo;
@@ -181,7 +162,7 @@ void test_checkout_index__honor_coresymlinks_default(void)
 	git_object_free(target);
 	git_repository_free(repo);
 
-	if (!supports_symlinks("symlink")) {
+	if (!filesystem_supports_symlinks("symlink/test")) {
 		check_file_contents("./symlink/link_to_new.txt", "new.txt");
 	} else {
 		char link_data[1024];
@@ -203,7 +184,7 @@ void test_checkout_index__coresymlinks_set_to_true_fails_when_unsupported(void)
 {
 	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
 
-	if (supports_symlinks("testrepo")) {
+	if (filesystem_supports_symlinks("testrepo/test")) {
 		cl_skip();
 	}
 
@@ -219,7 +200,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
 	char link_data[GIT_PATH_MAX];
 	size_t link_size = GIT_PATH_MAX;
 
-	if (!supports_symlinks("testrepo")) {
+	if (!filesystem_supports_symlinks("testrepo/test")) {
 		cl_skip();
 	}
 
diff --git a/tests/repo/init.c b/tests/repo/init.c
index 52cf157..677c238 100644
--- a/tests/repo/init.c
+++ b/tests/repo/init.c
@@ -249,15 +249,8 @@ void test_repo_init__detect_ignorecase(void)
 
 void test_repo_init__detect_symlinks(void)
 {
-	struct stat st;
-	bool no_symlinks;
-
-	no_symlinks = (p_symlink("target", "link") < 0 ||
-	    p_lstat("link", &st) < 0 ||
-	    ! (S_ISLNK(st.st_mode)));
-
 	assert_config_entry_on_init(
-	    "core.symlinks", no_symlinks ? false : GIT_ENOTFOUND);
+	    "core.symlinks", filesystem_supports_symlinks("link") ? GIT_ENOTFOUND : false);
 }
 
 void test_repo_init__detect_precompose_unicode_required(void)
diff --git a/tests/repo/repo_helpers.c b/tests/repo/repo_helpers.c
index 4dc5bfc..50a201e 100644
--- a/tests/repo/repo_helpers.c
+++ b/tests/repo/repo_helpers.c
@@ -20,3 +20,15 @@ void delete_head(git_repository* repo)
 
 	git_buf_dispose(&head_path);
 }
+
+int filesystem_supports_symlinks(const char *path)
+{
+	struct stat st;
+
+	if (p_symlink("target", path) < 0 ||
+		p_lstat(path, &st) < 0 ||
+		!(S_ISLNK(st.st_mode)))
+		return 0;
+
+	return 1;
+}
diff --git a/tests/repo/repo_helpers.h b/tests/repo/repo_helpers.h
index 6783d57..f184865 100644
--- a/tests/repo/repo_helpers.h
+++ b/tests/repo/repo_helpers.h
@@ -4,3 +4,4 @@
 
 extern void make_head_unborn(git_repository* repo, const char *target);
 extern void delete_head(git_repository* repo);
+extern int filesystem_supports_symlinks(const char *path);