dovecot-2.2: lib-test: test_expect_error_string() to match a sin...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jun 15 11:40:24 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/8739d201898c
changeset: 18853:8739d201898c
user: Phil Carmody <phil at dovecot.fi>
date: Mon Jun 15 14:31:19 2015 +0300
description:
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 at dovecot.fi>
diffstat:
src/lib-test/test-common.c | 14 +++++++++++++-
src/lib-test/test-common.h | 1 +
2 files changed, 14 insertions(+), 1 deletions(-)
diffs (56 lines):
diff -r 3275eee3613b -r 8739d201898c 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
@@ -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;
}
diff -r 3275eee3613b -r 8739d201898c 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
@@ -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);
More information about the dovecot-cvs
mailing list