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

static git_repository *_repo;

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

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

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

void test_repo_message__message(void)
{
25 26
	git_str path = GIT_STR_INIT;
	git_buf 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_str_joinpath(&path, git_repository_path(_repo), "MERGE_MSG"));
	cl_git_mkfile(git_str_cstr(&path), expected);
31

32
	cl_git_pass(git_repository_message(&actual, _repo));
33
	cl_assert_equal_s(expected, actual.ptr);
34
	git_buf_dispose(&actual);
35

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