tests: fix the error message when dying during test's execution
authorBartosz Golaszewski <bartekgola@gmail.com>
Thu, 15 Jun 2017 05:52:42 +0000 (07:52 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Thu, 15 Jun 2017 05:52:42 +0000 (07:52 +0200)
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 <bartekgola@gmail.com>
tests/gpiod-test.c

index 53cbc95aa8faa71039de07776e70b99ca2261185..c697184494b874ce170166572dc3523b4b9e36c1 100644 (file)
@@ -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++;