Commit 93d37a1d by Patrick Steinhardt

tests: core: improve symlink test coverage

Add two more tests to verify that we're not deleting symlink targets,
but the symlinks themselves. Furthermore, convert several `cl_skip`s on
Win32 to conditional skips depending on whether the clar sandbox
supports symlinks or not. Windows is grown up now and may allow
unprivileged symlinks if the machine has been configured accordingly.
parent 683ea2b0
...@@ -157,9 +157,8 @@ void test_core_filebuf__symlink_follow(void) ...@@ -157,9 +157,8 @@ void test_core_filebuf__symlink_follow(void)
git_filebuf file = GIT_FILEBUF_INIT; git_filebuf file = GIT_FILEBUF_INIT;
const char *dir = "linkdir", *source = "linkdir/link"; const char *dir = "linkdir", *source = "linkdir/link";
#ifdef GIT_WIN32 if (!git_path_supports_symlinks(clar_sandbox_path()))
cl_skip(); cl_skip();
#endif
cl_git_pass(p_mkdir(dir, 0777)); cl_git_pass(p_mkdir(dir, 0777));
cl_git_pass(p_symlink("target", source)); cl_git_pass(p_symlink("target", source));
...@@ -192,9 +191,8 @@ void test_core_filebuf__symlink_follow_absolute_paths(void) ...@@ -192,9 +191,8 @@ void test_core_filebuf__symlink_follow_absolute_paths(void)
git_filebuf file = GIT_FILEBUF_INIT; git_filebuf file = GIT_FILEBUF_INIT;
git_buf source = GIT_BUF_INIT, target = GIT_BUF_INIT; git_buf source = GIT_BUF_INIT, target = GIT_BUF_INIT;
#ifdef GIT_WIN32 if (!git_path_supports_symlinks(clar_sandbox_path()))
cl_skip(); cl_skip();
#endif
cl_git_pass(git_buf_joinpath(&source, clar_sandbox_path(), "linkdir/link")); cl_git_pass(git_buf_joinpath(&source, clar_sandbox_path(), "linkdir/link"));
cl_git_pass(git_buf_joinpath(&target, clar_sandbox_path(), "linkdir/target")); cl_git_pass(git_buf_joinpath(&target, clar_sandbox_path(), "linkdir/target"));
...@@ -221,9 +219,8 @@ void test_core_filebuf__symlink_depth(void) ...@@ -221,9 +219,8 @@ void test_core_filebuf__symlink_depth(void)
git_filebuf file = GIT_FILEBUF_INIT; git_filebuf file = GIT_FILEBUF_INIT;
const char *dir = "linkdir", *source = "linkdir/link"; const char *dir = "linkdir", *source = "linkdir/link";
#ifdef GIT_WIN32 if (!git_path_supports_symlinks(clar_sandbox_path()))
cl_skip(); cl_skip();
#endif
cl_git_pass(p_mkdir(dir, 0777)); cl_git_pass(p_mkdir(dir, 0777));
/* Endless loop */ /* Endless loop */
......
...@@ -66,3 +66,24 @@ void test_core_futils__write_hidden_file(void) ...@@ -66,3 +66,24 @@ void test_core_futils__write_hidden_file(void)
#endif #endif
} }
void test_core_futils__recursive_rmdir_keeps_symlink_targets(void)
{
if (!git_path_supports_symlinks(clar_sandbox_path()))
cl_skip();
cl_git_pass(git_futils_mkdir_r("a/b", 0777));
cl_git_pass(git_futils_mkdir_r("dir-target", 0777));
cl_git_mkfile("dir-target/file", "Contents");
cl_git_mkfile("file-target", "Contents");
cl_must_pass(p_symlink("dir-target", "a/symlink"));
cl_must_pass(p_symlink("file-target", "a/b/symlink"));
cl_git_pass(git_futils_rmdir_r("a", NULL, GIT_RMDIR_REMOVE_FILES));
cl_assert(git_path_exists("dir-target"));
cl_assert(git_path_exists("file-target"));
cl_must_pass(p_unlink("dir-target/file"));
cl_must_pass(p_rmdir("dir-target"));
cl_must_pass(p_unlink("file-target"));
}
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <locale.h> #include <locale.h>
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "futils.h"
#include "posix.h" #include "posix.h"
#include "userdiff.h" #include "userdiff.h"
...@@ -263,3 +264,24 @@ void test_core_posix__p_regcomp_compile_userdiff_regexps(void) ...@@ -263,3 +264,24 @@ void test_core_posix__p_regcomp_compile_userdiff_regexps(void)
cl_assert(!error); cl_assert(!error);
} }
} }
void test_core_posix__unlink_removes_symlink(void)
{
if (!git_path_supports_symlinks(clar_sandbox_path()))
clar__skip();
cl_git_mkfile("file", "Dummy file.");
cl_git_pass(git_futils_mkdir("dir", 0777, 0));
cl_must_pass(p_symlink("file", "file-symlink"));
cl_must_pass(p_symlink("dir", "dir-symlink"));
cl_must_pass(p_unlink("file-symlink"));
cl_must_pass(p_unlink("dir-symlink"));
cl_assert(git_path_exists("file"));
cl_assert(git_path_exists("dir"));
cl_must_pass(p_unlink("file"));
cl_must_pass(p_rmdir("dir"));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment