ANSI colors in test program output

This commit is contained in:
Thomas Bernard 2019-12-31 19:05:12 +01:00
parent 7e276e105a
commit bf8347e4d9
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -98,6 +98,10 @@ void init(void)
#endif /* ENABLE_FILENAMES_ICONV */ #endif /* ENABLE_FILENAMES_ICONV */
} }
#define ESC_GREEN "\033[32m"
#define ESC_RED "\033[31m"
#define ESC_RESET "\033[0m"
/** /**
* Test program entry point * Test program entry point
*/ */
@ -116,21 +120,21 @@ int main(int argc, char * * argv)
printf("Testing %s :\n", tests[i].test_name); printf("Testing %s :\n", tests[i].test_name);
r = tests[i].test_func(); r = tests[i].test_func();
if (r) if (r)
printf("OK\n"); printf(ESC_GREEN "OK" ESC_RESET "\n");
else { else {
printf("FAILED\n"); printf(ESC_RED "FAILED" ESC_RESET "\n");
fail++; fail++;
} }
} }
if (fail == 0) if (fail == 0)
{ {
printf("All tests succesfull\n"); printf(ESC_GREEN "All tests succesfull" ESC_RESET "\n");
return 0; return 0;
} }
else else
{ {
printf("%d tests failed\n", fail); printf(ESC_RED "%d tests failed" ESC_RESET "\n", fail);
return 1; return 1;
} }
} }