[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:
Justin C. Miller
2022-03-13 17:41:50 -07:00
parent 1cc22e78e2
commit cca07d97b5
2 changed files with 9 additions and 4 deletions

View File

@@ -2,7 +2,7 @@
namespace test {
util::vector<fixture*> registry::m_tests;
util::vector<fixture*> *registry::m_tests = nullptr;
void
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
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
registry::run_all_tests()
{
if (!m_tests)
return 0;
size_t failures = 0;
for (auto *test : m_tests) {
for (auto *test : *m_tests) {
test->test_execute();
failures += test->_test_failure_count;
}

View File

@@ -34,7 +34,7 @@ public:
static size_t run_all_tests();
private:
static util::vector<fixture*> m_tests;
static util::vector<fixture*> *m_tests;
};
template <typename T>