Refactored output_provider -> logger, and moved actual output providers to io/
This commit is contained in:
parent
8659994fa9
commit
554f25608f
13 changed files with 20 additions and 20 deletions
|
@ -127,11 +127,12 @@ set(SOURCE_FILES
|
||||||
src/io/event.h
|
src/io/event.h
|
||||||
src/io/asprintf.c
|
src/io/asprintf.c
|
||||||
src/io/file.c
|
src/io/file.c
|
||||||
|
src/io/output.c
|
||||||
|
src/io/output.h
|
||||||
|
src/io/tap.c
|
||||||
|
src/io/xml.c
|
||||||
src/log/logging.c
|
src/log/logging.c
|
||||||
src/log/output.c
|
|
||||||
src/log/tap.c
|
|
||||||
src/log/normal.c
|
src/log/normal.c
|
||||||
src/log/xml.c
|
|
||||||
src/string/i18n.c
|
src/string/i18n.c
|
||||||
src/string/i18n.h
|
src/string/i18n.h
|
||||||
src/entry/options.c
|
src/entry/options.c
|
||||||
|
@ -168,6 +169,7 @@ set(INTERFACE_FILES
|
||||||
include/criterion/alloc.h
|
include/criterion/alloc.h
|
||||||
include/criterion/parameterized.h
|
include/criterion/parameterized.h
|
||||||
include/criterion/redirect.h
|
include/criterion/redirect.h
|
||||||
|
include/criterion/output.h
|
||||||
)
|
)
|
||||||
|
|
||||||
# Generate the configure file
|
# Generate the configure file
|
||||||
|
|
|
@ -28,7 +28,7 @@ Field Type Description
|
||||||
=================== ================================== ==============================================================
|
=================== ================================== ==============================================================
|
||||||
logging_threshold enum criterion_logging_level The logging level
|
logging_threshold enum criterion_logging_level The logging level
|
||||||
------------------- ---------------------------------- --------------------------------------------------------------
|
------------------- ---------------------------------- --------------------------------------------------------------
|
||||||
output_provider struct criterion_output_provider * The output provider (see below)
|
logger struct criterion_logger * The logger (see below)
|
||||||
------------------- ---------------------------------- --------------------------------------------------------------
|
------------------- ---------------------------------- --------------------------------------------------------------
|
||||||
no_early_exit bool True iff the test worker should exit early
|
no_early_exit bool True iff the test worker should exit early
|
||||||
------------------- ---------------------------------- --------------------------------------------------------------
|
------------------- ---------------------------------- --------------------------------------------------------------
|
||||||
|
@ -75,15 +75,15 @@ Example main
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Implementing your own output provider
|
Implementing your own logger
|
||||||
-------------------------------------
|
----------------------------
|
||||||
|
|
||||||
In case you are not satisfied by the default output provider, you can implement
|
In case you are not satisfied by the default logger, you can implement
|
||||||
yours. To do so, simply set the ``output_provider`` option to your custom
|
yours. To do so, simply set the ``logger`` option to your custom
|
||||||
output provider.
|
logger.
|
||||||
|
|
||||||
Each function contained in the structure is called during one of the standard
|
Each function contained in the structure is called during one of the standard
|
||||||
phase of the criterion runner.
|
phase of the criterion runner.
|
||||||
|
|
||||||
For more insight on how to implement this, see other existing output providers
|
For more insight on how to implement this, see other existing loggers
|
||||||
in ``src/log/``.
|
in ``src/log/``.
|
||||||
|
|
|
@ -103,7 +103,7 @@ CR_API void criterion_log(enum criterion_logging_level level, const char *msg, .
|
||||||
|
|
||||||
# define criterion_perror(...) criterion_plog(CRITERION_IMPORTANT, CRITERION_PREFIX_ERR, __VA_ARGS__)
|
# define criterion_perror(...) criterion_plog(CRITERION_IMPORTANT, CRITERION_PREFIX_ERR, __VA_ARGS__)
|
||||||
|
|
||||||
struct criterion_output_provider {
|
struct criterion_logger {
|
||||||
void (*log_pre_all )(struct criterion_test_set *set);
|
void (*log_pre_all )(struct criterion_test_set *set);
|
||||||
void (*log_pre_suite )(struct criterion_suite_set *set);
|
void (*log_pre_suite )(struct criterion_suite_set *set);
|
||||||
void (*log_pre_init )(struct criterion_test *test);
|
void (*log_pre_init )(struct criterion_test *test);
|
||||||
|
@ -121,7 +121,7 @@ struct criterion_output_provider {
|
||||||
void (*log_post_all )(struct criterion_global_stats *stats);
|
void (*log_post_all )(struct criterion_global_stats *stats);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct criterion_output_provider normal_logging;
|
extern struct criterion_logger normal_logging;
|
||||||
|
|
||||||
CR_END_C_API
|
CR_END_C_API
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
struct criterion_options {
|
struct criterion_options {
|
||||||
enum criterion_logging_level logging_threshold;
|
enum criterion_logging_level logging_threshold;
|
||||||
struct criterion_output_provider *output_provider;
|
struct criterion_logger *logger;
|
||||||
bool no_early_exit;
|
bool no_early_exit;
|
||||||
bool always_succeed;
|
bool always_succeed;
|
||||||
bool use_ascii;
|
bool use_ascii;
|
||||||
|
|
|
@ -46,7 +46,7 @@ DECL_CALL_REPORT_HOOKS(POST_SUITE);
|
||||||
DECL_CALL_REPORT_HOOKS(POST_ALL);
|
DECL_CALL_REPORT_HOOKS(POST_ALL);
|
||||||
|
|
||||||
#define log(Type, ...) \
|
#define log(Type, ...) \
|
||||||
log_(criterion_options.output_provider->log_ ## Type, __VA_ARGS__);
|
log_(criterion_options.logger->log_ ## Type, __VA_ARGS__);
|
||||||
#define log_(Log, ...) \
|
#define log_(Log, ...) \
|
||||||
(Log ? Log(__VA_ARGS__) : nothing());
|
(Log ? Log(__VA_ARGS__) : nothing());
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#include "wrappers/wrap.h"
|
#include "wrappers/wrap.h"
|
||||||
#include "string/i18n.h"
|
#include "string/i18n.h"
|
||||||
#include "io/event.h"
|
#include "io/event.h"
|
||||||
#include "log/output.h"
|
#include "io/output.h"
|
||||||
#include "runner_coroutine.h"
|
#include "runner_coroutine.h"
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
#include "runner.h"
|
#include "runner.h"
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include "criterion/options.h"
|
#include "criterion/options.h"
|
||||||
#include "criterion/ordered-set.h"
|
#include "criterion/ordered-set.h"
|
||||||
#include "core/runner.h"
|
#include "core/runner.h"
|
||||||
#include "log/output.h"
|
#include "io/output.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,6 @@
|
||||||
|
|
||||||
struct criterion_options criterion_options = {
|
struct criterion_options criterion_options = {
|
||||||
.logging_threshold = CRITERION_IMPORTANT,
|
.logging_threshold = CRITERION_IMPORTANT,
|
||||||
.output_provider = &normal_logging,
|
.logger = &normal_logging,
|
||||||
.measure_time = true,
|
.measure_time = true,
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,9 +26,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "criterion/stats.h"
|
#include "criterion/stats.h"
|
||||||
#include "criterion/logging.h"
|
|
||||||
#include "criterion/options.h"
|
#include "criterion/options.h"
|
||||||
#include "criterion/ordered-set.h"
|
|
||||||
#include "compat/posix.h"
|
#include "compat/posix.h"
|
||||||
#include "compat/strtok.h"
|
#include "compat/strtok.h"
|
||||||
#include "compat/time.h"
|
#include "compat/time.h"
|
|
@ -233,7 +233,7 @@ void normal_log_test_abort(CR_UNUSED struct criterion_test_stats *stats, const c
|
||||||
free(dup);
|
free(dup);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct criterion_output_provider normal_logging = {
|
struct criterion_logger normal_logging = {
|
||||||
.log_pre_all = normal_log_pre_all,
|
.log_pre_all = normal_log_pre_all,
|
||||||
.log_pre_init = normal_log_pre_init,
|
.log_pre_init = normal_log_pre_init,
|
||||||
.log_pre_suite = normal_log_pre_suite,
|
.log_pre_suite = normal_log_pre_suite,
|
||||||
|
|
Loading…
Add table
Reference in a new issue