Sha256: d7a9c8b536ddabc1d1645ff5dd7790cd011e9f2daaa4cdf3d5a1d6248e235be0

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

#include "clar_libgit2.h"
#include "common.h"
#include "util.h"
#include "posix.h"

void test_core_errors__new_school(void)
{
	char *str_in_error;

	giterr_clear();
	cl_assert(giterr_last() == NULL);

	giterr_set_oom(); /* internal fn */

	cl_assert(giterr_last() != NULL);
	cl_assert(giterr_last()->klass == GITERR_NOMEMORY);
	str_in_error = strstr(giterr_last()->message, "memory");
	cl_assert(str_in_error != NULL);

	giterr_clear();

	giterr_set(GITERR_REPOSITORY, "This is a test"); /* internal fn */

	cl_assert(giterr_last() != NULL);
	str_in_error = strstr(giterr_last()->message, "This is a test");
	cl_assert(str_in_error != NULL);

	giterr_clear();
	cl_assert(giterr_last() == NULL);

	do {
		struct stat st;
		memset(&st, 0, sizeof(st));
		cl_assert(p_lstat("this_file_does_not_exist", &st) < 0);
		GIT_UNUSED(st);
	} while (false);
	giterr_set(GITERR_OS, "stat failed"); /* internal fn */

	cl_assert(giterr_last() != NULL);
	str_in_error = strstr(giterr_last()->message, "stat failed");
	cl_assert(str_in_error != NULL);
	cl_assert(git__prefixcmp(str_in_error, "stat failed: ") == 0);
	cl_assert(strlen(str_in_error) > strlen("stat failed: "));

#ifdef GIT_WIN32
	giterr_clear();

	/* The MSDN docs use this to generate a sample error */
	cl_assert(GetProcessId(NULL) == 0);
	giterr_set(GITERR_OS, "GetProcessId failed"); /* internal fn */

	cl_assert(giterr_last() != NULL);
	str_in_error = strstr(giterr_last()->message, "GetProcessId failed");
	cl_assert(str_in_error != NULL);
	cl_assert(git__prefixcmp(str_in_error, "GetProcessId failed: ") == 0);
	cl_assert(strlen(str_in_error) > strlen("GetProcessId failed: "));
#endif

	giterr_clear();
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rugged-0.17.0b2 ext/rugged/vendor/libgit2-dist/tests-clar/core/errors.c
rugged-0.17.0b1 ext/rugged/vendor/libgit2-dist/tests-clar/core/errors.c