test: print test success rate
This commit is contained in:
parent
1f0a022cc7
commit
947117e061
@ -1,19 +1,21 @@
|
|||||||
#ifndef CEX_TEST_ASSERT_H
|
#ifndef CEX_TEST_ASSERT_H
|
||||||
#define CEX_TEST_ASSERT_H
|
#define CEX_TEST_ASSERT_H
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <cex/ansi/codes.h>
|
#include <cex/ansi/codes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.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 {
|
typedef struct {
|
||||||
size_t test_count;
|
size_t test_count;
|
||||||
size_t fail_count;
|
size_t fail_count;
|
||||||
} test_result_t;
|
} 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) \
|
#define TEST(label) \
|
||||||
test_result_t test_##label() { \
|
test_result_t test_##label() { \
|
||||||
test_result_t result = {.test_count = 0, .fail_count = 0}; \
|
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}; \
|
test_result_t final_result = {.test_count = 0, .fail_count = 0}; \
|
||||||
fprintf(stderr, ANSI_BOLD ANSI_UNDERLINE "project: %s\n" ANSI_RESET, label);
|
fprintf(stderr, ANSI_BOLD ANSI_UNDERLINE "project: %s\n" ANSI_RESET, label);
|
||||||
|
|
||||||
#define END_PROJECT \
|
#define END_PROJECT \
|
||||||
fprintf(stderr, "%ld / %ld " ANSI_FG_GREEN " succesful" ANSI_RESET ", %ld " ANSI_FG_RED "failed\n" ANSI_RESET, \
|
_print_project_info(final_result); \
|
||||||
final_result.test_count - final_result.fail_count, final_result.test_count, final_result.fail_count); \
|
return final_result.fail_count != 0; \
|
||||||
return final_result.fail_count != 0; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LABEL(label) fprintf(stderr, ANSI_ITALIC " %s\n" ANSI_RESET, label);
|
#define LABEL(label) fprintf(stderr, ANSI_ITALIC " %s\n" ANSI_RESET, label);
|
||||||
|
@ -1,8 +1,22 @@
|
|||||||
|
#include <cex/ansi/codes.h>
|
||||||
#include <cex/test/assert.h>
|
#include <cex/test/assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
void _print_assert(bool success, const char* label, const char* file, size_t line) {
|
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");
|
fprintf(stderr, "%20s: \t%s" ANSI_RESET, label, success ? ANSI_FG_GREEN "OK" : ANSI_FG_RED "FAILED");
|
||||||
if (!success)
|
if (!success)
|
||||||
fprintf(stderr, " in %s on line %ld", file, line);
|
fprintf(stderr, " in %s on line %ld", file, line);
|
||||||
putc('\n', stderr);
|
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