# endif
#endif
-#include <locale.h>
-
#include "clar_libgit2.h"
+#include "futils.h"
#include "posix.h"
-#include "userdiff.h"
void test_core_posix__initialize(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", &addr)); /* AF_DECnet */
- cl_assert_equal_i(EAFNOSUPPORT, errno);
-
- cl_git_fail(p_inet_pton(5, "315.124", &addr)); /* AF_CHAOS */
+ cl_git_fail(p_inet_pton(INT_MAX-1, "52.472", &addr));
cl_assert_equal_i(EAFNOSUPPORT, errno);
}
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);
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);
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_ignores_global_locale_ctype(void)
+void test_core_posix__unlink_removes_symlink(void)
{
- regex_t preg;
- int error = 0;
+ if (!git_path_supports_symlinks(clar_sandbox_path()))
+ clar__skip();
- const char* oldlocale = setlocale(LC_CTYPE, NULL);
+ cl_git_mkfile("file", "Dummy file.");
+ cl_git_pass(git_futils_mkdir("dir", 0777, 0));
- if (!setlocale(LC_CTYPE, "UTF-8") &&
- !setlocale(LC_CTYPE, "c.utf8") &&
- !setlocale(LC_CTYPE, "en_US.UTF-8"))
- cl_skip();
+ cl_must_pass(p_symlink("file", "file-symlink"));
+ cl_must_pass(p_symlink("dir", "dir-symlink"));
- if (MB_CUR_MAX == 1) {
- setlocale(LC_CTYPE, oldlocale);
- cl_fail("Expected locale to be switched to multibyte");
- }
+ 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"));
+}
+
+void test_core_posix__symlink_resolves_to_correct_type(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_must_pass(git_futils_mkdir("file", 0777, 0));
+ cl_git_mkfile("dir/file", "symlink target");
+
+ cl_git_pass(p_symlink("file", "dir/link"));
- p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", REG_EXTENDED);
- regfree(&preg);
+ cl_git_pass(git_futils_readbuffer(&contents, "dir/file"));
+ cl_assert_equal_s(contents.ptr, "symlink target");
- setlocale(LC_CTYPE, oldlocale);
+ 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"));
- cl_must_pass(error);
+ git_buf_dispose(&contents);
}
-void test_core_posix__p_regcomp_compile_userdiff_regexps(void)
+void test_core_posix__relative_symlink(void)
{
- 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];
- int error = 0;
- regex_t preg;
+ if (!git_path_supports_symlinks(clar_sandbox_path()))
+ clar__skip();
- error = p_regcomp(&preg, ddef.fns, REG_EXTENDED | ddef.flags);
- regfree(&preg);
- cl_must_pass(error);
+ 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");
- error = p_regcomp(&preg, ddef.words, REG_EXTENDED);
- regfree(&preg);
- cl_must_pass(error);
- }
+ 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"));
+
+ git_buf_dispose(&contents);
}