[test_runner] Fix static ctor ordering bug
The test_runner was potentially initializing the array of tests after tests had been added. Now, allocate the vector dynamically on the first test addition.
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
|
|
||||||
util::vector<fixture*> registry::m_tests;
|
util::vector<fixture*> *registry::m_tests = nullptr;
|
||||||
|
|
||||||
void
|
void
|
||||||
fixture::_log_failure(const char *test_name, const char *message,
|
fixture::_log_failure(const char *test_name, const char *message,
|
||||||
@@ -15,14 +15,19 @@ fixture::_log_failure(const char *test_name, const char *message,
|
|||||||
void
|
void
|
||||||
registry::register_test_case(fixture &test)
|
registry::register_test_case(fixture &test)
|
||||||
{
|
{
|
||||||
m_tests.append(&test);
|
if (!m_tests)
|
||||||
|
m_tests = new util::vector<fixture*>;
|
||||||
|
m_tests->append(&test);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
registry::run_all_tests()
|
registry::run_all_tests()
|
||||||
{
|
{
|
||||||
|
if (!m_tests)
|
||||||
|
return 0;
|
||||||
|
|
||||||
size_t failures = 0;
|
size_t failures = 0;
|
||||||
for (auto *test : m_tests) {
|
for (auto *test : *m_tests) {
|
||||||
test->test_execute();
|
test->test_execute();
|
||||||
failures += test->_test_failure_count;
|
failures += test->_test_failure_count;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public:
|
|||||||
static size_t run_all_tests();
|
static size_t run_all_tests();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static util::vector<fixture*> m_tests;
|
static util::vector<fixture*> *m_tests;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|||||||
Reference in New Issue
Block a user