YMO_ASSERT_STREAM_OUT

Output stream for assertions

Definition
#define YMO_ASSERT_STREAM_OUT stdout

Assertions

Convenience Macros

ymo_assert_test_abort

Function used to abort test execution

Definition
#define ymo_assert_test_abort() exit(-1)
ymo_assert_test_fail_fmt

Function used to report assertion failure and abort

Definition
#define ymo_assert_test_fail_fmt(fmt, ...) \
        fprintf(YMO_ASSERT_STREAM_OUT, \
        " - \033[00;31mFAIL: "fmt " (%s:%s:%i)\033[00;m\n", \
        __VA_ARGS__, YMO_SOURCE, __func__, __LINE__); \
        ymo_assert_test_abort();
ymo_assert_test_fail

Function used to report assertion failure and abort

Definition
#define ymo_assert_test_fail(test_desc) \
        ymo_assert_test_fail_fmt("%s", test_desc); \
        ymo_assert_test_abort();
ymo_assert_test_pass_fmt

Function used to report assertion success, if verbose is defined

Definition
#define ymo_assert_test_pass_fmt(fmt, ...) \
        if( YMO_ASSERT_VERBOSE ) { \
            fprintf(YMO_ASSERT_STREAM_OUT, \
        " - \033[00;32mPASS: "fmt " (%s:%s:%i)\033[00;m\n", \
        __VA_ARGS__, YMO_SOURCE, __func__, __LINE__); \
        }
ymo_assert_test_pass

Function used to report assertion success, if verbose is defined

Definition
#define ymo_assert_test_pass(test_desc) ymo_assert_test_pass_fmt("%s", test_desc)
ymo_assert_test_fmt

Convenience macro used to execute tests and report failure

Definition
#define ymo_assert_test_fmt(test_cond, fmt, ...) \
        do { \
            if( !(test_cond) ) { \
                ymo_assert_test_fail_fmt(fmt, __VA_ARGS__); \
            }; \
            ymo_assert_test_pass_fmt(fmt, __VA_ARGS__); \
        } while( 0 )
ymo_assert_test

Convenience macro used to execute tests and report failure

Definition
#define ymo_assert_test(test_cond, test_desc) \
        do { \
            if( !(test_cond) ) { \
                ymo_assert_test_fail(test_desc); \
            }; \
            ymo_assert_test_pass(test_desc); \
        } while( 0 )

Assertions

ymo_assert

General true/false assertion.

Definition
#define ymo_assert(test_cond) ymo_assert_test(test_cond, #test_cond)

String Assertions

ymo_assert_str_eq

String equality:

  • pass if two non-null strings are lexicographically equal

  • pass if both strings are the NULL pointer

Definition
#define ymo_assert_str_eq(x, y) ymo_assert_test_fmt( \
        (x && y \
         && !strcmp((const char*)x,(const char*)y)) \
        || ((x == NULL) && (y == NULL)), \
        "%s:\n%s: >>%s<<\n%s: >>%s<<\n", \
        #x " == " #y, \
        #x, (const char*)x, \
        #y, (const char*)y \
        )
ymo_assert_str_ne

String inequality

  • pass if two non-null strings are not lexicographically equal

  • pass if one string is NULL and the other isn’t

Definition
#define ymo_assert_str_ne(x, y) ymo_assert_test_fmt( \
        (x && y && strcmp((const char*)x,(const char*)y)) \
        || ((x == NULL || y == NULL) && (x != y)), \
        "%s:\n%s: >>%s<<\n%s: >>%s<<\n", \
        #x " != " #y, #x, (const char*)x, #y, (const char*)y)
ymo_assert_str_contains

Substring matching: pass if x is a substring of y

Definition
#define ymo_assert_str_contains(x, y) ymo_assert_test( \
        x && y && strstr(x, y) != NULL, #x " contains " #y)
ymo_assert_str_startswith

Prefix matching: pass if x starts with y

Definition
#define ymo_assert_str_startswith(x, y) ymo_assert_test( \
        x && y && ((const char*)strstr(x, y)) == (const char*)x, \
        #x " starts with " #y)