tests: move the test case execution into a separate function
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 8 May 2017 09:28:27 +0000 (11:28 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Mon, 8 May 2017 14:25:52 +0000 (16:25 +0200)
For better readability move the code executing the test case into a
separate function - between the setup and teardown routines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
tests/unit/gpiod-unit.c

index 24fab6703d779c881640d302438fd99fefb969f6..f6a0b2ac6a7c60f64b6b3fb71ec5eac8906e94b7 100644 (file)
@@ -496,6 +496,30 @@ static void test_prepare(struct _gu_chip_descr *descr)
        qsort(ctx->chips, ctx->num_chips, sizeof(*ctx->chips), chipcmp);
 }
 
+static void test_run(struct _gu_test *test)
+{
+       print_header("TEST", CYELLOW);
+       pr_raw("'%s': ", test->name);
+
+       test->func();
+
+       if (globals.test_ctx.test_failed) {
+               globals.tests_failed++;
+               set_color(CREDBOLD);
+               pr_raw("FAILED:");
+               reset_color();
+               set_color(CRED);
+               pr_raw("\n\t\t'%s': %s\n",
+                      test->name, globals.test_ctx.failed_msg);
+               reset_color();
+               free(globals.test_ctx.failed_msg);
+       } else {
+               set_color(CGREEN);
+               pr_raw("OK\n");
+               reset_color();
+       }
+}
+
 static void test_teardown(void)
 {
        struct mockup_chip *chip;
@@ -553,28 +577,7 @@ int main(int argc GU_UNUSED, char **argv GU_UNUSED)
 
        for (test = globals.test_list_head; test; test = test->_next) {
                test_prepare(&test->chip_descr);
-
-               print_header("TEST", CYELLOW);
-               pr_raw("'%s': ", test->name);
-
-               test->func();
-
-               if (globals.test_ctx.test_failed) {
-                       globals.tests_failed++;
-                       set_color(CREDBOLD);
-                       pr_raw("FAILED:");
-                       reset_color();
-                       set_color(CRED);
-                       pr_raw("\n\t\t'%s': %s\n",
-                              test->name, globals.test_ctx.failed_msg);
-                       reset_color();
-                       free(globals.test_ctx.failed_msg);
-               } else {
-                       set_color(CGREEN);
-                       pr_raw("OK\n");
-                       reset_color();
-               }
-
+               test_run(test);
                test_teardown();
        }