From 955f324bfd9e7b5962977108cf7e8a6028a021c7 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Mon, 31 Oct 2016 15:37:00 +0200 Subject: [PATCH] lib-test: Do not init/deinit library twice If lib is initialized, do not initialize or deinitialize library. This is done to allow using master_service in unit tests which also wants to perform lib init and deinit itself. --- src/lib-test/test-common.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib-test/test-common.c b/src/lib-test/test-common.c index 3f7cf976e9..95f5be3a25 100644 --- a/src/lib-test/test-common.c +++ b/src/lib-test/test-common.c @@ -7,6 +7,8 @@ #include /* _exit() */ #include /* for fatal tests */ +static bool test_deinit_lib; + /* To test the firing of i_assert, we need non-local jumps, i.e. setjmp */ static volatile bool expecting_fatal = FALSE; static jmp_buf fatal_jmpbuf; @@ -206,7 +208,12 @@ static void test_init(void) failure_count = 0; total_count = 0; - lib_init(); + if (!lib_is_initialized()) { + lib_init(); + test_deinit_lib = TRUE; + } else + test_deinit_lib = FALSE; + i_set_error_handler(test_error_handler); /* Don't set fatal handler until actually needed for fatal testing */ } @@ -215,7 +222,8 @@ static int test_deinit(void) { i_assert(test_prefix == NULL); printf("%u / %u tests failed\n", failure_count, total_count); - lib_deinit(); + if (test_deinit_lib) + lib_deinit(); return failure_count == 0 ? 0 : 1; } -- 2.47.3