test: print test success rate
This commit is contained in:
parent
1f0a022cc7
commit
947117e061
@ -1,19 +1,21 @@
|
||||
#ifndef CEX_TEST_ASSERT_H
|
||||
#define CEX_TEST_ASSERT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <cex/ansi/codes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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);
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include <cex/ansi/codes.h>
|
||||
#include <cex/test/assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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");
|
||||
@ -6,3 +8,15 @@ void _print_assert(bool success, const char* label, const char* file, size_t lin
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user