summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorlhchavez <lhchavez@lhchavez.com>2017-01-01 17:35:29 -0800
committerlhchavez <lhchavez@lhchavez.com>2017-01-01 17:35:29 -0800
commitdef644e48a3cd4afd0cee975d3214eeeb3671c99 (patch)
treed9f6165b633318bf8117704210e5841c68ca618c /tests
parentdb535d0a7dfa3e5c2ded4a408234623b0241de00 (diff)
downloadlibgit2-def644e48a3cd4afd0cee975d3214eeeb3671c99.tar.gz
Add a test
Diffstat (limited to 'tests')
-rw-r--r--tests/pack/indexer.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/pack/indexer.c b/tests/pack/indexer.c
index 49a106d98..15a9017f1 100644
--- a/tests/pack/indexer.c
+++ b/tests/pack/indexer.c
@@ -125,3 +125,43 @@ void test_pack_indexer__fix_thin(void)
git_indexer_free(idx);
}
}
+
+static int find_tmp_file_recurs(void *opaque, git_buf *path)
+{
+ int error = 0;
+ git_buf *first_tmp_file = opaque;
+ struct stat st;
+
+ if ((error = p_lstat_posixly(path->ptr, &st)) < 0)
+ return error;
+
+ if (S_ISDIR(st.st_mode))
+ return git_path_direach(path, 0, find_tmp_file_recurs, opaque);
+
+ /* This is the template that's used in git_futils_mktmp. */
+ if (strstr(git_buf_cstr(path), "_git2_") != NULL)
+ return git_buf_sets(first_tmp_file, git_buf_cstr(path));
+
+ return 0;
+}
+
+void test_pack_indexer__no_tmp_files(void)
+{
+ git_indexer *idx = NULL;
+ git_buf path = GIT_BUF_INIT;
+ git_buf first_tmp_file = GIT_BUF_INIT;
+
+ /* Precondition: there are no temporary files. */
+ cl_git_pass(git_buf_sets(&path, clar_sandbox_path()));
+ cl_git_pass(find_tmp_file_recurs(&first_tmp_file, &path));
+ if (git_buf_is_allocated(&first_tmp_file)) {
+ cl_warning("Found a temporary file before running the test");
+ cl_skip();
+ }
+
+ cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL, NULL));
+ git_indexer_free(idx);
+
+ cl_git_pass(find_tmp_file_recurs(&first_tmp_file, &path));
+ cl_check(!git_buf_is_allocated(&first_tmp_file));
+}