From: Lucas De Marchi Date: Wed, 25 Jan 2012 21:48:31 +0000 (-0200) Subject: testsuite: add colors to test output X-Git-Tag: v5~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51b1d1ab28b594ab1369fe411a6be3bce40da51c;p=thirdparty%2Fkmod.git testsuite: add colors to test output --- diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index 4eadca5c..3c8b03fb 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -13,6 +13,10 @@ #include "testsuite.h" +static const char *ANSI_HIGHLIGHT_GREEN_ON = "\x1B[1;32m"; +static const char *ANSI_HIGHLIGHT_RED_ON = "\x1B[1;31m"; +static const char *ANSI_HIGHLIGHT_OFF = "\x1B[0m"; + static const char *progname; static int oneshot = 0; static const char options_short[] = "lhn"; @@ -80,6 +84,12 @@ int test_init(int argc, char *const argv[], const struct test *tests[]) } } + if (isatty(STDOUT_FILENO) == 0) { + ANSI_HIGHLIGHT_OFF = ""; + ANSI_HIGHLIGHT_RED_ON = ""; + ANSI_HIGHLIGHT_GREEN_ON = ""; + } + return optind; } @@ -377,14 +387,19 @@ static inline int test_run_parent(const struct test *t, int fdout[2], if (err == 0) { if (matchout) - LOG("PASSED: %s\n", t->name); + LOG("%sPASSED%s: %s\n", + ANSI_HIGHLIGHT_GREEN_ON, ANSI_HIGHLIGHT_OFF, + t->name); else { - ERR("FAILED: exit ok but outputs do not match: %s\n", - t->name); + ERR("%sFAILED%s: exit ok but outputs do not match: %s\n", + ANSI_HIGHLIGHT_RED_ON, ANSI_HIGHLIGHT_OFF, + t->name); err = EXIT_FAILURE; } } else - ERR("FAILED: %s\n", t->name); + ERR("%sFAILED%s: %s\n", + ANSI_HIGHLIGHT_RED_ON, ANSI_HIGHLIGHT_OFF, + t->name); return err; }