Skip to content
Snippets Groups Projects
Commit 2c57e513 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Testsuite: prevented warning messages from showing up by default.

parent 00194238
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
......
......@@ -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);
......
......@@ -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");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.