Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorschu <schu-github@schulog.org>2011-06-09 21:56:42 +0400
committerschu <schu-github@schulog.org>2011-07-06 14:25:27 +0400
commit7ea50f6077d0da28a471e8de2dc32dcdc994c5c6 (patch)
tree6ad45affa22be496b3d1afa2569cc389827917fb /tests
parent42b3a460976757dbe7c4755fd60c3f542a9fb1e2 (diff)
Add tests for git_futils_rmdir_resurs()
Signed-off-by: schu <schu-github@schulog.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/t00-core.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/t00-core.c b/tests/t00-core.c
index ba5188a43..0042da39c 100644
--- a/tests/t00-core.c
+++ b/tests/t00-core.c
@@ -474,6 +474,56 @@ BEGIN_TEST(filebuf2, "make sure git_filebuf_write writes large buffer correctly"
must_pass(p_unlink(test));
END_TEST
+static char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test";
+
+static int setup_empty_tmp_dir()
+{
+ char path[GIT_PATH_MAX];
+
+ if (mkdir(empty_tmp_dir, 0755))
+ return -1;
+
+ git_path_join(path, empty_tmp_dir, "/one");
+ if (mkdir(path, 0755))
+ return -1;
+
+ git_path_join(path, empty_tmp_dir, "/one/two_one");
+ if (mkdir(path, 0755))
+ return -1;
+
+ git_path_join(path, empty_tmp_dir, "/one/two_two");
+ if (mkdir(path, 0755))
+ return -1;
+
+ git_path_join(path, empty_tmp_dir, "/one/two_two/three");
+ if (mkdir(path, 0755))
+ return -1;
+
+ git_path_join(path, empty_tmp_dir, "/two");
+ if (mkdir(path, 0755))
+ return -1;
+
+ return 0;
+}
+
+BEGIN_TEST(rmdir0, "make sure empty dir can be deleted recusively")
+ must_pass(setup_empty_tmp_dir());
+ must_pass(git_futils_rmdir_recurs(empty_tmp_dir));
+END_TEST
+
+BEGIN_TEST(rmdir1, "make sure non-empty dir cannot be deleted recusively")
+ char file[GIT_PATH_MAX];
+
+ must_pass(setup_empty_tmp_dir());
+ git_path_join(file, empty_tmp_dir, "/two/file.txt");
+ must_pass(fd = p_creat(file, 0755));
+ must_pass(fd);
+ must_fail(git_futils_rmdir_recurs(empty_tmp_dir));
+ must_pass(p_close(fd));
+ must_pass(p_unlink(file));
+ must_pass(git_futils_rmdir_recurs(empty_tmp_dir));
+END_TEST
+
BEGIN_SUITE(core)
ADD_TEST(string0);
ADD_TEST(string1);
@@ -496,4 +546,7 @@ BEGIN_SUITE(core)
ADD_TEST(filebuf0);
ADD_TEST(filebuf1);
ADD_TEST(filebuf2);
+
+ ADD_TEST(rmdir0);
+ ADD_TEST(rmdir1);
END_SUITE