#ifndef COSMS_CORE_TEST #define COSMS_CORE_TEST #include #include #define COSMS_CORE_TEST_FUNCTION_NAME(name) cosms_core_##name##_test #define COSMS_CORE_TEST_DEFINE(name) void cosms_core_##name##_test(void) #define COSMS_CORE_TEST_TEST(name, implementation) void cosms_core_##name##_test(void) { \ printf("----------------------------------------\n%s\n----------------------------------------\n", #name); \ implementation \ } #define COSMS_CORE_TEST_SUB_TEST(name, implementation) { \ const char *cosms_core_test_sub_test_error = NULL; \ printf("[*] running test %s...\n", #name); \ implementation \ if (cosms_core_test_sub_test_error == NULL) { \ printf("[+] test %s completed successfully!\n", #name); \ } else { \ printf("[-] test %s failed with error: %s\n", #name, cosms_core_test_sub_test_error); \ } \ } #define COSMS_CORE_TEST_EXPORT(name, ...) static const cosms_core_test cosms_core_test_##name[] = { \ __VA_ARGS__ \ } #define COSMS_CORE_TEST_START static const cosms_core_test *cosms_core_test_tests[] = { #define COSMS_CORE_TEST_IMPORT(name) cosms_core_test_##name #define COSMS_CORE_TEST_END }; #define COSMS_CORE_TEST_RUN() \ for (unsigned long long index = 0; index < sizeof(cosms_core_test_tests); index += 1) { \ for (unsigned long long test_index = 0; test_index < sizeof(cosms_core_test_tests[index]); test_index += 1) { \ cosms_core_test_tests[index][test_index](); \ } \ } typedef void (*cosms_core_test)(); #endif