tests: sanitize file hierarchy after running rmdir tests Currently, we do not clean up after ourselves after tests in core::rmdir have created new files in the directory hierarchy. This may leave stale files and/or directories after having run tests, confusing subsequent tests that expect a pristine test environment. Most importantly, it may cause the test initialization to fail which expects being able to re-create the testing hierarchy before each test in case where another test hasn't cleaned up after itself. Fix the issue by adding a cleanup function that removes the temporary testing hierarchy after each test if it still exists.
diff --git a/tests/core/rmdir.c b/tests/core/rmdir.c
index 760cb5d..e00ec5c 100644
--- a/tests/core/rmdir.c
+++ b/tests/core/rmdir.c
@@ -27,6 +27,12 @@ void test_core_rmdir__initialize(void)
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)
{