summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests-clay/clay_helpers.c18
-rw-r--r--tests-clay/clay_libgit2.h3
-rw-r--r--tests-clay/index/read_tree.c7
-rw-r--r--tests-clay/index/rename.c3
-rw-r--r--tests-clay/object/commit/commitstagedfile.c12
-rw-r--r--tests-clay/status/single.c11
-rw-r--r--tests-clay/testlib.c20
-rw-r--r--tests-clay/testlib.h6
8 files changed, 27 insertions, 53 deletions
diff --git a/tests-clay/clay_helpers.c b/tests-clay/clay_helpers.c
index f1b83ca3a..081fb087e 100644
--- a/tests-clay/clay_helpers.c
+++ b/tests-clay/clay_helpers.c
@@ -1,4 +1,5 @@
#include "clay_libgit2.h"
+#include "posix.h"
void clay_on_init(void)
{
@@ -9,3 +10,20 @@ void clay_on_shutdown(void)
{
git_threads_shutdown();
}
+
+void cl_git_mkfile(const char *filename, const char *content)
+{
+ int fd;
+
+ fd = p_creat(filename, 0666);
+ cl_assert(fd != 0);
+
+ if (content) {
+ cl_must_pass(p_write(fd, content, strlen(content)));
+ } else {
+ cl_must_pass(p_write(fd, filename, strlen(filename)));
+ cl_must_pass(p_write(fd, "\n", 1));
+ }
+
+ cl_must_pass(p_close(fd));
+}
diff --git a/tests-clay/clay_libgit2.h b/tests-clay/clay_libgit2.h
index d0faf9a90..1364eb06b 100644
--- a/tests-clay/clay_libgit2.h
+++ b/tests-clay/clay_libgit2.h
@@ -51,4 +51,7 @@ GIT_INLINE(void) cl_assert_strequal_internal(
#define REP256(STR) REP16(REP16(STR))
#define REP1024(STR) REP4(REP256(STR))
+/* Write the contents of a buffer to disk */
+void cl_git_mkfile(const char *filename, const char *content);
+
#endif
diff --git a/tests-clay/index/read_tree.c b/tests-clay/index/read_tree.c
index d884c8d51..b3f4a6655 100644
--- a/tests-clay/index/read_tree.c
+++ b/tests-clay/index/read_tree.c
@@ -1,5 +1,4 @@
#include "clay_libgit2.h"
-#include "testlib.h"
#include "posix.h"
/* Test that reading and writing a tree is a no-op */
@@ -21,9 +20,9 @@ void test_index_read_tree__read_write_involution(void)
p_mkdir("./read_tree/abc", 0700);
/* Sort order: '-' < '/' < '_' */
- file_create("./read_tree/abc-d", NULL);
- file_create("./read_tree/abc/d", NULL);
- file_create("./read_tree/abc_d", NULL);
+ cl_git_mkfile("./read_tree/abc-d", NULL);
+ cl_git_mkfile("./read_tree/abc/d", NULL);
+ cl_git_mkfile("./read_tree/abc_d", NULL);
cl_git_pass(git_index_add(index, "abc-d", 0));
cl_git_pass(git_index_add(index, "abc_d", 0));
diff --git a/tests-clay/index/rename.c b/tests-clay/index/rename.c
index c949fa7f2..104982a15 100644
--- a/tests-clay/index/rename.c
+++ b/tests-clay/index/rename.c
@@ -1,5 +1,4 @@
#include "clay_libgit2.h"
-#include "testlib.h"
#include "posix.h"
void test_index_rename__single_file(void)
@@ -17,7 +16,7 @@ void test_index_rename__single_file(void)
cl_assert(git_index_entrycount(index) == 0);
- file_create("./rename/lame.name.txt", "new_file\n");
+ cl_git_mkfile("./rename/lame.name.txt", "new_file\n");
/* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */
cl_git_pass(git_index_add(index, "lame.name.txt", 0));
diff --git a/tests-clay/object/commit/commitstagedfile.c b/tests-clay/object/commit/commitstagedfile.c
index 80ae3d549..fd149bfc3 100644
--- a/tests-clay/object/commit/commitstagedfile.c
+++ b/tests-clay/object/commit/commitstagedfile.c
@@ -3,16 +3,6 @@
static git_repository *repo;
-static void file_create(const char *filename, const char *content)
-{
- int fd;
-
- fd = p_creat(filename, 0666);
- cl_assert(fd != 0);
- cl_git_pass(p_write(fd, content, strlen(content)));
- cl_git_pass(p_close(fd));
-}
-
void test_object_commit_commitstagedfile__initialize(void)
{
cl_fixture("treebuilder");
@@ -79,7 +69,7 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
/*
* Add a new file to the index
*/
- file_create("treebuilder/test.txt", "test\n");
+ cl_git_mkfile("treebuilder/test.txt", "test\n");
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add(index, "test.txt", 0));
diff --git a/tests-clay/status/single.c b/tests-clay/status/single.c
index 4fd6e6ff4..c290bddff 100644
--- a/tests-clay/status/single.c
+++ b/tests-clay/status/single.c
@@ -7,15 +7,6 @@ cleanup__remove_file(void *_file)
cl_must_pass(p_unlink((char *)_file));
}
-static void
-file_create(const char *filename, const char *content)
-{
- int fd = p_creat(filename, 0666);
- cl_assert(fd >= 0);
- cl_must_pass(p_write(fd, content, strlen(content)));
- cl_must_pass(p_close(fd));
-}
-
/* test retrieving OID from a file apart from the ODB */
void test_status_single__hash_single_file(void)
{
@@ -27,7 +18,7 @@ void test_status_single__hash_single_file(void)
/* initialization */
git_oid_fromstr(&expected_id, file_hash);
- file_create(file_name, file_contents);
+ cl_git_mkfile(file_name, file_contents);
cl_set_cleanup(&cleanup__remove_file, (void *)file_name);
cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJ_BLOB));
diff --git a/tests-clay/testlib.c b/tests-clay/testlib.c
deleted file mode 100644
index d45fc2c26..000000000
--- a/tests-clay/testlib.c
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "clay.h"
-#include "testlib.h"
-#include "posix.h"
-
-void file_create(const char *filename, const char *content)
-{
- int fd;
-
- fd = p_creat(filename, 0666);
- cl_assert(fd != 0);
-
- if (content) {
- cl_must_pass(p_write(fd, content, strlen(content)));
- } else {
- cl_must_pass(p_write(fd, filename, strlen(filename)));
- cl_must_pass(p_write(fd, "\n", 1));
- }
-
- cl_must_pass(p_close(fd));
-}
diff --git a/tests-clay/testlib.h b/tests-clay/testlib.h
deleted file mode 100644
index 2e8867c12..000000000
--- a/tests-clay/testlib.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef INCLUDE_testlib_h__
-#define INCLUDE_testlib_h__
-
-void file_create(const char *filename, const char *content);
-
-#endif