dovecot-2.0-pigeonhole: Testsuite: prevented warning messages fr...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Tue Aug 3 13:30:11 EEST 2010
details: http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/b404d36cdd8d
changeset: 1354:b404d36cdd8d
user: Stephan Bosch <stephan at rename-it.nl>
date: Tue Aug 03 12:29:46 2010 +0200
description:
Testsuite: prevented warning messages from showing up by default.
diffstat:
src/testsuite/testsuite-log.c | 93 +++++++++++++++++++++++++++++++---------------
src/testsuite/testsuite-log.h | 11 ++++-
src/testsuite/testsuite.c | 14 +++---
3 files changed, 78 insertions(+), 40 deletions(-)
diffs (247 lines):
diff -r 3f718ad2060c -r b404d36cdd8d src/testsuite/testsuite-log.c
--- a/src/testsuite/testsuite-log.c Tue Aug 03 03:10:22 2010 +0200
+++ b/src/testsuite/testsuite-log.c Tue Aug 03 12:29:46 2010 +0200
@@ -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 @@
{
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 @@
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 @@
{
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 @@
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 @@
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 @@
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 @@
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 @@
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 -r 3f718ad2060c -r b404d36cdd8d src/testsuite/testsuite-log.h
--- a/src/testsuite/testsuite-log.h Tue Aug 03 03:10:22 2010 +0200
+++ b/src/testsuite/testsuite-log.h Tue Aug 03 12:29:46 2010 +0200
@@ -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 -r 3f718ad2060c -r b404d36cdd8d src/testsuite/testsuite.c
--- a/src/testsuite/testsuite.c Tue Aug 03 03:10:22 2010 +0200
+++ b/src/testsuite/testsuite.c Tue Aug 03 12:29:46 2010 +0200
@@ -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 @@
("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 @@
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");
More information about the dovecot-cvs
mailing list