From 2c57e513ffaf56f58b90115d64915b361ed33e90 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan@rename-it.nl> Date: Tue, 3 Aug 2010 12:29:46 +0200 Subject: [PATCH] Testsuite: prevented warning messages from showing up by default. --- src/testsuite/testsuite-log.c | 93 +++++++++++++++++++++++------------ src/testsuite/testsuite-log.h | 11 ++++- src/testsuite/testsuite.c | 14 +++--- 3 files changed, 78 insertions(+), 40 deletions(-) diff --git a/src/testsuite/testsuite-log.c b/src/testsuite/testsuite-log.c index 309572615..97b54a194 100644 --- a/src/testsuite/testsuite-log.c +++ b/src/testsuite/testsuite-log.c @@ -11,21 +11,24 @@ #include "testsuite-log.h" +/* + * Configuration + */ + +bool _testsuite_log_stdout = FALSE; + /* - * Testsuite error handler + * Testsuite log error handlers */ struct sieve_error_handler *testsuite_log_ehandler = NULL; +struct sieve_error_handler *testsuite_log_main_ehandler = NULL; struct _testsuite_log_message { const char *location; const char *message; }; -bool _testsuite_log_stdout = FALSE; - -unsigned int _testsuite_log_error_index = 0; - static pool_t _testsuite_logmsg_pool = NULL; ARRAY_DEFINE(_testsuite_log_errors, struct _testsuite_log_message); ARRAY_DEFINE(_testsuite_log_warnings, struct _testsuite_log_message); @@ -41,7 +44,13 @@ static void _testsuite_log_verror { va_list args_copy; VA_COPY(args_copy, args); - printf("error: %s: %s.\n", location, t_strdup_vprintf(fmt, args_copy)); + + if ( location == NULL || *location == '\0' ) + fprintf(stdout, + "LOG: error: %s.\n", t_strdup_vprintf(fmt, args_copy)); + else + fprintf(stdout, + "LOG: error: %s: %s.\n", location, t_strdup_vprintf(fmt, args_copy)); } msg.location = p_strdup(pool, location); @@ -50,6 +59,18 @@ static void _testsuite_log_verror array_append(&_testsuite_log_errors, &msg, 1); } +static void _testsuite_log_main_verror +(struct sieve_error_handler *ehandler ATTR_UNUSED, const char *location, + const char *fmt, va_list args) +{ + if ( location == NULL || *location == '\0' ) + fprintf(stderr, + "error: %s.\n", t_strdup_vprintf(fmt, args)); + else + fprintf(stderr, + "%s: error: %s.\n", location, t_strdup_vprintf(fmt, args)); +} + static void _testsuite_log_vwarning (struct sieve_error_handler *ehandler ATTR_UNUSED, const char *location, const char *fmt, va_list args) @@ -61,7 +82,13 @@ static void _testsuite_log_vwarning { va_list args_copy; VA_COPY(args_copy, args); - printf("warning: %s: %s.\n", location, t_strdup_vprintf(fmt, args_copy)); + + if ( location == NULL || *location == '\0' ) + fprintf(stdout, + "LOG: warning: %s.\n", t_strdup_vprintf(fmt, args_copy)); + else + fprintf(stdout, + "LOG: warning: %s: %s.\n", location, t_strdup_vprintf(fmt, args_copy)); } msg.location = p_strdup(pool, location); @@ -75,11 +102,8 @@ static struct sieve_error_handler *_testsuite_log_ehandler_create(void) pool_t pool; struct sieve_error_handler *ehandler; - /* Pool is not strictly necessary, but other handler types will need a pool, - * so this one will have one too. - */ pool = pool_alloconly_create - ("testsuite_log_handler", sizeof(struct sieve_error_handler)); + ("testsuite_log_ehandler", sizeof(struct sieve_error_handler)); ehandler = p_new(pool, struct sieve_error_handler, 1); sieve_error_handler_init(ehandler, pool, 0); @@ -89,6 +113,26 @@ static struct sieve_error_handler *_testsuite_log_ehandler_create(void) return ehandler; } +static struct sieve_error_handler *_testsuite_log_main_ehandler_create(void) +{ + pool_t pool; + struct sieve_error_handler *ehandler; + + pool = pool_alloconly_create + ("testsuite_log_main_ehandler", sizeof(struct sieve_error_handler)); + ehandler = p_new(pool, struct sieve_error_handler, 1); + sieve_error_handler_init(ehandler, pool, 0); + + ehandler->verror = _testsuite_log_main_verror; + ehandler->vwarning = _testsuite_log_vwarning; + + return ehandler; +} + +/* + * + */ + void testsuite_log_clear_messages(void) { if ( _testsuite_logmsg_pool != NULL ) { @@ -106,25 +150,9 @@ void testsuite_log_clear_messages(void) sieve_error_handler_reset(testsuite_log_ehandler); } -void testsuite_log_get_error_init(void) -{ - _testsuite_log_error_index = 0; -} - -const char *testsuite_log_get_error_next(bool location) -{ - const struct _testsuite_log_message *msg; - - if ( _testsuite_log_error_index >= array_count(&_testsuite_log_errors) ) - return NULL; - - msg = array_idx(&_testsuite_log_errors, _testsuite_log_error_index++); - - if ( location ) - return msg->location; - - return msg->message; -} +/* + * + */ void testsuite_log_init(bool log_stdout) { @@ -133,6 +161,8 @@ void testsuite_log_init(bool log_stdout) testsuite_log_ehandler = _testsuite_log_ehandler_create(); sieve_error_handler_accept_infolog(testsuite_log_ehandler, TRUE); + testsuite_log_main_ehandler = _testsuite_log_main_ehandler_create(); + sieve_system_ehandler_set(testsuite_log_ehandler); testsuite_log_clear_messages(); @@ -143,12 +173,13 @@ void testsuite_log_deinit(void) sieve_system_ehandler_reset(); sieve_error_handler_unref(&testsuite_log_ehandler); + sieve_error_handler_unref(&testsuite_log_main_ehandler); pool_unref(&_testsuite_logmsg_pool); } /* - * Result stringlist + * Log stringlist */ /* Forward declarations */ diff --git a/src/testsuite/testsuite-log.h b/src/testsuite/testsuite-log.h index d5e8c6d59..f909301cb 100644 --- a/src/testsuite/testsuite-log.h +++ b/src/testsuite/testsuite-log.h @@ -7,13 +7,20 @@ #include "sieve-common.h" extern struct sieve_error_handler *testsuite_log_ehandler; +extern struct sieve_error_handler *testsuite_log_main_ehandler; + +/* + * Initialization + */ void testsuite_log_init(bool log_stdout); void testsuite_log_deinit(void); +/* + * Access + */ + void testsuite_log_clear_messages(void); -void testsuite_log_get_error_init(void); -const char *testsuite_log_get_error_next(bool location); struct sieve_stringlist *testsuite_log_stringlist_create (const struct sieve_runtime_env *renv, int index); diff --git a/src/testsuite/testsuite.c b/src/testsuite/testsuite.c index 27df768f4..dfbaffcf4 100644 --- a/src/testsuite/testsuite.c +++ b/src/testsuite/testsuite.c @@ -19,6 +19,7 @@ #include "sieve-tool.h" #include "testsuite-common.h" +#include "testsuite-log.h" #include "testsuite-settings.h" #include "testsuite-result.h" #include "testsuite-message.h" @@ -163,8 +164,8 @@ int main(int argc, char **argv) ("sieve_global_dir", t_strconcat(sieve_dir, "included-global", NULL)); /* Compile sieve script */ - if ( (sbin = sieve_tool_script_compile(svinst, scriptfile, NULL)) != NULL ) { - struct sieve_error_handler *ehandler; + if ( (sbin = sieve_compile + (svinst, scriptfile, NULL, testsuite_log_main_ehandler)) != NULL ) { struct ostream *tracestream = NULL; struct sieve_script_env scriptenv; @@ -193,19 +194,18 @@ int main(int argc, char **argv) testsuite_result_init(); /* Run the test */ - ehandler = sieve_stderr_ehandler_create(0); - ret = testsuite_run(sbin, &testsuite_msgdata, &scriptenv, ehandler); - sieve_error_handler_unref(&ehandler); + ret = testsuite_run + (sbin, &testsuite_msgdata, &scriptenv, testsuite_log_main_ehandler); switch ( ret ) { case SIEVE_EXEC_OK: break; case SIEVE_EXEC_FAILURE: case SIEVE_EXEC_KEEP_FAILED: - testsuite_testcase_fail("execution aborted"); + testsuite_testcase_fail("test script execution aborted due to error"); break; case SIEVE_EXEC_BIN_CORRUPT: - testsuite_testcase_fail("binary corrupt"); + testsuite_testcase_fail("compiled test script binary is corrupt"); break; default: testsuite_testcase_fail("unknown execution exit code"); -- GitLab