Add option to suppress log output when testing
This commit is contained in:
parent
cad2ac34f9
commit
2c503c2984
@ -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")) {
|
||||
|
14
src/log.c
14
src/log.c
@ -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: */
|
||||
|
@ -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: */
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user