]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: add colors to test output
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 25 Jan 2012 21:48:31 +0000 (19:48 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 26 Jan 2012 18:05:05 +0000 (16:05 -0200)
testsuite/testsuite.c

index 4eadca5c0bbef63dce2ca4b531345cd06e48fb46..3c8b03fbd7d99ac53234c5581ae4615ea960f403 100644 (file)
 
 #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;
 }