Пример #1
0
static void add_entry_and_check_mode_(
	git_index *index, bool from_file, git_filemode_t mode,
	const char *file, int line)
{
	size_t pos;
	const git_index_entry* entry;
	git_index_entry new_entry;

	/* If old_filename exists, we copy that to the new file, and test
	 * git_index_add(), otherwise create a new entry testing git_index_add_frombuffer
	 */
	if (from_file)
	{
		clar__assert(!git_index_find(&pos, index, "exec_off"),
			file, line, "Cannot find original index entry", NULL, 1);

		entry = git_index_get_byindex(index, pos);

		memcpy(&new_entry, entry, sizeof(new_entry));
	}
	else
		memset(&new_entry, 0x0, sizeof(git_index_entry));

	new_entry.path = "filemodes/explicit_test";
	new_entry.mode = mode;

	if (from_file)
	{
		clar__assert(!git_index_add(index, &new_entry),
			file, line, "Cannot add index entry", NULL, 1);
	}
	else
	{
		const char *content = "hey there\n";
		clar__assert(!git_index_add_frombuffer(index, &new_entry, content, strlen(content)),
			file, line, "Cannot add index entry from buffer", NULL, 1);
	}

	clar__assert(!git_index_find(&pos, index, "filemodes/explicit_test"),
		file, line, "Cannot find new index entry", NULL, 1);

	entry = git_index_get_byindex(index, pos);

	clar__assert_equal(file, line, "Expected mode does not match index",
		1, "%07o", (unsigned int)entry->mode, (unsigned int)mode);
}
Пример #2
0
void cl_git_report_failure(
	int error, const char *file, int line, const char *fncall)
{
	char msg[4096];
	const git_error *last = giterr_last();
	p_snprintf(msg, 4096, "error %d - %s",
		error, last ? last->message : "<no message>");
	clar__assert(0, file, line, fncall, msg, 1);
}
Пример #3
0
void clar__assert_equal_file(
	const char *expected_data,
	size_t expected_bytes,
	int ignore_cr,
	const char *path,
	const char *file,
	int line)
{
	char buf[4000];
	ssize_t bytes, total_bytes = 0;
	int fd = p_open(path, O_RDONLY | O_BINARY);
	cl_assert(fd >= 0);

	if (expected_data && !expected_bytes)
		expected_bytes = strlen(expected_data);

	while ((bytes = p_read(fd, buf, sizeof(buf))) != 0) {
		clar__assert(
			bytes > 0, file, line, "error reading from file", path, 1);

		if (ignore_cr)
			bytes = strip_cr_from_buf(buf, bytes);

		if (memcmp(expected_data, buf, bytes) != 0) {
			int pos;
			for (pos = 0; pos < bytes && expected_data[pos] == buf[pos]; ++pos)
				/* find differing byte offset */;
			p_snprintf(
				buf, sizeof(buf), "file content mismatch at byte %"PRIdZ,
				(ssize_t)(total_bytes + pos));
			p_close(fd);
			clar__fail(file, line, path, buf, 1);
		}

		expected_data += bytes;
		total_bytes   += bytes;
	}

	p_close(fd);

	clar__assert(!bytes, file, line, "error reading from file", path, 1);
	clar__assert_equal(file, line, "mismatched file length", 1, "%"PRIuZ,
		(size_t)expected_bytes, (size_t)total_bytes);
}
Пример #4
0
static void assert_ignored_(
	bool expected, const char *filepath, const char *file, int line)
{
	int is_ignored = 0;
	cl_git_expect(
		git_status_should_ignore(&is_ignored, g_repo, filepath), 0, file, line);
	clar__assert(
		(expected != 0) == (is_ignored != 0),
		file, line, "expected != is_ignored", filepath, 1);
}
Пример #5
0
void clar__assert_equal_i(
	int i1,
	int i2,
	const char *file,
	int line,
	const char *err,
	int should_abort)
{
	if (i1 != i2) {
		char buf[128];
		snprint_eq(buf, 128, "%d != %d", i1, i2);
		clar__assert(0, file, line, err, buf, should_abort);
	}
}
Пример #6
0
void clar__assert_equal_s(
	const char *s1,
	const char *s2,
	const char *file,
	int line,
	const char *err,
	int should_abort)
{
	int match = (s1 == NULL || s2 == NULL) ? (s1 == s2) : (strcmp(s1, s2) == 0);

	if (!match) {
		char buf[4096];
		snprint_eq(buf, 4096, "'%s' != '%s'", s1, s2);
		clar__assert(0, file, line, err, buf, should_abort);
	}
}
Пример #7
0
static void add_and_check_mode_(
	git_index *index, const char *filename, unsigned int expect_mode,
	const char *file, int line)
{
	size_t pos;
	const git_index_entry *entry;

	cl_git_pass(git_index_add_bypath(index, filename));

	clar__assert(!git_index_find(&pos, index, filename),
		file, line, "Cannot find index entry", NULL, 1);

	entry = git_index_get_byindex(index, pos);

	clar__assert_equal(file, line, "Expected mode does not match index",
		1, "%07o", (unsigned int)entry->mode, (unsigned int)expect_mode);
}
Пример #8
0
void cl_git_report_failure(
	int error, int expected, const char *file, int line, const char *fncall)
{
	char msg[4096];
	const git_error *last = git_error_last();

	if (expected)
		p_snprintf(msg, 4096, "error %d (expected %d) - %s",
			error, expected, last ? last->message : "<no message>");
	else if (error || last)
		p_snprintf(msg, 4096, "error %d - %s",
			error, last ? last->message : "<no message>");
	else
		p_snprintf(msg, 4096, "no error, expected non-zero return");

	clar__assert(0, file, line, fncall, msg, 1);
}