Hash :
a95096ba
Author :
Date :
2020-01-12T10:31:07
assert: optionally fall-back to assert(3) Fall back to the system assert(3) in debug builds, which may aide in debugging. "Safe" assertions can be enabled in debug builds by setting GIT_ASSERT_HARD=0. Similarly, hard assertions can be enabled in release builds by setting GIT_ASSERT_HARD to nonzero.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#define GIT_ASSERT_HARD 0
#include "clar_libgit2.h"
static const char *hello_world = "hello, world";
static int dummy_fn(const char *myarg)
{
GIT_ASSERT_ARG(myarg);
GIT_ASSERT_ARG(myarg != hello_world);
return 0;
}
static int bad_math(void)
{
GIT_ASSERT(1 + 1 == 3);
return 42;
}
void test_core_assert__argument(void)
{
cl_git_fail(dummy_fn(NULL));
cl_assert(git_error_last());
cl_assert_equal_i(GIT_ERROR_INVALID, git_error_last()->klass);
cl_assert_equal_s("invalid argument: 'myarg'", git_error_last()->message);
cl_git_fail(dummy_fn(hello_world));
cl_assert(git_error_last());
cl_assert_equal_i(GIT_ERROR_INVALID, git_error_last()->klass);
cl_assert_equal_s("invalid argument: 'myarg != hello_world'", git_error_last()->message);
cl_git_pass(dummy_fn("foo"));
}
void test_core_assert__internal(void)
{
cl_git_fail(bad_math());
cl_assert(git_error_last());
cl_assert_equal_i(GIT_ERROR_INTERNAL, git_error_last()->klass);
cl_assert_equal_s("unrecoverable internal error: '1 + 1 == 3'", git_error_last()->message);
}