From 69e5e095813d880a14bc1f5ab3a8d1f66b63a2a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 26 Oct 2008 11:11:26 +0000 Subject: [PATCH] Testing: Only run tests in a specified class --- testrunner.cpp | 4 ++-- testsuite.cpp | 13 +++++++++++-- testsuite.h | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/testrunner.cpp b/testrunner.cpp index 901de37da..d8d1575ec 100644 --- a/testrunner.cpp +++ b/testrunner.cpp @@ -27,10 +27,10 @@ bool CheckCodingStyle = true; extern std::vector Files; -int main() +int main(int argc, const char *argv[]) { Files.push_back( "test.cpp" ); - TestFixture::runTests(); + TestFixture::runTests( (argc==2) ? argv[1] : NULL ); return 0; } diff --git a/testsuite.cpp b/testsuite.cpp index 7cd962262..e5bd5204e 100644 --- a/testsuite.cpp +++ b/testsuite.cpp @@ -103,8 +103,16 @@ void TestFixture::printTests() } } -void TestFixture::runTests() +void TestFixture::runTests(const char cmd[]) { + std::string classname(cmd ? cmd : ""); + std::string testname(""); + if ( classname.find("::") != std::string::npos ) + { + testname = classname.substr( classname.find("::") + 2 ); + classname.erase( classname.find("::") ); + } + countTests = 0; errmsg.str(""); @@ -112,7 +120,8 @@ void TestFixture::runTests() for ( std::list::const_iterator it = tests.begin(); it != tests.end(); ++it ) { - (*it)->run(); + if ( classname.empty() || (*it)->classname == classname ) + (*it)->run(); } std::cout << "\n\nTesting Complete\nNumber of tests: " << countTests << "\n"; diff --git a/testsuite.h b/testsuite.h index 0b2af5316..a1a2ed8df 100644 --- a/testsuite.h +++ b/testsuite.h @@ -22,7 +22,7 @@ public: virtual ~TestFixture() { } static void printTests(); - static void runTests(); + static void runTests(const char cmd[]); };