From a7b167032b000d4326177676c76d7bf03f26e861 Mon Sep 17 00:00:00 2001 From: Crzyrndm Date: Thu, 5 Jul 2018 20:46:32 +1200 Subject: [PATCH] Modifications to test suite to support test auto-registration Issue #299 --- tests/helpers/assertions.hpp | 1 + tests/helpers/test_suite.hpp | 13 +++++-- tests/helpers/timing.hpp | 2 +- tests/runner.cpp | 75 +++++------------------------------- 4 files changed, 20 insertions(+), 71 deletions(-) diff --git a/tests/helpers/assertions.hpp b/tests/helpers/assertions.hpp index 8be904d3..531f6afd 100644 --- a/tests/helpers/assertions.hpp +++ b/tests/helpers/assertions.hpp @@ -2,6 +2,7 @@ #include #include +#include #define XLNT_STRINGIFYX(x) #x #define XLNT_STRINGIFY(x) XLNT_STRINGIFYX(x) diff --git a/tests/helpers/test_suite.hpp b/tests/helpers/test_suite.hpp index 02460d96..36010c10 100644 --- a/tests/helpers/test_suite.hpp +++ b/tests/helpers/test_suite.hpp @@ -8,6 +8,11 @@ #include #include +#include +//#include +//#include +#include +#include struct test_status { @@ -17,7 +22,7 @@ struct test_status std::vector failures; }; -std::string build_name(const std::string &pretty, const std::string &method) +inline std::string build_name(const std::string &pretty, const std::string &method) { return pretty.substr(0, pretty.find("::") + 2) + method; } @@ -27,7 +32,7 @@ std::string build_name(const std::string &pretty, const std::string &method) class test_suite { public: - test_status go() + static test_status go() { test_status status; @@ -62,11 +67,11 @@ public: } protected: - void register_test_internal(std::function t, const std::string &function) + static void register_test_internal(std::function t, const std::string &function) { tests.push_back(std::make_pair(t, function)); } private: - std::vector, std::string>> tests; + static std::vector, std::string>> tests; }; diff --git a/tests/helpers/timing.hpp b/tests/helpers/timing.hpp index 5623987a..b2d91869 100644 --- a/tests/helpers/timing.hpp +++ b/tests/helpers/timing.hpp @@ -26,7 +26,7 @@ namespace xlnt { namespace benchmarks { -std::size_t current_time() +inline std::size_t current_time() { auto now = std::chrono::system_clock::now(); auto time_since_epoch = now.time_since_epoch(); diff --git a/tests/runner.cpp b/tests/runner.cpp index 08a589f2..eca211f3 100644 --- a/tests/runner.cpp +++ b/tests/runner.cpp @@ -22,50 +22,18 @@ // @author: see AUTHORS file #include +#include -#include -#include -#include +std::vector, std::string>> test_suite::tests; -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include - -test_status overall_status; - -template -void run_tests() -{ - auto status = T{}.go(); - - overall_status.tests_run += status.tests_run; - overall_status.tests_passed += status.tests_passed; - overall_status.tests_failed += status.tests_failed; - - std::copy(status.failures.begin(), status.failures.end(), std::back_inserter(overall_status.failures)); -} - -void print_summary() +void print_summary(const test_status& results) { std::cout << "\n\n"; - for (auto failure : overall_status.failures) + std::cout << "Passed: " << results.tests_passed << '\n'; + std::cout << "Failed: " << results.tests_failed << '\n'; + + for (auto failure : results.failures) { std::cout << failure << "\n\n"; } @@ -73,34 +41,9 @@ void print_summary() int main() { - // cell - run_tests(); - run_tests(); - run_tests(); + test_status overall_status = test_suite::go(); - // styles - run_tests(); - run_tests(); - run_tests(); - run_tests(); - - // utils - run_tests(); - run_tests(); - run_tests(); - run_tests(); - - // workbook - run_tests(); - run_tests(); - run_tests(); - - // worksheet - run_tests(); - run_tests(); - run_tests(); - - print_summary(); + print_summary(overall_status); return static_cast(overall_status.tests_failed); }