dovecot-2.2: lib-test: more delicate *assert() behaviour when do...

dovecot at dovecot.org dovecot at dovecot.org
Fri Nov 28 08:58:05 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/247f3742a3c2
changeset: 18116:247f3742a3c2
user:      Phil Carmody <phil at dovecot.fi>
date:      Fri Nov 28 10:57:43 2014 +0200
description:
lib-test: more delicate *assert() behaviour when doing fatal tests
We shouldn't be i_asserting ourselves when we're in the state of wanting a
test to fail. Therefore instead test_assert to get the assert message, and
ensure that the success flag is cleared to get the FAILED at the end.

Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib-test/test-common.c |  20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)

diffs (52 lines):

diff -r b7074256cc65 -r 247f3742a3c2 src/lib-test/test-common.c
--- a/src/lib-test/test-common.c	Tue Nov 25 03:48:42 2014 +0200
+++ b/src/lib-test/test-common.c	Fri Nov 28 10:57:43 2014 +0200
@@ -9,6 +9,10 @@
 
 #include <setjmp.h> /* for fatal tests */
 
+/* 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;
+
 #define OUT_NAME_ALIGN 70
 
 static char *test_prefix;
@@ -145,9 +149,12 @@
 
 void test_begin(const char *name)
 {
-	i_assert(test_prefix == NULL);
+	test_success = TRUE;
+	if (!expecting_fatal)
+		i_assert(test_prefix == NULL);
+	else
+		test_assert((test_success = (test_prefix == NULL)));
 	test_prefix = i_strdup(name);
-	test_success = TRUE;
 }
 
 bool test_has_failed(void)
@@ -185,7 +192,10 @@
 
 void test_end(void)
 {
-	i_assert(test_prefix != NULL);
+	if (!expecting_fatal)
+		i_assert(test_prefix != NULL);
+	else
+		test_assert(test_prefix != NULL);
 
 	test_out("", test_success);
 	if (!test_success)
@@ -260,10 +270,6 @@
 	test_success = FALSE;
 }
 
-/* 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;
-
 static void ATTR_FORMAT(2, 0) ATTR_NORETURN
 test_fatal_handler(const struct failure_context *ctx,
 		   const char *format, va_list args)


More information about the dovecot-cvs mailing list