mirror of
https://git.proxmox.com/git/libgit2
synced 2025-12-26 21:39:56 +00:00
clay: Move file_create to the helpers file
This commit is contained in:
parent
7a704309ae
commit
1d415455d9
@ -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));
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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));
|
||||
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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));
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
#ifndef INCLUDE_testlib_h__
|
||||
#define INCLUDE_testlib_h__
|
||||
|
||||
void file_create(const char *filename, const char *content);
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user