tests: add diag_multiline() helper to escape multi-line diagnostic info
[babeltrace.git] / tests / utils / tap / tap.c
index 8bf72f6fcde57dac97fd9673cb0df5efdf9b6b0c..4d09a58a5e8c2e39835d14dba24a83d249da7ed5 100644 (file)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2004 Nik Clayton
+ *               2017 Jérémie Galarneau
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * SUCH DAMAGE.
  */
 
-#define _GNU_SOURCE
 #include <ctype.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+#include <limits.h>
 
 #include "tap.h"
 
@@ -59,6 +62,18 @@ static void _expected_tests(unsigned int);
 static void _tap_init(void);
 static void _cleanup(void);
 
+#ifdef __MINGW32__
+static inline
+void flockfile (FILE * filehandle) {
+       return;
+}
+
+static inline
+void funlockfile(FILE * filehandle) {
+       return;
+}
+#endif
+
 /*
  * Generate a test result.
  *
@@ -284,6 +299,28 @@ diag(char *fmt, ...)
        return 0;
 }
 
+void
+diag_multiline(const char *val)
+{
+       size_t len, i, line_start_idx = 0;
+
+       assert(val);
+       len = strlen(val);
+
+       for (i = 0; i < len; i++) {
+               int line_length;
+
+               if (val[i] != '\n') {
+                       continue;
+               }
+
+               assert((i - line_start_idx + 1) <= INT_MAX);
+               line_length = i - line_start_idx + 1;
+               fprintf(stderr, "# %.*s", line_length, &val[line_start_idx]);
+               line_start_idx = i + 1;
+       }
+}
+
 void
 _expected_tests(unsigned int tests)
 {
This page took 0.024275 seconds and 4 git commands to generate.