tests: add diag_multiline() helper to escape multi-line diagnostic info
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 18 Aug 2017 23:43:11 +0000 (19:43 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 21 Aug 2017 21:02:22 +0000 (17:02 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/utils/tap/tap.c
tests/utils/tap/tap.h

index b505eff613d2faf31b92bddc81d3526cbbff770e..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
@@ -28,6 +29,9 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+#include <limits.h>
 
 #include "tap.h"
 
@@ -295,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)
 {
index 0f0594308ea27b20a207853bf7a05e1384b7d77b..40fb79168652d7cea54f9fc5f0c94fd475aaf072 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
@@ -80,6 +81,7 @@ int plan_skip_all(char *);
 int plan_tests(unsigned int);
 
 unsigned int diag(char *, ...);
+void diag_multiline(const char *);
 
 int skip(unsigned int, char *, ...);
 
This page took 0.025187 seconds and 4 git commands to generate.