Skip to content

Commit

Permalink
Update print line and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
anderson- committed Apr 11, 2020
1 parent 84342a7 commit 31e1237
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
32 changes: 21 additions & 11 deletions src/microcuts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/microcuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 31e1237

Please sign in to comment.