summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Straub <bstraub@github.com>2012-07-13 15:52:27 -0700
committerBen Straub <bstraub@github.com>2012-07-13 15:52:27 -0700
commit280c7bbf13080c00fb563f8ecc08d9e606e3bd12 (patch)
tree9b69e66eca2f8cedf241e1abd0736613a558a017
parentdeac801de98be4974cfe806eb4bc072f34f81cc5 (diff)
downloadlibgit2-280c7bbf13080c00fb563f8ecc08d9e606e3bd12.tar.gz
Add checkout test suite.
Removed 'bare' option from test repository to allow checkout tests.
-rw-r--r--tests-clar/checkout/checkout.c68
-rw-r--r--tests-clar/resources/testrepo/.gitted/config2
2 files changed, 69 insertions, 1 deletions
diff --git a/tests-clar/checkout/checkout.c b/tests-clar/checkout/checkout.c
new file mode 100644
index 000000000..33a960313
--- /dev/null
+++ b/tests-clar/checkout/checkout.c
@@ -0,0 +1,68 @@
+#include "clar_libgit2.h"
+
+#include "git2/checkout.h"
+#include "repository.h"
+
+#define DO_LOCAL_TEST 0
+#define DO_LIVE_NETWORK_TESTS 1
+#define LIVE_REPO_URL "http://github.com/libgit2/node-gitteh"
+
+
+static git_repository *g_repo;
+
+void test_checkout_checkout__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("testrepo");
+}
+
+void test_checkout_checkout__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+
+static void test_file_contents(const char *path, const char *expectedcontents)
+{
+ int fd;
+ char buffer[1024] = {0};
+ fd = p_open(path, O_RDONLY);
+ cl_assert(fd);
+ cl_assert_equal_i(p_read(fd, buffer, 1024), strlen(expectedcontents));
+ cl_assert_equal_s(expectedcontents, buffer);
+ cl_git_pass(p_close(fd));
+}
+
+
+void test_checkout_checkout__bare(void)
+{
+ cl_git_sandbox_cleanup();
+ g_repo = cl_git_sandbox_init("testrepo.git");
+ cl_git_fail(git_checkout_force(g_repo, NULL));
+}
+
+void test_checkout_checkout__default(void)
+{
+ cl_git_pass(git_checkout_force(g_repo, NULL));
+ test_file_contents("./testrepo/README", "hey there\n");
+ test_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
+ test_file_contents("./testrepo/new.txt", "my new file\n");
+}
+
+
+void test_checkout_checkout__crlf(void)
+{
+ const char *attributes =
+ "branch_file.txt text eol=crlf\n"
+ "README text eol=cr\n"
+ "new.txt text eol=lf\n";
+ cl_git_mkfile("./testrepo/.gitattributes", attributes);
+ cl_git_pass(git_checkout_force(g_repo, NULL));
+ test_file_contents("./testrepo/README", "hey there\n");
+ test_file_contents("./testrepo/new.txt", "my new file\n");
+ test_file_contents("./testrepo/branch_file.txt", "hi\r\nbye!\r\n");
+}
+
+void test_checkout_checkout__stats(void)
+{
+ /* TODO */
+}
diff --git a/tests-clar/resources/testrepo/.gitted/config b/tests-clar/resources/testrepo/.gitted/config
index 1a5aacdfa..d0114012f 100644
--- a/tests-clar/resources/testrepo/.gitted/config
+++ b/tests-clar/resources/testrepo/.gitted/config
@@ -1,7 +1,7 @@
[core]
repositoryformatversion = 0
filemode = true
- bare = true
+ bare = false
logallrefupdates = true
[remote "test"]
url = git://github.com/libgit2/libgit2