From 31e123738c17f94b760e4507936a12855440b6ef Mon Sep 17 00:00:00 2001 From: Anderson Antunes Date: Sat, 11 Apr 2020 16:48:20 -0300 Subject: [PATCH] Update print line and cleanup --- src/microcuts.c | 32 +++++++++++++++++++++----------- src/microcuts.h | 6 ++++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/microcuts.c b/src/microcuts.c index 8c1379e..a3b5d15 100644 --- a/src/microcuts.c +++ b/src/microcuts.c @@ -12,11 +12,13 @@ #define KMAG "\x1B[35m" #define KCYN "\x1B[36m" #define KWHT "\x1B[37m" +#define LINE 49 int assert_no = INT_MIN; int failed = 0; char * section_name = NULL; int total_failed = 0; +int print_sec_ok = 1; void start_tests(){ assert_no = INT_MIN; @@ -25,18 +27,24 @@ void start_tests(){ total_failed = 0; } +void printf_line(){ + for (int i = 0; i < LINE; i++) printf("="); + printf("\n"); +} + void end_tests(){ if (total_failed == 0){ - printf("%s", KGRN); - printf("\n=============================================\n"); + printf("%s\n", KGRN); + printf_line(); printf("> OK\n"); - printf("=============================================\n"); + printf_line(); printf("%s", KNRM); } else { - printf("%s", KYEL); - printf("\n=============================================\n"); - printf("> Check messages above. %d assertion%s failed\n", total_failed, (total_failed == 1? "" : "s")); - printf("=============================================\n"); + printf("%s\n", KYEL); + printf_line(); + printf("> Check messages above. %d assertion%s failed\n", total_failed, + (total_failed == 1? "" : "s")); + printf_line(); printf("%s", KNRM); } } @@ -51,9 +59,9 @@ void begin_section(const char* name){ void end_section(){ if (failed){ - } else { + } else if (print_sec_ok){ printf("%s", KGRN); - printf("\nAll tests on '%s' passed.\n", section_name); + printf("\nAll '%s' tests passed\n", section_name); printf("%s", KNRM); } assert_no = INT_MIN; @@ -77,7 +85,8 @@ void __assert(const char* expr_str, int a, const char* file, int line){ assert_no++; } -void __assert_eq(const char* expr_str_a, const char* expr_str_b, int a, int b, const char* file, int line){ +void __assert_eq(const char* expr_str_a, const char* expr_str_b, int a, int b, + const char* file, int line){ if (a != b){ if (assert_no < 0){ printf("%s", KRED); @@ -96,7 +105,8 @@ void __assert_eq(const char* expr_str_a, const char* expr_str_b, int a, int b, c assert_no++; } -void __assert_str_eq(const char* expr_str_a, const char* expr_str_b, const char* a, const char* b, const char* file, int line){ +void __assert_str_eq(const char* expr_str_a, const char* expr_str_b, + const char* a, const char* b, const char* file, int line){ if (strcmp(a, b)){ if (assert_no < 0){ printf("%s", KRED); diff --git a/src/microcuts.h b/src/microcuts.h index 3c5fc6e..ddf7f40 100644 --- a/src/microcuts.h +++ b/src/microcuts.h @@ -16,7 +16,9 @@ void end_tests(); void begin_section(const char* name); void end_section(); void __assert(const char* expr_str, int a, const char* file, int line); -void __assert_eq(const char* expr_str_a, const char* expr_str_b, int a, int b, const char* file, int line); -void __assert_str_eq(const char* expr_str_a, const char* expr_str_b, const char* a, const char* b, const char* file, int line); +void __assert_eq(const char* expr_str_a, const char* expr_str_b, int a, int b, + const char* file, int line); +void __assert_str_eq(const char* expr_str_a, const char* expr_str_b, + const char* a, const char* b, const char* file, int line); #endif