@@ -99,21 +99,24 @@ bool TestFixture::prepareTest(const char testname[])
9999 prepareTestInternal ();
100100
101101 // Check if tests should be executed
102- if (testToRun.empty () || testToRun == testname) {
103- // Tests will be executed - prepare them
104- mTestname = testname;
105- ++countTests;
106- std::string fullTestName = classname + " ::" + mTestname ;
107- if (quiet_tests) {
108- std::putchar (' .' ); // Use putchar to write through redirection of std::cout/cerr
109- std::fflush (stdout);
110- } else {
111- std::cout << fullTestName << std::endl;
112- }
113- mTimer .reset (new Timer (fullTestName, ShowTime::TOP5_SUMMARY, timerResults));
114- return !dry_run;
102+ if (!testsToRun.empty ()) {
103+ const bool match = testsToRun.count (testname);
104+ if ((match && exclude_tests) || (!match && !exclude_tests))
105+ return false ;
106+ }
107+
108+ // Tests will be executed - prepare them
109+ mTestname = testname;
110+ ++countTests;
111+ std::string fullTestName = classname + " ::" + mTestname ;
112+ if (quiet_tests) {
113+ std::putchar (' .' ); // Use putchar to write through redirection of std::cout/cerr
114+ std::fflush (stdout);
115+ } else {
116+ std::cout << fullTestName << std::endl;
115117 }
116- return false ;
118+ mTimer .reset (new Timer (fullTestName, ShowTime::TOP5_SUMMARY, timerResults));
119+ return !dry_run;
117120}
118121
119122void TestFixture::teardownTest ()
@@ -358,9 +361,9 @@ void TestFixture::printHelp()
358361 " -x Exclude the specified tests.\n " ;
359362}
360363
361- void TestFixture::run (const std::string &str )
364+ void TestFixture::run (const std::set<std:: string> &tests )
362365{
363- testToRun = str ;
366+ testsToRun = tests ;
364367 try {
365368 if (quiet_tests) {
366369 std::cout << ' \n ' << classname << ' :' ;
@@ -388,6 +391,7 @@ void TestFixture::processOptions(const options& args)
388391{
389392 quiet_tests = args.quiet ();
390393 dry_run = args.dry_run ();
394+ exclude_tests = args.exclude_tests ();
391395 exename = args.exe ();
392396 timerResults = args.timer_results ();
393397}
@@ -397,29 +401,30 @@ std::size_t TestFixture::runTests(const options& args)
397401 countTests = 0 ;
398402 errmsg.str (" " );
399403
404+ const auto & which_tests = args.which_tests ();
405+ const auto exclude_tests = args.exclude_tests ();
406+
400407 // TODO: bail out when given class/test is not found?
401- for (std::string classname : args.which_test ()) {
402- std::string testname;
403- const std::string::size_type pos = classname.find (" ::" );
404- if (pos != std::string::npos) {
405- // TODO: excluding indiviual tests is not supported yet
406- testname = classname.substr (pos + 2 );
407- classname.erase (pos);
408+ for (TestInstance * test : TestRegistry::theInstance ().tests ())
409+ {
410+ std::set<std::string> tests;
411+ if (!which_tests.empty ()) {
412+ const auto it = which_tests.find (test->classname );
413+ const bool match = it != which_tests.cend ();
414+ if (match && exclude_tests && it->second .empty ()) // only bailout when the whole fixture is excluded
415+ continue ;
416+ if (!match && !exclude_tests)
417+ continue ;
418+ if (match)
419+ tests = it->second ;
408420 }
409421
410- for (TestInstance * test : TestRegistry::theInstance ().tests ()) {
411- if (!classname.empty ()) {
412- const bool match = test->classname == classname;
413- if ((match && args.exclude_tests ()) || (!match && !args.exclude_tests ()))
414- continue ;
415- }
416-
417422 TestFixture* fixture;
418423 Timer::run (test->classname + " - create" , ShowTime::TOP5_SUMMARY, args.timer_results (), [&](){
419424 fixture = test->create ();
420425 });
421426 fixture->processOptions (args);
422- fixture->run (testname );
427+ fixture->run (tests );
423428 }
424429
425430 if (args.summary () && !args.dry_run ()) {
0 commit comments