changeset 21013:c0d9a47756db

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.
author Aki Tuomi <aki.tuomi@dovecot.fi>
date Mon, 31 Oct 2016 15:37:00 +0200
parents 5789122033bc
children c73462b1e164
files src/lib-test/test-common.c
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-test/test-common.c	Mon Oct 31 15:36:39 2016 +0200
+++ b/src/lib-test/test-common.c	Mon Oct 31 15:37:00 2016 +0200
@@ -7,6 +7,8 @@
 #include <unistd.h> /* _exit() */
 #include <setjmp.h> /* 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;
@@ -214,7 +216,12 @@
 	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 */
 }
@@ -223,7 +230,8 @@
 {
 	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;
 }