dovecot-2.2: lib-test: let tests invoke i_warning/i_error behaviour

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 15 11:40:23 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/3275eee3613b
changeset: 18852:3275eee3613b
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Jun 15 14:31:19 2015 +0300
description:
lib-test: let tests invoke i_warning/i_error behaviour
Error-handling paths should be testable too. Permit a test case to register
that a known number of warnings/errors are to be expected, and to verify
that those warnings did occur afterwards. Too many messages will fail the
test exactly as it did in the past, they're unexpected messages. However,
too few messages will also cause the test case to fail.

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

diffstat:

 src/lib-test/test-common.c |  18 ++++++++++++++++++
 src/lib-test/test-common.h |   3 +++
 2 files changed, 21 insertions(+), 0 deletions(-)

diffs (55 lines):

diff -r b5608c537daa -r 3275eee3613b src/lib-test/test-common.c
--- a/src/lib-test/test-common.c	Mon Jun 15 14:31:19 2015 +0300
+++ b/src/lib-test/test-common.c	Mon Jun 15 14:31:19 2015 +0300
@@ -19,6 +19,7 @@
 static bool test_success;
 static unsigned int failure_count;
 static unsigned int total_count;
+static unsigned int expected_errors;
 
 struct test_istream {
 	struct istream_private istream;
@@ -256,6 +257,19 @@
 	total_count++;
 }
 
+void
+test_expect_errors(unsigned int expected)
+{
+	i_assert(expected_errors == 0);
+	expected_errors = expected;
+}
+void
+test_expect_no_more_errors(void)
+{
+	test_assert(expected_errors == 0);
+	expected_errors = 0;
+}
+
 static void ATTR_FORMAT(2, 0)
 test_error_handler(const struct failure_context *ctx,
 		   const char *format, va_list args)
@@ -270,6 +284,10 @@
 		return;
 	}
 #endif
+	if (expected_errors > 0) {
+		expected_errors--;
+		return;
+	}
 	test_success = FALSE;
 }
 
diff -r b5608c537daa -r 3275eee3613b src/lib-test/test-common.h
--- a/src/lib-test/test-common.h	Mon Jun 15 14:31:19 2015 +0300
+++ b/src/lib-test/test-common.h	Mon Jun 15 14:31:19 2015 +0300
@@ -20,6 +20,9 @@
 void test_assert_failed(const char *code, const char *file, unsigned int line);
 void test_assert_failed_idx(const char *code, const char *file, unsigned int line, long long i);
 bool test_has_failed(void);
+/* If you're testing nasty cases which you want to warn, surround the noisy op with these */
+void test_expect_errors(unsigned int expected);
+void test_expect_no_more_errors(void);
 void test_end(void);
 
 void test_out(const char *name, bool success);


More information about the dovecot-cvs mailing list