Result * Suite::run( const std::string& filter, int runsPerTest ) { log(1) << "\t about to setupTests" << std::endl; setupTests(); log(1) << "\t done setupTests" << std::endl; Result * r = new Result( _name ); Result::cur = r; for ( std::vector<TestHolder*>::iterator i=_tests.begin(); i!=_tests.end(); i++ ) { TestHolder* tc = *i; if ( filter.size() && tc->getName().find( filter ) == std::string::npos ) { log(1) << "\t skipping test: " << tc->getName() << " because doesn't match filter" << std::endl; continue; } r->_tests++; bool passes = false; onCurrentTestNameChange( tc->getName() ); log() << "\t going to run test: " << tc->getName() << std::endl; std::stringstream err; err << tc->getName() << "\t"; try { for ( int x=0; x<runsPerTest; x++ ) tc->run(); passes = true; } catch ( const TestAssertionFailureException& ae ) { err << ae.toString(); } catch ( const std::exception& e ) { err << " std::exception: " << e.what() << " in test " << tc->getName(); } catch ( int x ) { err << " caught int " << x << " in test " << tc->getName(); } if ( ! passes ) { std::string s = err.str(); log() << "FAIL: " << s << std::endl; r->_fails++; r->_messages.push_back( s ); } } if ( r->_fails ) r->_rc = 17; onCurrentTestNameChange( "" ); log() << "\t DONE running tests" << std::endl; return r; }
Result * Suite::run( const std::string& filter, int runsPerTest ) { setupTests(); Result * r = new Result( _name ); Result::cur = r; for ( std::vector<TestHolder*>::iterator i=_tests.begin(); i!=_tests.end(); i++ ) { TestHolder* tc = *i; r->_tests++; bool passes = false; std::cerr << "\t going to run test: " << tc->getName() << std::endl; std::stringstream err; err << tc->getName() << "\t"; try { for ( int x=0; x<runsPerTest; x++ ) tc->run(); passes = true; } catch ( const TestAssertionFailureException& ae ) { err << ae.toString(); } catch ( const std::exception& e ) { err << " std::exception: " << e.what() << " in test " << tc->getName(); } catch ( int x ) { err << " caught int " << x << " in test " << tc->getName(); } if ( ! passes ) { std::string s = err.str(); std::cerr << "FAIL: " << s << std::endl; r->_fails.push_back(tc->getName()); r->_messages.push_back( s ); } } if ( !r->_fails.empty() ) r->_rc = 17; std::cerr << "\t DONE running tests" << std::endl; return r; }