From e694a23ab28686ecc0635c2ac8c625e743b89a3b Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 16 Jun 2018 16:32:02 +0200 Subject: Experimentally port drumkitparsertest to DGUnit. --- test/dgunit.h | 58 +++++++++++++++++++++++++--------------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) (limited to 'test/dgunit.h') diff --git a/test/dgunit.h b/test/dgunit.h index 4439134..5bb47bb 100644 --- a/test/dgunit.h +++ b/test/dgunit.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -37,11 +38,19 @@ class DGUnit { public: - DGUnit(const std::string& test_name, const std::string& test_suite = "all") - : test_name(test_name) - , test_suite(test_suite) + DGUnit() { - suites.emplace_back(this); + if(DGUnit::suite_list == nullptr) + { + DGUnit::suite_list = this; + return; + } + + auto unit = DGUnit::suite_list; + while(unit->next_unit) + { + } + unit->next_unit = this; } //! Overload to prepare stuff for each of the tests. @@ -52,8 +61,8 @@ public: struct test_result { - const char* func; - const char* file; + std::string func; + std::string file; std::size_t line; std::string msg; int id; @@ -63,9 +72,7 @@ public: //! \param test_suite the name of a test suite or null for all. //! \param test_name the name of a test name inside a test suite. Only valid //! if test_suite is non-null. nullptr for all tests. - static int runTests(std::ofstream& out, - const std::string& test_suite = "all", - const std::string& test_name = "all") + static int runTests(std::ofstream& out) { std::size_t test_num{0}; std::size_t failed{0}; @@ -73,22 +80,8 @@ public: std::list failed_tests; std::list successful_tests; - std::cout << "Run tests\n"; - for(auto suite : suites) + for(auto suite = DGUnit::suite_list; suite; suite = suite->next_unit) { - if(test_suite != "all" && suite->test_suite != test_suite) - { - continue; - } - - if(test_name != "all" && suite->test_name != test_name) - { - continue; - } - - std::cout << "Test: " << suite->test_suite << "::" - << suite->test_name << std::endl; - for(auto test : suite->tests) { ++test_num; @@ -115,7 +108,7 @@ public: fflush(stdout); test_result result{test.second}; result.id = test_num; - successful_tests.emplace_back(result); + successful_tests.push_back(result); } } @@ -134,7 +127,7 @@ public: out << " " << test.msg << "\n"; out << " \n"; } - out << " \n"; + out << " \n"; out << " \n"; for(auto test : successful_tests) { @@ -164,7 +157,7 @@ protected: #define DGUNIT_TEST(func) \ registerTest(this, &func, #func) - void assert(bool value, const char* expr, + void dg_assert(bool value, const char* expr, const char* file, std::size_t line) { if(!value) @@ -177,7 +170,7 @@ protected: } //! Convenience macro to pass along filename and linenumber #define DGUNIT_ASSERT(value) \ - assert(value, #value, __FILE__, __LINE__) + dg_assert(value, #value, __FILE__, __LINE__) template void assert_equal(T expected, T value, @@ -197,12 +190,11 @@ protected: assert_equal(expected, value, __FILE__, __LINE__) private: - static std::list suites; - std::list, const char*>> tests; - const std::string test_name; - const std::string test_suite; + static DGUnit* suite_list; + DGUnit* next_unit{nullptr}; + std::vector, const char*>> tests; }; #ifdef DGUNIT_MAIN -std::list DGUnit::suites; +DGUnit* DGUnit::suite_list{nullptr}; #endif -- cgit v1.2.3