testsuite : make it possible to run a specific testcase

This commit is contained in:
Daniel Marjamäki 2008-12-17 19:18:39 +00:00
parent fc325ac98a
commit a19b938665
2 changed files with 22 additions and 8 deletions

View File

@ -71,10 +71,14 @@ TestFixture::TestFixture(const std::string &_name) : classname(_name)
bool TestFixture::runTest(const char testname[])
{
countTests++;
std::cout << classname << "::" << testname << "\n";
return true;
{
if ( testToRun.empty() || testToRun == testname )
{
countTests++;
std::cout << classname << "::" << testname << "\n";
return true;
}
return false;
}
static std::string writestr( const std::string &str )
@ -127,6 +131,12 @@ void TestFixture::printTests()
std::cout << (*it)->classname << std::endl;
}
}
void TestFixture::run(const std::string &str)
{
testToRun = str;
run();
}
void TestFixture::runTests(const char cmd[])
{
@ -145,8 +155,10 @@ void TestFixture::runTests(const char cmd[])
for ( std::list<TestFixture *>::const_iterator it = tests.begin(); it != tests.end(); ++it )
{
if ( classname.empty() || (*it)->classname == classname )
(*it)->run();
if ( classname.empty() || (*it)->classname == classname )
{
(*it)->run(testname);
}
}
std::cout << "\n\nTesting Complete\nNumber of tests: " << countTests << "\n";

View File

@ -32,9 +32,9 @@ private:
protected:
std::string classname;
std::string testToRun;
virtual void run()
{ }
virtual void run() = 0;
bool runTest(const char testname[]);
void assertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual);
@ -44,6 +44,8 @@ public:
virtual void reportErr( const std::string &errmsg);
virtual void reportOut( const std::string &outmsg);
void run(const std::string &str);
TestFixture(const std::string &_name);
virtual ~TestFixture() { }