From 3ec3ef32b3366c18005277c216d175a144edc477 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Wed, 24 Oct 2012 12:33:15 +0200 Subject: [PATCH] Way to run particular unit tests instead of all tests --- src/tests/main.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/tests/main.cpp b/src/tests/main.cpp index aea740f0..218d66fb 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -22,6 +22,16 @@ int main (int argc, char* argv[]) root->addAppender(new FileAppender(new PatternLayout("%d %-5p %c: %m%n"), "libtransport_test.log", false)); #endif + std::vector testsToRun; + for (int i = 1; i < argc; ++i) { + std::string param(argv[i]); + testsToRun.push_back(param); + } + + if (testsToRun.empty()) { + testsToRun.push_back(""); + } + // informs test-listener about testresults CPPUNIT_NS :: TestResult testresult; @@ -36,7 +46,15 @@ int main (int argc, char* argv[]) // insert test-suite at test-runner by registry CPPUNIT_NS :: TestRunner testrunner; testrunner.addTest (CPPUNIT_NS :: TestFactoryRegistry :: getRegistry ().makeTest ()); - testrunner.run (testresult); + for (std::vector::const_iterator i = testsToRun.begin(); i != testsToRun.end(); ++i) { + try { + testrunner.run(testresult, *i); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + return -1; + } + } // output results in compiler-format CPPUNIT_NS :: CompilerOutputter compileroutputter (&collectedresults, std::cerr);