diff --git a/inc/cex/test/assert.h b/inc/cex/test/assert.h index e2e12d1..44d8762 100644 --- a/inc/cex/test/assert.h +++ b/inc/cex/test/assert.h @@ -1,19 +1,21 @@ #ifndef CEX_TEST_ASSERT_H #define CEX_TEST_ASSERT_H -#include #include #include #include #include -void _print_assert(bool success, const char* label, const char* file, size_t line); +#define INFO_BAR_WIDTH 50 typedef struct { size_t test_count; size_t fail_count; } test_result_t; +void _print_assert(bool success, const char* label, const char* file, size_t line); +void _print_project_info(test_result_t final_result); + #define TEST(label) \ test_result_t test_##label() { \ test_result_t result = {.test_count = 0, .fail_count = 0}; \ @@ -29,10 +31,9 @@ typedef struct { test_result_t final_result = {.test_count = 0, .fail_count = 0}; \ fprintf(stderr, ANSI_BOLD ANSI_UNDERLINE "project: %s\n" ANSI_RESET, label); -#define END_PROJECT \ - fprintf(stderr, "%ld / %ld " ANSI_FG_GREEN " succesful" ANSI_RESET ", %ld " ANSI_FG_RED "failed\n" ANSI_RESET, \ - final_result.test_count - final_result.fail_count, final_result.test_count, final_result.fail_count); \ - return final_result.fail_count != 0; \ +#define END_PROJECT \ + _print_project_info(final_result); \ + return final_result.fail_count != 0; \ } #define LABEL(label) fprintf(stderr, ANSI_ITALIC " %s\n" ANSI_RESET, label); diff --git a/src/cex/test/assert.c b/src/cex/test/assert.c index 10be72b..e0509e3 100644 --- a/src/cex/test/assert.c +++ b/src/cex/test/assert.c @@ -1,8 +1,22 @@ +#include #include +#include void _print_assert(bool success, const char* label, const char* file, size_t line) { fprintf(stderr, "%20s: \t%s" ANSI_RESET, label, success ? ANSI_FG_GREEN "OK" : ANSI_FG_RED "FAILED"); if (!success) fprintf(stderr, " in %s on line %ld", file, line); putc('\n', stderr); +} + +void _print_project_info(test_result_t final_result) { + int succes_len = INFO_BAR_WIDTH * (final_result.test_count - final_result.fail_count) / final_result.test_count; + fprintf(stderr, "["); + for (int i = 0; i < INFO_BAR_WIDTH; i++) { + fprintf(stderr, "%s ", succes_len > i ? ANSI_BG_GREEN : ANSI_BG_RED); + } + fprintf(stderr, ANSI_RESET "]\n"); + + fprintf(stderr, "%ld / %ld " ANSI_FG_GREEN " succesful" ANSI_RESET ", %ld " ANSI_FG_RED "failed\n" ANSI_RESET, + final_result.test_count - final_result.fail_count, final_result.test_count, final_result.fail_count); } \ No newline at end of file