message.c 1009 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
#include "clar_libgit2.h"
#include "buffer.h"
#include "refs.h"
#include "posix.h"

static git_repository *_repo;

void test_repo_message__initialize(void)
{
10
	_repo = cl_git_sandbox_init("testrepo.git");
11 12 13 14
}

void test_repo_message__cleanup(void)
{
15
	cl_git_sandbox_cleanup();
16 17 18 19
}

void test_repo_message__none(void)
{
20 21
	git_buf actual = GIT_BUF_INIT;
	cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&actual, _repo));
22 23 24 25
}

void test_repo_message__message(void)
{
26
	git_buf path = GIT_BUF_INIT, actual = GIT_BUF_INIT;
27 28
	const char expected[] = "Test\n\nThis is a test of the emergency broadcast system\n";

29 30
	cl_git_pass(git_buf_joinpath(&path, git_repository_path(_repo), "MERGE_MSG"));
	cl_git_mkfile(git_buf_cstr(&path), expected);
31

32 33 34
	cl_git_pass(git_repository_message(&actual, _repo));
	cl_assert_equal_s(expected, git_buf_cstr(&actual));
	git_buf_free(&actual);
35

36 37 38
	cl_git_pass(p_unlink(git_buf_cstr(&path)));
	cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&actual, _repo));
	git_buf_free(&path);
39
}