[PATCH 1/2] include: Add optional ANSI color codes for winetests.

Rafał Harabień rafalh1992 at o2.pl
Sat Nov 25 12:57:00 CST 2017


By default colors are disabled.
Use WINETEST_COLOR=1 to enable colors in tests.

Signed-off-by: Rafał Harabień <rafalh1992 at o2.pl>
---
 include/wine/test.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/wine/test.h b/include/wine/test.h
index 4ec66d5..3388414 100644
--- a/include/wine/test.h
+++ b/include/wine/test.h
@@ -206,6 +206,9 @@ const char *winetest_platform = "windows";
 /* report successful tests (BOOL) */
 static int report_success = 0;
 
+/* use ANSI escape codes for output coloring */
+static int winetest_color = 0;
+
 /* passing arguments around */
 static int winetest_argc;
 static char** winetest_argv;
@@ -303,14 +306,20 @@ int broken( int condition )
 int winetest_vok( int condition, const char *msg, __winetest_va_list args )
 {
     struct tls_data *data = get_tls_data();
+    const char *color_red = "\e[91m";
+    const char *color_reset = "\e[39m";
 
     if (data->todo_level)
     {
         if (condition)
         {
+            if (winetest_color)
+                printf("%s", color_red);
             printf( "%s:%d: Test succeeded inside todo block: ",
                     data->current_file, data->current_line );
             vprintf(msg, args);
+            if (winetest_color)
+                printf("%s", color_reset);
             InterlockedIncrement(&todo_failures);
             return 0;
         }
@@ -330,9 +339,13 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
     {
         if (!condition)
         {
+            if (winetest_color)
+                printf("%s", color_red);
             printf( "%s:%d: Test failed: ",
                     data->current_file, data->current_line );
             vprintf(msg, args);
+            if (winetest_color)
+                printf("%s", color_reset);
             InterlockedIncrement(&failures);
             return 0;
         }
@@ -669,6 +682,7 @@ int main( int argc, char **argv )
     if (GetEnvironmentVariableA( "WINETEST_DEBUG", p, sizeof(p) )) winetest_debug = atoi(p);
     if (GetEnvironmentVariableA( "WINETEST_INTERACTIVE", p, sizeof(p) )) winetest_interactive = atoi(p);
     if (GetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", p, sizeof(p) )) report_success = atoi(p);
+    if (GetEnvironmentVariableA( "WINETEST_COLOR", p, sizeof(p) )) winetest_color = atoi(p);
 
     if (!strcmp( winetest_platform, "windows" )) SetUnhandledExceptionFilter( exc_filter );
     if (!winetest_interactive) SetErrorMode( SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX );
-- 
2.7.4




More information about the wine-devel mailing list