fix static initialisation order issues causing the tests vector to get reset

This commit is contained in:
Crzyrndm 2018-07-07 16:58:59 +12:00
parent 1ab40c8cde
commit 9a9dd64306
2 changed files with 10 additions and 5 deletions

View File

@ -1,6 +1,11 @@
#include "test_suite.hpp"
#include <iostream>
std::vector<std::pair<std::function<void(void)>, std::string>> test_suite::tests;
std::vector<std::pair<std::function<void(void)>, std::string>> &test_suite::tests()
{
static std::vector<std::pair<std::function<void(void)>, std::string>> all_tests;
return all_tests;
}
std::string build_name(const std::string &pretty, const std::string &method)
{
@ -11,12 +16,12 @@ test_status test_suite::go()
{
test_status status;
for (auto test : tests)
for (auto test : tests())
{
try
{
test.first();
std::cout << ".";
std::cout << '.';
status.tests_passed++;
}
catch (std::exception &ex)

View File

@ -31,9 +31,9 @@ public:
protected:
static void register_test_internal(std::function<void()> t, const std::string &function)
{
tests.push_back(std::make_pair(t, function));
tests().push_back(std::make_pair(t, function));
}
private:
static std::vector<std::pair<std::function<void()>, std::string>> tests;
static std::vector<std::pair<std::function<void(void)>, std::string>> &tests();
};