summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-09-09 01:37:06 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-09-09 01:37:06 +0200
commit53ba8c9e8b834eb005daba76d7ee319cde990248 (patch)
tree5c4882d4ffbf16b7b4ad1de567d70dc14c12448b
parentc1770aeb8b6893d38ba2721a1cdd9ba0d6ed610c (diff)
parent8e736a73cac81f09197eca32bf578f74ab21e97e (diff)
downloadlibgit2-53ba8c9e8b834eb005daba76d7ee319cde990248.tar.gz
Merge pull request #3415 from ethomson/lock_hidden
filebuf: ensure we can lock a hidden file
-rw-r--r--tests/core/filebuf.c26
-rw-r--r--tests/core/futils.c68
2 files changed, 94 insertions, 0 deletions
diff --git a/tests/core/filebuf.c b/tests/core/filebuf.c
index 39d98ff7e..915e3cc34 100644
--- a/tests/core/filebuf.c
+++ b/tests/core/filebuf.c
@@ -204,3 +204,29 @@ void test_core_filebuf__symlink_depth(void)
cl_git_pass(git_futils_rmdir_r(dir, NULL, GIT_RMDIR_REMOVE_FILES));
}
+
+void test_core_filebuf__hidden_file(void)
+{
+#ifndef GIT_WIN32
+ cl_skip();
+#else
+ git_filebuf file = GIT_FILEBUF_INIT;
+ char *dir = "hidden", *test = "hidden/test";
+ bool hidden;
+
+ cl_git_pass(p_mkdir(dir, 0666));
+ cl_git_mkfile(test, "dummy content");
+
+ cl_git_pass(git_win32__set_hidden(test, true));
+ cl_git_pass(git_win32__hidden(&hidden, test));
+ cl_assert(hidden);
+
+ cl_git_pass(git_filebuf_open(&file, test, 0, 0666));
+
+ cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
+
+ cl_git_pass(git_filebuf_commit(&file));
+
+ git_filebuf_cleanup(&file);
+#endif
+}
diff --git a/tests/core/futils.c b/tests/core/futils.c
new file mode 100644
index 000000000..e7f7154ed
--- /dev/null
+++ b/tests/core/futils.c
@@ -0,0 +1,68 @@
+#include "clar_libgit2.h"
+#include "fileops.h"
+
+// Fixture setup and teardown
+void test_core_futils__initialize(void)
+{
+ cl_must_pass(p_mkdir("futils", 0777));
+}
+
+void test_core_futils__cleanup(void)
+{
+ cl_fixture_cleanup("futils");
+}
+
+void test_core_futils__writebuffer(void)
+{
+ git_buf out = GIT_BUF_INIT,
+ append = GIT_BUF_INIT;
+
+ /* create a new file */
+ git_buf_puts(&out, "hello!\n");
+ git_buf_printf(&out, "this is a %s\n", "test");
+
+ cl_git_pass(git_futils_writebuffer(&out, "futils/test-file", O_RDWR|O_CREAT, 0666));
+
+ cl_assert_equal_file(out.ptr, out.size, "futils/test-file");
+
+ /* append some more data */
+ git_buf_puts(&append, "And some more!\n");
+ git_buf_put(&out, append.ptr, append.size);
+
+ cl_git_pass(git_futils_writebuffer(&append, "futils/test-file", O_RDWR|O_APPEND, 0666));
+
+ cl_assert_equal_file(out.ptr, out.size, "futils/test-file");
+
+ git_buf_free(&out);
+ git_buf_free(&append);
+}
+
+void test_core_futils__write_hidden_file(void)
+{
+#ifndef GIT_WIN32
+ cl_skip();
+#else
+ git_buf out = GIT_BUF_INIT, append = GIT_BUF_INIT;
+ bool hidden;
+
+ git_buf_puts(&out, "hidden file.\n");
+ git_futils_writebuffer(&out, "futils/test-file", O_RDWR | O_CREAT, 0666);
+
+ cl_git_pass(git_win32__set_hidden("futils/test-file", true));
+
+ /* append some more data */
+ git_buf_puts(&append, "And some more!\n");
+ git_buf_put(&out, append.ptr, append.size);
+
+ cl_git_pass(git_futils_writebuffer(&append, "futils/test-file", O_RDWR | O_APPEND, 0666));
+
+ cl_assert_equal_file(out.ptr, out.size, "futils/test-file");
+
+ cl_git_pass(git_win32__hidden(&hidden, "futils/test-file"));
+ cl_assert(hidden);
+
+ git_buf_free(&out);
+ git_buf_free(&append);
+#endif
+}
+