clay: Move `file_create` to the helpers file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
diff --git a/tests-clay/clay_helpers.c b/tests-clay/clay_helpers.c
index f1b83ca..081fb08 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 d0faf9a..1364eb0 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 d884c8d..b3f4a66 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 c949fa7..104982a 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 80ae3d5..fd149bf 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 4fd6e6f..c290bdd 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 d45fc2c..0000000
--- 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 2e8867c..0000000
--- 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