Fix sorting order for test fixtures to get consistent behaviour across different platforms (#1145)
This commit is contained in:
parent
a62c932a8f
commit
41a46364c8
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <list>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
std::ostringstream errout;
|
std::ostringstream errout;
|
||||||
|
@ -33,21 +32,27 @@ std::ostringstream output;
|
||||||
* TestRegistry
|
* TestRegistry
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class TestRegistry {
|
struct CompareFixtures {
|
||||||
private:
|
bool operator()(const TestFixture* lhs, const TestFixture* rhs) {
|
||||||
std::list<TestFixture *> _tests;
|
return lhs->classname < rhs->classname;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::set<TestFixture*, CompareFixtures> TestSet;
|
||||||
|
class TestRegistry {
|
||||||
|
TestSet _tests;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static TestRegistry &theInstance() {
|
static TestRegistry &theInstance() {
|
||||||
static TestRegistry testreg;
|
static TestRegistry testreg;
|
||||||
return testreg;
|
return testreg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addTest(TestFixture *t) {
|
void addTest(TestFixture *t) {
|
||||||
_tests.push_back(t);
|
_tests.insert(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::list<TestFixture *> &tests() const {
|
const TestSet &tests() const {
|
||||||
return _tests;
|
return _tests;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -68,8 +73,8 @@ std::size_t TestFixture::succeeded_todos_counter = 0;
|
||||||
std::set<std::string> TestFixture::missingLibs;
|
std::set<std::string> TestFixture::missingLibs;
|
||||||
|
|
||||||
TestFixture::TestFixture(const char * const _name)
|
TestFixture::TestFixture(const char * const _name)
|
||||||
:classname(_name)
|
:quiet_tests(false),
|
||||||
,quiet_tests(false)
|
classname(_name)
|
||||||
{
|
{
|
||||||
TestRegistry::theInstance().addTest(this);
|
TestRegistry::theInstance().addTest(this);
|
||||||
}
|
}
|
||||||
|
@ -287,9 +292,9 @@ std::size_t TestFixture::runTests(const options& args)
|
||||||
countTests = 0;
|
countTests = 0;
|
||||||
errmsg.str("");
|
errmsg.str("");
|
||||||
|
|
||||||
const std::list<TestFixture *> &tests = TestRegistry::theInstance().tests();
|
const TestSet &tests = TestRegistry::theInstance().tests();
|
||||||
|
|
||||||
for (std::list<TestFixture *>::const_iterator it = tests.begin(); it != tests.end(); ++it) {
|
for (TestSet::const_iterator it = tests.begin(); it != tests.end(); ++it) {
|
||||||
if (classname.empty() || (*it)->classname == classname) {
|
if (classname.empty() || (*it)->classname == classname) {
|
||||||
(*it)->processOptions(args);
|
(*it)->processOptions(args);
|
||||||
(*it)->run(testname);
|
(*it)->run(testname);
|
||||||
|
|
|
@ -39,7 +39,6 @@ private:
|
||||||
static std::set<std::string> missingLibs;
|
static std::set<std::string> missingLibs;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string classname;
|
|
||||||
std::string testToRun;
|
std::string testToRun;
|
||||||
bool quiet_tests;
|
bool quiet_tests;
|
||||||
|
|
||||||
|
@ -73,6 +72,7 @@ public:
|
||||||
virtual void reportOut(const std::string &outmsg);
|
virtual void reportOut(const std::string &outmsg);
|
||||||
virtual void reportErr(const ErrorLogger::ErrorMessage &msg);
|
virtual void reportErr(const ErrorLogger::ErrorMessage &msg);
|
||||||
void run(const std::string &str);
|
void run(const std::string &str);
|
||||||
|
const std::string classname;
|
||||||
|
|
||||||
explicit TestFixture(const char * const _name);
|
explicit TestFixture(const char * const _name);
|
||||||
virtual ~TestFixture() { }
|
virtual ~TestFixture() { }
|
||||||
|
|
Loading…
Reference in New Issue