diff options
author | Jakub Hrozek <jakub.hrozek@posteo.se> | 2015-02-04 18:01:02 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2015-02-08 10:29:16 +0100 |
commit | 3e3d6be03d7c596e3ded99061ff70e2bed2a4b2a (patch) | |
tree | 8a5c1b606219b5b691c62a5e54044575aa635243 | |
parent | 3e8d86a7adedd0645e4edb2954f045cb93fa82cc (diff) | |
download | cmocka-3e3d6be03d7c596e3ded99061ff70e2bed2a4b2a.zip cmocka-3e3d6be03d7c596e3ded99061ff70e2bed2a4b2a.tar.gz cmocka-3e3d6be03d7c596e3ded99061ff70e2bed2a4b2a.tar.bz2 |
cmocka: Add a function to select the message output type
Signed-off-by: Jakub Hrozek <jakub.hrozek@posteo.se>
-rw-r--r-- | include/cmocka.h | 17 | ||||
-rw-r--r-- | src/cmocka.c | 33 |
2 files changed, 43 insertions, 7 deletions
diff --git a/include/cmocka.h b/include/cmocka.h index 5eef82f..efadd59 100644 --- a/include/cmocka.h +++ b/include/cmocka.h @@ -1952,6 +1952,23 @@ void print_error(const char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2); void vprint_message(const char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0); void vprint_error(const char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0); +enum cm_message_output { + CM_OUTPUT_STDOUT, +}; + +/** + * @brief Function to set the output format for a test. + * + * The ouput format for the test can either be set globally using this + * function or overriden with environment variable CMOCKA_MESSAGE_OUTPUT. + * + * The environment variable can be set to either STDOUT or SUBUNIT. + * + * @param[in] output The output format to use for the test. + * + */ +void cmocka_set_message_output(enum cm_message_output output); + /** @} */ #endif /* CMOCKA_H_ */ diff --git a/src/cmocka.c b/src/cmocka.c index a767680..fc8c5a1 100644 --- a/src/cmocka.c +++ b/src/cmocka.c @@ -273,6 +273,8 @@ static CMOCKA_THREAD SourceLocation global_last_parameter_location; /* List of all currently allocated blocks. */ static CMOCKA_THREAD ListNode global_allocated_blocks; +static enum cm_message_output global_msg_output = CM_OUTPUT_STDOUT; + #ifndef _WIN32 /* Signals caught by exception_handler(). */ static const int exception_signals[] = { @@ -1934,7 +1936,11 @@ static void cmprintf_standard(enum cm_printf_type type, static void cmprintf_group_start(const size_t num_tests) { - cmprintf_group_start_standard(num_tests); + switch (global_msg_output) { + case CM_OUTPUT_STDOUT: + cmprintf_group_start_standard(num_tests); + break; + } } static void cmprintf_group_finish(size_t total_executed, @@ -1943,18 +1949,31 @@ static void cmprintf_group_finish(size_t total_executed, size_t total_errors, struct CMUnitTestState *cm_tests) { - cmprintf_group_finish_standard(total_executed, - total_passed, - total_failed, - total_errors, - cm_tests); + switch (global_msg_output) { + case CM_OUTPUT_STDOUT: + cmprintf_group_finish_standard(total_executed, + total_passed, + total_failed, + total_errors, + cm_tests); + break; + } } static void cmprintf(enum cm_printf_type type, const char *test_name, const char *error_message) { - cmprintf_standard(type, test_name, error_message); + switch (global_msg_output) { + case CM_OUTPUT_STDOUT: + cmprintf_standard(type, test_name, error_message); + break; + } +} + +void cmocka_set_message_output(enum cm_message_output output) +{ + global_msg_output = output; } /**************************************************************************** |