From 2b347407b1157086b58ae9d897e14b77fbdce5b4 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 26 Oct 2020 15:56:44 +0100 Subject: Add test status callback function that can be overridden by a user-implementation if needed. --- uunit.h | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/uunit.h b/uunit.h index 97f3ecc..330ecb6 100644 --- a/uunit.h +++ b/uunit.h @@ -76,8 +76,7 @@ public: } catch(test_result& result) { - std::cout << "F"; - fflush(stdout); + status_cb(test.name, test.file, false); result.id = test_num; result.func = test.name; result.failure_type = "Assertion"; @@ -86,9 +85,8 @@ public: } catch(...) { + status_cb(test.name, test.file, false); test_result result; - std::cout << "F"; - fflush(stdout); result.id = test_num; result.func = test.name; result.file = test.file; @@ -109,8 +107,7 @@ public: failed_tests.push_back(result); continue; } - std::cout << "."; - fflush(stdout); + status_cb(test.name, test.file, true); test_result result{test.name}; result.id = test_num; successful_tests.push_back(result); @@ -159,6 +156,8 @@ public: return failed_tests.size() == 0 ? 0 : 1; } + static std::function status_cb; + protected: template void registerTest(O* obj, const F& fn, const char* name, const char* file) @@ -254,5 +253,28 @@ private: }; #ifdef uUNIT_MAIN + uUnit* uUnit::suite_list{nullptr}; + +namespace +{ +//! Default implementation of test result reporter function. +//! Overload this with your own implementation by assigning the uUnit::status_cb +//! function pointer to a function with the same signature. +void report_result(const char* name, const char* file, bool success) +{ + if(success) + { + std::cout << "."; + } + else + { + std::cout << "F"; + } + std::cout << std::flush; +} +} + +std::function uUnit::status_cb{report_result}; + #endif -- cgit v1.2.3