]> git.proxmox.com Git - libgit2.git/blobdiff - tests/core/rmdir.c
New upstream version 1.1.0+dfsg.1
[libgit2.git] / tests / core / rmdir.c
index f0b0bfa42931b63d49d9d75f1b9e0b41dd96f664..b436b97e061832e921460e2f263738d4e369ab3a 100644 (file)
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 
 static const char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test";
 
@@ -24,13 +24,27 @@ void test_core_rmdir__initialize(void)
        cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/two"));
        cl_must_pass(p_mkdir(path.ptr, 0777));
 
-       git_buf_free(&path);
+       git_buf_dispose(&path);
+}
+
+void test_core_rmdir__cleanup(void)
+{
+       if (git_path_exists(empty_tmp_dir))
+               cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_REMOVE_FILES));
 }
 
 /* make sure empty dir can be deleted recusively */
 void test_core_rmdir__delete_recursive(void)
 {
+       git_buf path = GIT_BUF_INIT;
+       cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one"));
+       cl_assert(git_path_exists(git_buf_cstr(&path)));
+
        cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
+
+       cl_assert(!git_path_exists(git_buf_cstr(&path)));
+
+       git_buf_dispose(&path);
 }
 
 /* make sure non-empty dir cannot be deleted recusively */
@@ -47,7 +61,15 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void)
        cl_must_pass(p_unlink(file.ptr));
        cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
 
-       git_buf_free(&file);
+       cl_assert(!git_path_exists(empty_tmp_dir));
+
+       git_buf_dispose(&file);
+}
+
+void test_core_rmdir__keep_base(void)
+{
+       cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_SKIP_ROOT));
+       cl_assert(git_path_exists(empty_tmp_dir));
 }
 
 void test_core_rmdir__can_skip_non_empty_dir(void)
@@ -64,7 +86,7 @@ void test_core_rmdir__can_skip_non_empty_dir(void)
        cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_REMOVE_FILES));
        cl_assert(git_path_exists(empty_tmp_dir) == false);
 
-       git_buf_free(&file);
+       git_buf_dispose(&file);
 }
 
 void test_core_rmdir__can_remove_empty_parents(void)
@@ -92,7 +114,7 @@ void test_core_rmdir__can_remove_empty_parents(void)
 
        cl_assert(git_path_exists(empty_tmp_dir) == true);
 
-       git_buf_free(&file);
+       git_buf_dispose(&file);
 
        cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
 }