[PATCH v2] include: Add optional ANSI color codes for winetests and debug macros.
Rafał Harabień
rafalh1992 at o2.pl
Sun Nov 19 07:39:57 CST 2017
By default colors are disabled.
Use WINETEST_COLOR=1 to enable colors in tests.
Use WINEDEBUG_COLOR=1 to enable colors in debug messages.
Second version of the patch fixes compiler warnings.
Signed-off-by: Rafał Harabień <rafalh1992 at o2.pl>
---
include/wine/test.h | 14 ++++++++++++++
libs/wine/debug.c | 14 +++++++++++++-
2 files changed, 27 insertions(+), 1 deletion(-)
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 );
diff --git a/libs/wine/debug.c b/libs/wine/debug.c
index 8b04ef9..af84e67 100644
--- a/libs/wine/debug.c
+++ b/libs/wine/debug.c
@@ -39,12 +39,14 @@ WINE_DECLARE_DEBUG_CHANNEL(pid);
#endif
static const char * const debug_classes[] = { "fixme", "err", "warn", "trace" };
+static const char * const debug_classes_color[] = { "\e[93m", "\e[91m", "\e[93m", "" };
#define MAX_DEBUG_OPTIONS 256
static unsigned char default_flags = (1 << __WINE_DBCL_ERR) | (1 << __WINE_DBCL_FIXME);
static int nb_debug_options = -1;
static struct __wine_debug_channel debug_options[MAX_DEBUG_OPTIONS];
+static int debug_color = 0;
static struct __wine_debug_functions funcs;
@@ -193,7 +195,7 @@ static void debug_usage(void)
/* initialize all options at startup */
static void debug_init(void)
{
- char *wine_debug;
+ char *wine_debug, *color;
struct stat st1, st2;
if (nb_debug_options != -1) return; /* already initialized */
@@ -212,6 +214,8 @@ static void debug_init(void)
if (!strcmp( wine_debug, "help" )) debug_usage();
parse_options( wine_debug );
}
+ color = getenv("WINEDEBUG_COLOR");
+ if (color != NULL) debug_color = atoi(color);
}
/* varargs wrapper for funcs.dbg_vprintf */
@@ -406,6 +410,7 @@ static int default_dbg_vlog( enum __wine_debug_class cls, struct __wine_debug_ch
const char *func, const char *format, va_list args )
{
int ret = 0;
+ const char *color_reset = "\e[39m";
#if defined(__MINGW32__) || defined(_MSC_VER)
if (TRACE_ON(pid))
@@ -414,9 +419,16 @@ static int default_dbg_vlog( enum __wine_debug_class cls, struct __wine_debug_ch
ret += wine_dbg_printf( "%04x:", GetCurrentThreadId() );
#endif
if (cls < sizeof(debug_classes)/sizeof(debug_classes[0]))
+ {
+ if (debug_color)
+ ret += wine_dbg_printf( "%s", debug_classes_color[cls] );
ret += wine_dbg_printf( "%s:%s:%s ", debug_classes[cls], channel->name, func );
+ }
if (format)
ret += funcs.dbg_vprintf( format, args );
+ if (debug_color)
+ ret += wine_dbg_printf( "%s", color_reset );
+
return ret;
}
--
2.7.4
More information about the wine-devel
mailing list