[PATCH libinput 3/4] test: detect linebreaks in log messages

Peter Hutterer peter.hutterer at who-t.net
Tue Mar 28 10:07:51 UTC 2017


If a single log message is composed of multiple calls (as are all from
evdev_log_*), don't prefix multiple times.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/litest.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/test/litest.c b/test/litest.c
index d91a524..acba871 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -786,6 +786,7 @@ litest_log_handler(struct libinput *libinput,
 		   va_list args)
 {
 	static int is_tty = -1;
+	static bool had_newline = true;
 	const char *priority = NULL;
 	const char *color;
 
@@ -812,11 +813,12 @@ litest_log_handler(struct libinput *libinput,
 	if (!is_tty)
 		color = "";
 
-	fprintf(stderr, "%slitest %s ", color, priority);
-
+	if (had_newline)
+		fprintf(stderr, "%slitest %s ", color, priority);
 	vfprintf(stderr, format, args);
-
-	if (is_tty)
+	had_newline = strlen(format) >= 1 &&
+		      format[strlen(format) - 1] == '\n';
+	if (is_tty && had_newline)
 		fprintf(stderr, ANSI_NORMAL);
 
 	if (strstr(format, "client bug: ") ||
-- 
2.9.3



More information about the wayland-devel mailing list