>From e9864067f4a31d18a0829ce7ae1331ea92da65e4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 26 Oct 2014 00:46:58 +0200 Subject: [PATCH 1/3] Refactor: use a dedicated class instead of std::pair<> for the test results. This makes the code more readable and will allow to extend the results returned as a struct is not limited to just two of them, unlike the pair. --- main_wx_test.cpp | 41 ++++++++++++++++++++++++++--------------- 1 files changed, 26 insertions(+), 15 deletions(-) diff --git a/main_wx_test.cpp b/main_wx_test.cpp index 8c1a927..d7a8f5b 100644 --- a/main_wx_test.cpp +++ b/main_wx_test.cpp @@ -52,7 +52,6 @@ #include #include #include -#include // std::pair #include LMI_FORCE_LINKING_EX_SITU(file_command_wx) @@ -109,6 +108,21 @@ class test_assertion_failure_exception } }; +/// Simple struct collecting the statistics about the tests we ran. +/// +/// Implicitly-declared special member functions do the right thing. +struct TestsResults +{ + TestsResults() + :total(0) + ,failed(0) + { + } + + int total, + failed; +}; + /// Run the tests. /// /// This is a simple Meyers singleton. @@ -131,10 +145,7 @@ class application_test // // This function consumes all the exceptions thrown during its execution // and never throws itself. - // - // Return the number of tests executed as the first pair component and the - // number of failed tests as the second component. - std::pair run() /* noexcept */; + TestsResults run() /* noexcept */; // Used by LMI_WX_TEST_CASE() macro to register the individual test cases. void add_test(wx_base_test_case* test); @@ -312,14 +323,14 @@ bool application_test::process_command_line(int& argc, char* argv[]) return true; } -std::pair application_test::run() +TestsResults application_test::run() { // Always run the tests in the same, predictable order (we may want to add // a "random shuffle" option later, but even then predictable behaviour // should arguably remain the default). sort_tests(); - std::pair results(0, 0); + TestsResults results; // Indent the test status reports to make them stand out. char const* const indent = " "; @@ -330,7 +341,7 @@ bool application_test::process_command_line(int& argc, char* argv[]) if ((run_all_ && i->run != run_no) || i->run == run_yes) { std::string error; - results.first++; + results.total++; try { @@ -349,7 +360,7 @@ bool application_test::process_command_line(int& argc, char* argv[]) if (!error.empty()) { - results.second++; + results.failed++; // When logging to a log window, it's better to have everything // on a single line to avoid breaking the output structure. @@ -575,18 +586,18 @@ void SkeletonTest::RunTheTests() // some RAII-based pattern because of application_test::run() noexcept // guarantee. is_running_tests_ = true; - std::pair const results = application_test::instance().run(); + TestsResults const results = application_test::instance().run(); is_running_tests_ = false; - if (results.first == 0) + if (results.total == 0) { wxLogMessage("WARNING: no tests have been executed."); } - else if (results.second == 0) + else if (results.failed == 0) { wxLogMessage ("SUCCESS: %d tests successfully completed in %ldms." - ,results.first + ,results.total ,sw.Time() ); } @@ -594,8 +605,8 @@ void SkeletonTest::RunTheTests() { wxLogMessage ("FAILURE: %d out of %d tests failed." - ,results.second - ,results.first + ,results.failed + ,results.total ); } -- 1.7.9