test_expect_no_more_errors(void)
{
test_assert(expected_errors == 0 && expected_error_str == NULL);
+ i_free_and_null(expected_error_str);
expected_errors = 0;
}
test_error_handler(const struct failure_context *ctx,
const char *format, va_list args)
{
- test_dump_rand_state();
- default_error_handler(ctx, format, args);
+ bool suppress = FALSE;
+
#ifdef DEBUG
if (ctx->type == LOG_TYPE_WARNING &&
strstr(format, "Growing") != NULL) {
#endif
if (expected_errors > 0) {
if (expected_error_str != NULL) {
- test_assert(strstr(format, expected_error_str) != NULL);
- i_free(expected_error_str);
+ /* test_assert() will reset test_success if need be. */
+ suppress = strstr(format, expected_error_str) != NULL;
+ test_assert(suppress == TRUE);
+ i_free_and_null(expected_error_str);
}
expected_errors--;
- return;
+ } else {
+ test_success = FALSE;
+ }
+
+ if (!suppress) {
+ test_dump_rand_state();
+ default_error_handler(ctx, format, args);
}
- test_success = FALSE;
}
static void ATTR_FORMAT(2, 0) ATTR_NORETURN
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);
+/* Note that test_expect_error{s,_string}() effectively begin with a check equivalent
+ to test_expect_no_more_errors(), so you don't need the latter explicitly if following
+ it with either of the former.*/
+
void test_end(void);
void test_out(const char *name, bool success);
{
test_begin("expected messages");
test_expect_errors(1);
- i_warning("deliberate warning - be happy you're seeing this");
+ i_warning("deliberate warning - not suppressed");
test_expect_no_more_errors();
test_end();
}
static void test_expected_str(void)
{
test_begin("expected strings in messages");
- test_expect_error_string("be happy");
- i_error("deliberate error - be happy you're seeing this");
+ test_expect_error_string("be unhappy");
+ i_error("deliberate error - suppressed - be unhappy if you see this");
test_expect_no_more_errors();
test_end();
}