From 840c5b8053ae58755e57dba5bdc4488945594600 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 18 Aug 2017 19:43:11 -0400 Subject: [PATCH] tests: add diag_multiline() helper to escape multi-line diagnostic info MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- tests/utils/tap/tap.c | 26 ++++++++++++++++++++++++++ tests/utils/tap/tap.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/tests/utils/tap/tap.c b/tests/utils/tap/tap.c index b505eff6..4d09a58a 100644 --- a/tests/utils/tap/tap.c +++ b/tests/utils/tap/tap.c @@ -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 #include #include +#include +#include +#include #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) { diff --git a/tests/utils/tap/tap.h b/tests/utils/tap/tap.h index 0f059430..40fb7916 100644 --- a/tests/utils/tap/tap.h +++ b/tests/utils/tap/tap.h @@ -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 *, ...); -- 2.34.1