changeset 18853:8739d201898c

lib-test: test_expect_error_string() to match a single known message This gives us very fine control over what is acceptable as an expected warning. Alas you have to do it for each message individually. Signed-off-by: Phil Carmody <phil@dovecot.fi>
author Phil Carmody <phil@dovecot.fi>
date Mon, 15 Jun 2015 14:31:19 +0300
parents 3275eee3613b
children 6d965c726810
files src/lib-test/test-common.c src/lib-test/test-common.h
diffstat 2 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
@@ -20,6 +20,7 @@
 static unsigned int failure_count;
 static unsigned int total_count;
 static unsigned int expected_errors;
+static char *expected_error_str;
 
 struct test_istream {
 	struct istream_private istream;
@@ -258,6 +259,13 @@
 }
 
 void
+test_expect_error_string(const char *substr)
+{
+	i_assert(expected_errors == 0);
+	expected_errors = 1;
+	expected_error_str = i_strdup(substr);
+}
+void
 test_expect_errors(unsigned int expected)
 {
 	i_assert(expected_errors == 0);
@@ -266,7 +274,7 @@
 void
 test_expect_no_more_errors(void)
 {
-	test_assert(expected_errors == 0);
+	test_assert(expected_errors == 0 && expected_error_str == NULL);
 	expected_errors = 0;
 }
 
@@ -285,6 +293,10 @@
 	}
 #endif
 	if (expected_errors > 0) {
+		if (expected_error_str != NULL) {
+			test_assert(strstr(format, expected_error_str) != NULL);
+			i_free(expected_error_str);
+		}
 		expected_errors--;
 		return;
 	}
--- 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
@@ -22,6 +22,7 @@
 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_error_string(const char *substr); /* expect just 1 message matching the printf format */
 void test_expect_no_more_errors(void);
 void test_end(void);