From d8aac5c51466990a4bbddc9d38c116ed9c59b769 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 1 Jan 2019 12:57:12 -0500 Subject: overwrite passsed tests, print summary of tests at the end of each header --- ctype.c | 2 ++ locale.c | 2 ++ test.c | 24 ++++++++++++++++++++---- test.h | 1 + 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ctype.c b/ctype.c index cb38da4..94de005 100644 --- a/ctype.c +++ b/ctype.c @@ -81,4 +81,6 @@ void test_ctype(void) test_ctype_conversion(tolower, UPPER, LOWER); test_ctype_conversion(toupper, LOWER, UPPER); + + testing_end(); } diff --git a/locale.c b/locale.c index 629ef0b..b6d48ed 100644 --- a/locale.c +++ b/locale.c @@ -72,4 +72,6 @@ void test_locale(void) test_int_equals(lc->n_sep_by_space, CHAR_MAX); test_int_equals(lc->p_sign_posn, CHAR_MAX); test_int_equals(lc->n_sign_posn, CHAR_MAX); + + testing_end(); } diff --git a/test.c b/test.c index 2d25648..2750ec3 100644 --- a/test.c +++ b/test.c @@ -1,6 +1,9 @@ #include #include +static int passed; +static int failed; + typedef enum { DEFAULT = 39, RED = 31, @@ -21,9 +24,14 @@ static void print_result(int success, const char *format, ...) Color color = GREEN; char indicator = '+'; - if (!success) { - color = RED; - indicator = '!'; + if (success) { + set_output_color(GREEN); + printf("+ "); + passed++; + } else { + set_output_color(RED); + printf("- "); + failed++; } set_output_color(color); @@ -33,7 +41,7 @@ static void print_result(int success, const char *format, ...) vprintf(format, ap); va_end(ap); - printf("\n"); + printf("%c", success ? '\r' : '\n'); set_output_color(DEFAULT); } @@ -46,6 +54,14 @@ void testing_header(const char *header) printf("\n"); } +void testing_end(void) +{ + printf("%d tests passed, %d tests failed\n", passed, failed); + + passed = 0; + failed = 0; +} + void testing_comment(const char *comment) { printf("- %s\n", comment); diff --git a/test.h b/test.h index 7fa1efe..f6566b9 100644 --- a/test.h +++ b/test.h @@ -1,5 +1,6 @@ void testing_header(const char *); void testing_comment(const char*); +void testing_end(void); void test_int_equals_imp(const char*, int, int); #define test_int_equals(expression, expected) test_int_equals_imp(#expression, expression, expected) -- cgit v1.2.1