diff mbox

[libvirt] testutils: Add coloring to verbose PASS/FAILED output

Message ID 35387d821292c29717cd1e2bf5256c7c3cfd932b.1443570869.git.crobinso@redhat.com
State New
Headers show

Commit Message

Cole Robinson Sept. 29, 2015, 11:54 p.m. UTC
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 | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

Comments

Martin Kletzander Sept. 30, 2015, 5:40 a.m. UTC | #1
On Tue, Sep 29, 2015 at 07:54:50PM -0400, Cole Robinson wrote:
>Helps to visually track down test failures if debugging the test suite.
>
>The colors match what 'make check' does for pass/fail/skip
>---

Consistency is always fine, ACK.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox

Patch

diff --git a/tests/testutils.c b/tests/testutils.c
index 89026c6..bd4ff73 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -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)) {