Commit ad2737185d1b09e90154c18d5d7b98e1fb4bbafe

Patrick Steinhardt 2018-10-04T10:32:07

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)
 {