Add option to suppress log output when testing

This commit is contained in:
Benedikt Heine 2017-12-07 20:35:20 +01:00
parent cad2ac34f9
commit 2c503c2984
4 changed files with 20 additions and 5 deletions

View File

@ -129,7 +129,7 @@ int dunst_main(int argc, char *argv[])
cmdline_load(argc, argv);
dunst_log_init();
dunst_log_init(false);
if (cmdline_get_bool("-v/-version", false, "Print version")
|| cmdline_get_bool("--version", false, "Print version")) {

View File

@ -19,13 +19,18 @@ static const char *log_level_to_string(GLogLevelFlags level)
/*
* Log handling function for GLib's logging wrapper
*
* If the gpointer is valid, do not do anything
*/
static void dunst_log_handler(
const gchar *log_domain,
GLogLevelFlags message_level,
const gchar *message,
gpointer user_data)
gpointer testing)
{
if (testing)
return;
const char *log_level_str =
log_level_to_string(message_level & G_LOG_LEVEL_MASK);
@ -38,10 +43,13 @@ static void dunst_log_handler(
/*
* Initialise log handling. Can be called any time.
*
* If bool is %TRUE, it suppresses all logging output.
* Primarily used for testing
*/
void dunst_log_init(void)
void dunst_log_init(bool testing)
{
g_log_set_default_handler(dunst_log_handler, NULL);
g_log_set_default_handler(dunst_log_handler, (void*)testing);
}
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */

View File

@ -14,7 +14,7 @@
#define LOG_I g_info
#define LOG_D g_debug
void dunst_log_init(void);
void dunst_log_init(bool testing);
#endif
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */

View File

@ -1,5 +1,9 @@
#include "greatest.h"
#include <stdbool.h>
#include "src/log.h"
SUITE_EXTERN(suite_utils);
SUITE_EXTERN(suite_option_parser);
SUITE_EXTERN(suite_notification);
@ -8,6 +12,9 @@ SUITE_EXTERN(suite_markup);
GREATEST_MAIN_DEFS();
int main(int argc, char *argv[]) {
// do not print out warning messages, when executing tests
dunst_log_init(true);
GREATEST_MAIN_BEGIN();
RUN_SUITE(suite_utils);
RUN_SUITE(suite_option_parser);