X_TEST_VERSION_MAJOR
#define X_TEST_VERSION_MAJOR 1
STDX - Minimal Unit Test framework Part of the STDX General Purpose C Library by marciovmf License: MIT https://github.com/marciovmf/stdx
To compile the implementation define X_IMPL_TEST
in one source file before including this header.
ASSERT_* macros for checksX_TEST(name) and run with x_tests_run(...)X_IMPL_TEST before including to enable main runner. int32_t test_example() {
ASSERT_TRUE(2 + 2 == 4);
return 0;
}
int32_t main() {
STDXTestCase tests[] = {
X_TEST(test_example)
};
return x_tests_run(tests, sizeof(tests)/sizeof(tests[0]));
}
x_log.h
#define X_TEST_VERSION_MAJOR 1
#define X_TEST_VERSION_MINOR 0
#define X_TEST_VERSION_PATCH 0
#define X_TEST_VERSION(X_TEST_VERSION_MAJOR *10000+X_TEST_VERSION_MINOR *100+X_TEST_VERSION_PATCH)
#define X_TEST_SUCCESS 0
#define X_TEST_FAIL -1
#define XLOG_GREEN(msg, ...) x_log_raw(stdout, XLOG_LEVEL_INFO, XLOG_COLOR_GREEN, XLOG_COLOR_BLACK, 0, msg, __VA_ARGS__, 0)
#define XLOG_WHITE(msg, ...) x_log_raw(stdout, XLOG_LEVEL_INFO, XLOG_COLOR_WHITE, XLOG_COLOR_BLACK, 0, msg, __VA_ARGS__, 0)
#define XLOG_RED(msg, ...) x_log_raw(stderr, XLOG_LEVEL_INFO, XLOG_COLOR_RED, XLOG_COLOR_BLACK, 0, msg, __VA_ARGS__, 0)
Assert that an expression evaluates to true; logs an error and returns 1 from the test on failure.
#define ASSERT_TRUE(expr) do{\
if(!(expr)){\
x_log_error("\t%s:%d: Assertion failed: %s\n", __FILE__, __LINE__, (#expr));\
return 1;\
}\
}while(0)
exprNothing (on failure, returns 1 from the calling function).
Assert that an expression evaluates to false; logs an error and returns 1 from the test on failure.
#define ASSERT_FALSE(expr) ASSERT_TRUE(!(expr))
exprNothing (on failure, returns 1 from the calling function).
Assert that two values are equal; logs an error and returns 1 from the test on failure.
#define ASSERT_EQ(actual, expected) do{\
if((actual)!=(expected)){\
x_log_error("\t%s:%d: Assertion failed: %s == %s", __FILE__, __LINE__, #actual, #expected);\
return 1;\
}\
}while(0)
actualexpectedNothing (on failure, returns 1 from the calling function).
Default epsilon used by ASSERT_FLOAT_EQ for approximate float comparisons.
#define X_TEST_FLOAT_EPSILON 0.1f
None.Assert that two floating-point values are approximately equal within X_TEST_FLOAT_EPSILON.
#define ASSERT_FLOAT_EQ(actual, expected) do{\
if(fabs((actual)-(expected))>X_TEST_FLOAT_EPSILON){\
x_log_error("\t%s:%d: Assertion failed: %s == %s", __FILE__, __LINE__, #actual, #expected);\
return 1;\
}\
}while(0)
actualexpectedNothing (on failure, returns 1 from the calling function).
Assert that two values are not equal; logs an error and returns 1 from the test on failure.
#define ASSERT_NEQ(actual, expected) do{\
if((actual)==(expected)){\
x_log_error("\t%s:%d: Assertion failed: %s != %s", __FILE__, __LINE__, #actual, #expected);\
return 1;\
}\
}while(0)
actualexpectedNothing (on failure, returns 1 from the calling function).
Test function signature used by the STDX test runner.
typedef int32_t(*STDXTestFunction)();
None.typedef struct{
const char *name;
STDXTestFunction func;
}STDXTestCase;
#define X_TEST(name) {#name, name}
int x_tests_run(
STDXTestCase *tests,
int32_t num_tests
);