Commit 7ea50f6077d0da28a471e8de2dc32dcdc994c5c6

schu 2011-06-09T19:56:42

Add tests for git_futils_rmdir_resurs() Signed-off-by: schu <schu-github@schulog.org>

diff --git a/tests/t00-core.c b/tests/t00-core.c
index ba5188a..0042da3 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