From 05a6748bd137031d517b088851ee346193809963 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 15 Jun 2017 07:52:42 +0200 Subject: [PATCH] tests: fix the error message when dying during test's execution If die() or die_perr() is called during a test case, print an additional newline character so that the error message is displayed below the test description. Signed-off-by: Bartosz Golaszewski --- tests/gpiod-test.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/gpiod-test.c b/tests/gpiod-test.c index 53cbc95..c697184 100644 --- a/tests/gpiod-test.c +++ b/tests/gpiod-test.c @@ -70,6 +70,7 @@ struct test_context { char *failed_msg; struct event_thread event; struct gpiotool_proc tool_proc; + bool running; }; static struct { @@ -169,6 +170,9 @@ static TEST_PRINTF(1, 2) NORETURN void die(const char *fmt, ...) { va_list va; + if (globals.test_ctx.running) + pr_raw("\n"); + va_start(va, fmt); vmsg("FATAL", CRED, fmt, va); va_end(va); @@ -180,6 +184,9 @@ static TEST_PRINTF(1, 2) NORETURN void die_perr(const char *fmt, ...) { va_list va; + if (globals.test_ctx.running) + pr_raw("\n"); + va_start(va, fmt); vmsgn("FATAL", CRED, fmt, va); pr_raw(": %s\n", strerror(errno)); @@ -827,7 +834,9 @@ static void run_test(struct _test_case *test) print_header("TEST", CYELLOW); pr_raw("'%s': ", test->name); + globals.test_ctx.running = true; test->func(); + globals.test_ctx.running = false; if (globals.test_ctx.test_failed) { globals.tests_failed++; -- 2.30.2