87#define __FUNCTION__ __func__
90#if !defined(__clang__) && __GNUC__ > 3
91#pragma GCC diagnostic ignored "-Wclobbered"
161 if (suite == NULL)
return;
185 if (suite->
tests == NULL) {
209 if (suite->
name == NULL) {
210 out_writer(
"*** Test Suite ***\n", 1, 19, out_target);
212 out_writer(
"*** Test Suite : ", 1, 17, out_target);
213 out_writer(suite->
name, 1, strlen(suite->
name), out_target);
214 out_writer(
" ***\n", 1, 5, out_target);
219 elem->test(suite, out_target, out_writer);
221 out_writer(
"\nAll test completed.\n", 1, 21, out_target);
225 " Total: %u\n Success: %u\n Failure: %u\n\n",
228 out_writer(total, 1, len, out_target);
236#define cx_test_run_f(suite, file) cx_test_run(suite, (void*)file, (cx_write_func)fwrite)
242#define cx_test_run_stdout(suite) cx_test_run_f(suite, stdout)
251#define CX_TEST(name) void name(CxTestSuite* _suite_,void *_output_, cx_write_func _writefnc_)
269#define CX_TEST_DO _writefnc_("Running ", 1, 8, _output_);\
270 _writefnc_(__FUNCTION__, 1, strlen(__FUNCTION__), _output_);\
271 _writefnc_("... ", 1, 4, _output_);\
273 for (unsigned int _cx_test_loop_ = 0 ;\
274 _cx_test_loop_ == 0 && !setjmp(_env_);\
275 _writefnc_("success.\n", 1, 9, _output_),\
276 _suite_->success++, _cx_test_loop_++)
286#define CX_TEST_ASSERTM(condition,message) if (!(condition)) { \
287 const char *_assert_msg_ = message; \
288 _writefnc_(_assert_msg_, 1, strlen(_assert_msg_), _output_); \
289 _writefnc_(".\n", 1, 2, _output_); \
290 _suite_->failure++; \
301#define CX_TEST_ASSERT(condition) CX_TEST_ASSERTM(condition, #condition " failed")
314#define CX_TEST_SUBROUTINE(name,...) void name(CxTestSuite* _suite_,\
315 void *_output_, cx_write_func _writefnc_, jmp_buf _env_, __VA_ARGS__)
330#define CX_TEST_CALL_SUBROUTINE(name,...) \
331 name(_suite_,_output_,_writefnc_,_env_,__VA_ARGS__)
Common definitions and feature checks.
#define cx_attr_nonnull
All pointer arguments must be non-NULL.
Definition common.h:136
size_t(* cx_write_func)(const void *, size_t, size_t, void *)
Function pointer compatible with fwrite-like functions.
Definition common.h:295
#define cx_attr_nodiscard
Warn about discarded return value.
Definition common.h:265
#define cx_attr_malloc
The attributed function always returns freshly allocated memory.
Definition common.h:151
#define cx_attr_cstr_arg(idx)
No support for null_terminated_string_arg in clang or GCC below 14.
Definition common.h:206
Strings that know their length.
Structure for the internal list of test cases.
Definition test.h:104
CxTest test
Test case.
Definition test.h:107
CxTestSet * next
Pointer to the next list element.
Definition test.h:110
A test suite containing multiple test cases.
Definition test.h:116
const char * name
The optional name of this test suite.
Definition test.h:125
unsigned int success
The number of successful tests after the suite has been run.
Definition test.h:119
unsigned int failure
The number of failed tests after the suite has been run.
Definition test.h:122
CxTestSet * tests
Internal list of test cases.
Definition test.h:131
void(* CxTest)(CxTestSuite *, void *, cx_write_func)
Pointer to a test function.
Definition test.h:98
static CxTestSuite * cx_test_suite_new(const char *name)
Creates a new test suite.
Definition test.h:143
static int cx_test_register(CxTestSuite *suite, CxTest test)
Registers a test function with the specified test suite.
Definition test.h:180
static void cx_test_suite_free(CxTestSuite *suite)
Deallocates a test suite.
Definition test.h:160
static void cx_test_run(CxTestSuite *suite, void *out_target, cx_write_func out_writer)
Runs a test suite and writes the test log to the specified stream.
Definition test.h:207