Rename testing macros

This commit is contained in:
Abdelrahman Said 2024-06-03 07:58:24 +01:00
parent 75bbb82058
commit 6499dd7be9
4 changed files with 15 additions and 14 deletions

View File

@ -21,7 +21,7 @@ void run_tests(TestFunc *func1, ...) {
TestFuncResult result = func();
print_test_result(result);
if (!result.success) {
if (!result.passed) {
exit(EXIT_FAILURE);
}
}
@ -35,7 +35,7 @@ internal void print_test_result(TestFuncResult result) {
const char *colour;
const char *result_text;
if (result.success) {
if (result.passed) {
colour = TERM_COLOUR_FG_BR_GREEN;
result_text = "PASSED";
} else {

View File

@ -7,13 +7,14 @@
extern "C" {
#endif // __cplusplus
#define TEST_RESULT(BOOL) ((TestFuncResult){.name = __func__, .success = BOOL})
#define RUN_TEST_FUNCS(...) run_tests(__VA_ARGS__, NULL)
#define wapp_tester_result(test_passed) \
((TestFuncResult){.name = __func__, .passed = test_passed})
#define wapp_tester_run_tests(...) run_tests(__VA_ARGS__, NULL)
typedef struct test_func_result TestFuncResult;
struct test_func_result {
const char *name;
bool success;
bool passed;
};
typedef TestFuncResult(TestFunc)(void);

View File

@ -16,7 +16,7 @@ TestFuncResult test_arena_init(void) {
bool result = wapp_mem_arena_init(&arena, ARENA_CAPACITY,
WAPP_MEM_ALLOC_RESERVE, false);
return TEST_RESULT(result);
return wapp_tester_result(result);
}
TestFuncResult test_arena_alloc_succeeds_when_within_capacity(void) {
@ -27,14 +27,14 @@ TestFuncResult test_arena_alloc_succeeds_when_within_capacity(void) {
array[i] = i * 10;
}
return TEST_RESULT(result);
return wapp_tester_result(result);
}
TestFuncResult test_arena_alloc_fails_when_over_capacity(void) {
u8 *bytes = wapp_mem_arena_alloc(arena, ARENA_CAPACITY * 2);
bool result = bytes == NULL;
return TEST_RESULT(result);
return wapp_tester_result(result);
}
TestFuncResult test_arena_clear(void) {
@ -48,12 +48,12 @@ TestFuncResult test_arena_clear(void) {
}
}
return TEST_RESULT(result);
return wapp_tester_result(result);
}
TestFuncResult test_arena_destroy(void) {
wapp_mem_arena_destroy(&arena);
bool result = arena == NULL;
return TEST_RESULT(result);
return wapp_tester_result(result);
}

View File

@ -3,10 +3,10 @@
#include <stdlib.h>
int main(void) {
RUN_TEST_FUNCS(test_arena_init,
test_arena_alloc_succeeds_when_within_capacity,
test_arena_alloc_fails_when_over_capacity, test_arena_clear,
test_arena_destroy);
wapp_tester_run_tests(test_arena_init,
test_arena_alloc_succeeds_when_within_capacity,
test_arena_alloc_fails_when_over_capacity,
test_arena_clear, test_arena_destroy);
return EXIT_SUCCESS;
}