Result * Suite::run(){ setupTests(); Result * r = new Result( _name ); Result::cur = r; for ( list<TestCase*>::iterator i=_tests.begin(); i!=_tests.end(); i++ ){ TestCase * tc = *i; r->_tests++; bool passes = false; log(1) << "\t" << tc->getName() << endl; try { tc->run(); passes = true; } catch ( ... ){ log() << "unknown exception in test: " << tc->getName() << endl; } if ( ! passes ) r->_fails++; } return r; }
Result * Suite::run(){ tlogLevel = -1; log(1) << "\t about to setupTests" << endl; setupTests(); log(1) << "\t done setupTests" << endl; Result * r = new Result( _name ); Result::cur = r; /* see note in SavedContext */ //writelock lk(""); for ( list<TestCase*>::iterator i=_tests.begin(); i!=_tests.end(); i++ ){ TestCase * tc = *i; r->_tests++; bool passes = false; log(1) << "\t going to run test: " << tc->getName() << endl; stringstream err; err << tc->getName() << "\t"; try { tc->run(); passes = true; } catch ( MyAssertionException * ae ){ err << ae->ss.str(); delete( ae ); } catch ( std::exception& e ){ err << " exception: " << e.what(); } catch ( int x ){ err << " caught int : " << x << endl; } catch ( ... ){ cerr << "unknown exception in test: " << tc->getName() << endl; } if ( ! passes ){ string s = err.str(); log() << "FAIL: " << s << endl; r->_fails++; r->_messages.push_back( s ); } } if ( r->_fails ) r->_rc = 17; log(1) << "\t DONE running tests" << endl; return r; }
Result runTestCase (const TestCase& testCase) { Result result; printf ("%s\n", testCase.getName ().c_str()); intend++; for (auto& it : testCase) { try { if (testCase.setup ()) { testCase.setup () (this); } if (runTest (it.first, it.second)) { result.succeded++; } else { result.failed++; } if (testCase.teardown ()) { testCase.teardown () (this); } } catch (const std::exception& exc) { result.failed++; } } intend--; return result; }
Result * Suite::run(){ setupTests(); Result * r = new Result( _name ); Result::cur = r; for ( list<TestCase*>::iterator i=_tests.begin(); i!=_tests.end(); i++ ){ TestCase * tc = *i; r->_tests++; bool passes = false; log(1) << "\t" << tc->getName() << endl; stringstream err; err << tc->getName() << "\t"; try { tc->run(); passes = true; } catch ( MyAssertionException * ae ){ err << ae->ss.str(); delete( ae ); } catch ( std::exception& e ){ err << " exception " << " : " << e.what(); } catch ( int x ){ err << " caught int : " << x << endl; } catch ( ... ){ cerr << "unknown exception in test: " << tc->getName() << endl; } if ( ! passes ){ r->_fails++; r->_messages.push_back( err.str() ); } } return r; }
void TestSuite::runNextCaseHelper() { TestCase* testCase; // There must be test cases to run. if (mTestCases.size() > 0) { // Increment test case index. mCurrentTestCase ++; // Is this the first test case? if (0 == mCurrentTestCase) { // Signal beginning of the test suite. fireBeginTestSuite(mName); } // If this is not the first test case then // signal the end of the previous test case. else { // Close/clear the previous test case. testCase = mTestCases[mCurrentTestCase - 1]; testCase->clearTimeOut(); testCase->close(); fireEndTestCase(); } // If last test case has been run, reset the // test case index and end the suite. if (mCurrentTestCase >= mTestCases.size()) { mCurrentTestCase = -1; fireEndTestSuite(); return; } // Get the current test case. testCase = mTestCases[mCurrentTestCase]; // Open the current test case. fireBeginTestCase(testCase->getName()); testCase->open(); // Run current test case. testCase->start(); // Note: We do not call fireEndTestCase() here, // because it should not be called until the // current test case has called runNextTestCase(). } }
void DefaultTestPrinter::print( const TestResult *testResult ) { int failures; int successes; int errors; std::string state; std::string name; TestCase *testCase = testResult->getTestCases(); int size = testResult->getTestCaseCount(); printHeader( testResult ); if ( testResult->getTestCaseRanCount() == 0 ) { fprintf( output_, "No test ran\n" ); } for ( int i = 0;i < size;i++ ) { if ( testCase->ran() ) { name = testCase->getName(); failures = testCase->getFailuresCount(); successes = testCase->getSuccessesCount(); errors = testCase->getErrorsCount(); if ( failures > 0 || errors > 0 ) { state = "FAILED"; } else { state = "PASSED"; } fprintf( output_, "Test case \"%s\" %s with %d error(s), %d failure(s) and %d success(es):\n", name.c_str(), state.c_str(), errors, failures, successes ); printTests( testCase ); fprintf( output_, "\n" ); } testCase = testCase->getNext(); } }
Result * Suite::run( const string& filter ) { // set tlogLevel to -1 to suppress tlog() output in a test program tlogLevel = -1; log(1) << "\t about to setupTests" << endl; setupTests(); log(1) << "\t done setupTests" << endl; Result * r = new Result( _name ); Result::cur = r; /* see note in SavedContext */ //writelock lk(""); for ( list<TestCase*>::iterator i=_tests.begin(); i!=_tests.end(); i++ ) { TestCase * tc = *i; if ( filter.size() && tc->getName().find( filter ) == string::npos ) { log(1) << "\t skipping test: " << tc->getName() << " because doesn't match filter" << endl; continue; } r->_tests++; bool passes = false; log(1) << "\t going to run test: " << tc->getName() << endl; stringstream err; err << tc->getName() << "\t"; { scoped_lock lk(minutesRunningMutex); minutesRunning = 0; currentTestName = tc->getName(); } try { tc->run(); passes = true; } catch ( MyAssertionException * ae ) { err << ae->ss.str(); delete( ae ); } catch ( std::exception& e ) { err << " exception: " << e.what(); } catch ( int x ) { err << " caught int : " << x << endl; } catch ( ... ) { cerr << "unknown exception in test: " << tc->getName() << endl; } if ( ! passes ) { string s = err.str(); log() << "FAIL: " << s << endl; r->_fails++; r->_messages.push_back( s ); } } if ( r->_fails ) r->_rc = 17; log(1) << "\t DONE running tests" << endl; return r; }