]> git.proxmox.com Git - libgit2.git/blobdiff - tests/core/posix.c
New upstream version 1.0.0+dfsg.1
[libgit2.git] / tests / core / posix.c
index 4e177b1f995fca8213e39e57447cf44f8c846524..1bb1e9c6b1d539be47e2e881a75718e59a88836d 100644 (file)
@@ -10,8 +10,8 @@
 #endif
 
 #include "clar_libgit2.h"
+#include "futils.h"
 #include "posix.h"
-#include "userdiff.h"
 
 void test_core_posix__initialize(void)
 {
@@ -92,10 +92,7 @@ void test_core_posix__inet_pton(void)
        cl_assert(p_inet_pton(AF_INET, "10.foo.bar.1", &addr) == 0);
 
        /* Test unsupported address families */
-       cl_git_fail(p_inet_pton(12, "52.472", NULL)); /* AF_DECnet */
-       cl_assert_equal_i(EAFNOSUPPORT, errno);
-
-       cl_git_fail(p_inet_pton(5, "315.124", NULL)); /* AF_CHAOS */
+       cl_git_fail(p_inet_pton(INT_MAX-1, "52.472", &addr));
        cl_assert_equal_i(EAFNOSUPPORT, errno);
 }
 
@@ -115,7 +112,7 @@ void test_core_posix__utimes(void)
        cl_git_mkfile("foo", "Dummy file.");
        cl_must_pass(p_utimes("foo", times));
 
-       p_stat("foo", &st);
+       cl_must_pass(p_stat("foo", &st));
        cl_assert_equal_i(1234567890, st.st_atime);
        cl_assert_equal_i(1234567890, st.st_mtime);
 
@@ -128,9 +125,9 @@ void test_core_posix__utimes(void)
 
        cl_must_pass(fd = p_open("foo", O_RDWR));
        cl_must_pass(p_futimes(fd, times));
-       p_close(fd);
+       cl_must_pass(p_close(fd));
 
-       p_stat("foo", &st);
+       cl_must_pass(p_stat("foo", &st));
        cl_assert_equal_i(1414141414, st.st_atime);
        cl_assert_equal_i(1414141414, st.st_mtime);
 
@@ -141,33 +138,101 @@ void test_core_posix__utimes(void)
        cl_must_pass(p_utimes("foo", NULL));
 
        curtime = time(NULL);
-       p_stat("foo", &st);
+       cl_must_pass(p_stat("foo", &st));
        cl_assert((st.st_atime - curtime) < 5);
        cl_assert((st.st_mtime - curtime) < 5);
 
-       p_unlink("foo");
+       cl_must_pass(p_unlink("foo"));
 }
 
-void test_core_posix__p_regcomp_compile_single_byte_regexps(void)
+void test_core_posix__unlink_removes_symlink(void)
 {
-       regex_t preg;
+       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_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", REG_EXTENDED));
+       cl_must_pass(p_unlink("file-symlink"));
+       cl_must_pass(p_unlink("dir-symlink"));
 
-       regfree(&preg);
+       cl_assert(git_path_exists("file"));
+       cl_assert(git_path_exists("dir"));
+
+       cl_must_pass(p_unlink("file"));
+       cl_must_pass(p_rmdir("dir"));
 }
 
-void test_core_posix__p_regcomp_compile_userdiff_regexps(void)
+void test_core_posix__symlink_resolves_to_correct_type(void)
 {
-       regex_t preg;
-       size_t idx;
+       git_buf contents = GIT_BUF_INIT;
 
-       for (idx = 0; idx < ARRAY_SIZE(builtin_defs); ++idx) {
-               git_diff_driver_definition ddef = builtin_defs[idx];
+       if (!git_path_supports_symlinks(clar_sandbox_path()))
+               clar__skip();
 
-               cl_must_pass(p_regcomp(&preg, ddef.fns, REG_EXTENDED | ddef.flags));
-               cl_must_pass(p_regcomp(&preg, ddef.words, REG_EXTENDED));
-       }
+       cl_must_pass(git_futils_mkdir("dir", 0777, 0));
+       cl_must_pass(git_futils_mkdir("file", 0777, 0));
+       cl_git_mkfile("dir/file", "symlink target");
+
+       cl_git_pass(p_symlink("file", "dir/link"));
+
+       cl_git_pass(git_futils_readbuffer(&contents, "dir/file"));
+       cl_assert_equal_s(contents.ptr, "symlink target");
+
+       cl_must_pass(p_unlink("dir/link"));
+       cl_must_pass(p_unlink("dir/file"));
+       cl_must_pass(p_rmdir("dir"));
+       cl_must_pass(p_rmdir("file"));
+
+       git_buf_dispose(&contents);
+}
+
+void test_core_posix__relative_symlink(void)
+{
+       git_buf contents = GIT_BUF_INIT;
+
+       if (!git_path_supports_symlinks(clar_sandbox_path()))
+               clar__skip();
+
+       cl_must_pass(git_futils_mkdir("dir", 0777, 0));
+       cl_git_mkfile("file", "contents");
+       cl_git_pass(p_symlink("../file", "dir/link"));
+       cl_git_pass(git_futils_readbuffer(&contents, "dir/link"));
+       cl_assert_equal_s(contents.ptr, "contents");
+
+       cl_must_pass(p_unlink("file"));
+       cl_must_pass(p_unlink("dir/link"));
+       cl_must_pass(p_rmdir("dir"));
+
+       git_buf_dispose(&contents);
+}
+
+void test_core_posix__symlink_to_file_across_dirs(void)
+{
+       git_buf contents = GIT_BUF_INIT;
+
+       if (!git_path_supports_symlinks(clar_sandbox_path()))
+               clar__skip();
+
+       /*
+        * Create a relative symlink that points into another
+        * directory. This used to not work on Win32, where we
+        * forgot to convert directory separators to
+        * Windows-style ones.
+        */
+       cl_must_pass(git_futils_mkdir("dir", 0777, 0));
+       cl_git_mkfile("dir/target", "symlink target");
+       cl_git_pass(p_symlink("dir/target", "link"));
+
+       cl_git_pass(git_futils_readbuffer(&contents, "dir/target"));
+       cl_assert_equal_s(contents.ptr, "symlink target");
+
+       cl_must_pass(p_unlink("dir/target"));
+       cl_must_pass(p_unlink("link"));
+       cl_must_pass(p_rmdir("dir"));
 
-       regfree(&preg);
+       git_buf_dispose(&contents);
 }