From: Bartosz Golaszewski Date: Thu, 15 Jun 2017 05:52:42 +0000 (+0200) Subject: tests: fix the error message when dying during test's execution X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=05a6748bd137031d517b088851ee346193809963;p=qemu-gpiodev%2Flibgpiod.git 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 --- 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++;