mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[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 {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user