]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-test: test_expect_error_string() to match a single known message
authorPhil Carmody <phil@dovecot.fi>
Mon, 15 Jun 2015 11:31:19 +0000 (14:31 +0300)
committerPhil Carmody <phil@dovecot.fi>
Mon, 15 Jun 2015 11:31:19 +0000 (14:31 +0300)
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>
src/lib-test/test-common.c
src/lib-test/test-common.h

index 72038a29dbe155694a0efa3a84a4fe7a9517765e..43e72ea719904b2000500b7410d2f59d76f89a56 100644 (file)
@@ -20,6 +20,7 @@ static bool test_success;
 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;
@@ -257,6 +258,13 @@ void test_out_reason(const char *name, bool success, const char *reason)
        total_count++;
 }
 
+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)
 {
@@ -266,7 +274,7 @@ test_expect_errors(unsigned int expected)
 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 @@ test_error_handler(const struct failure_context *ctx,
        }
 #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;
        }
index 0e6f85390782065160f82ebfa6d2aef470c41847..cbb02100738570fc24039814ae83d12c9eb39478 100644 (file)
@@ -22,6 +22,7 @@ void test_assert_failed_idx(const char *code, const char *file, unsigned int lin
 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);