Add tests for git_futils_rmdir_resurs() Signed-off-by: schu <schu-github@schulog.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
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