cmocka: Add a function to select the message output type
authorJakub Hrozek <jakub.hrozek@posteo.se>
Wed, 4 Feb 2015 17:01:02 +0000 (18:01 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Sun, 8 Feb 2015 09:29:16 +0000 (10:29 +0100)
Signed-off-by: Jakub Hrozek <jakub.hrozek@posteo.se>
include/cmocka.h
src/cmocka.c

index 5eef82f..efadd59 100644 (file)
@@ -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_ */
index a767680..fc8c5a1 100644 (file)
@@ -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;
 }
 
 /****************************************************************************