mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
fix static initialisation order issues causing the tests vector to get reset
This commit is contained in:
parent
51545734e8
commit
bf5105f0a3
48
tests/helpers/test_suite.cpp
Normal file
48
tests/helpers/test_suite.cpp
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
return pretty.substr(0, pretty.find("::") + 2) + method;
|
||||||
|
}
|
||||||
|
|
||||||
|
test_status test_suite::go()
|
||||||
|
{
|
||||||
|
test_status status;
|
||||||
|
|
||||||
|
for (auto test : tests())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
test.first();
|
||||||
|
std::cout << '.';
|
||||||
|
status.tests_passed++;
|
||||||
|
}
|
||||||
|
catch (std::exception &ex)
|
||||||
|
{
|
||||||
|
std::string fail_msg = test.second + " failed with:\n" + std::string(ex.what());
|
||||||
|
std::cout << "*\n"
|
||||||
|
<< fail_msg << '\n';
|
||||||
|
status.tests_failed++;
|
||||||
|
status.failures.push_back(fail_msg);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
std::cout << "*\n"
|
||||||
|
<< test.second << " failed\n";
|
||||||
|
status.tests_failed++;
|
||||||
|
status.failures.push_back(test.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout.flush();
|
||||||
|
status.tests_run++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
|
@ -36,7 +36,7 @@ public:
|
||||||
{
|
{
|
||||||
test_status status;
|
test_status status;
|
||||||
|
|
||||||
for (auto test : tests)
|
for (auto test : tests())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -69,9 +69,9 @@ public:
|
||||||
protected:
|
protected:
|
||||||
static void register_test_internal(std::function<void()> t, const std::string &function)
|
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:
|
private:
|
||||||
static std::vector<std::pair<std::function<void(void)>, std::string>> tests;
|
static std::vector<std::pair<std::function<void(void)>, std::string>> &tests();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user