]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
testutils: Add coloring to verbose PASS/FAILED output
authorCole Robinson <crobinso@redhat.com>
Tue, 29 Sep 2015 15:28:15 +0000 (11:28 -0400)
committerCole Robinson <crobinso@redhat.com>
Mon, 5 Oct 2015 18:34:04 +0000 (14:34 -0400)
Helps to visually track down test failures if debugging the test suite.

The colors match what 'make check' does for pass/fail/skip

tests/testutils.c

index 89026c6341d72d7fad13be09ae954f9f94e2a545..bd4ff73f431eda21152df363e0d51a53b52d5833 100644 (file)
@@ -91,6 +91,11 @@ bool virtTestOOMActive(void)
     return testOOMActive;
 }
 
+static int virtTestUseTerminalColors(void)
+{
+    return isatty(STDIN_FILENO);
+}
+
 static unsigned int
 virTestGetFlag(const char *name)
 {
@@ -217,11 +222,20 @@ virtTestRun(const char *title,
 
     if (virTestGetVerbose()) {
         if (ret == 0)
-            fprintf(stderr, "OK\n");
+            if (virtTestUseTerminalColors())
+                fprintf(stderr, "\e[32mOK\e[0m\n");  /* green */
+            else
+                fprintf(stderr, "OK\n");
         else if (ret == EXIT_AM_SKIP)
-            fprintf(stderr, "SKIP\n");
+            if (virtTestUseTerminalColors())
+                fprintf(stderr, "\e[34m\e[1mSKIP\e[0m\n");  /* bold blue */
+            else
+                fprintf(stderr, "SKIP\n");
         else
-            fprintf(stderr, "FAILED\n");
+            if (virtTestUseTerminalColors())
+                fprintf(stderr, "\e[31m\e[1mFAILED\e[0m\n");  /* bold red */
+            else
+                fprintf(stderr, "FAILED\n");
     } else {
         if (testCounter != 1 &&
             !((testCounter-1) % 40)) {