bool Runner::runAllTest(bool printSummary) const { unsigned int count = testCount(); std::deque<TestResult> failures; for (unsigned int index = 0; index < count; ++index) { TestResult result; runTestAt(index, result); if (result.failed()) { failures.push_back(result); } } if (failures.empty()) { if (printSummary) { printf("All %d tests passed\n", count); } return true; } else { for (unsigned int index = 0; index < failures.size(); ++index) { TestResult& result = failures[index]; result.printFailure(count > 1); } if (printSummary) { unsigned int failedCount = static_cast<unsigned int>(failures.size()); unsigned int passedCount = count - failedCount; printf("%d/%d tests passed (%d failure(s))\n", passedCount, count, failedCount); } return false; } }
void Runner::runTestAt( unsigned int index, TestResult &result ) const { TestCase *test = tests_[index](); result.setTestName( test->testName() ); printf( "Testing %s: ", test->testName() ); fflush( stdout ); #if JSON_USE_EXCEPTION try { #endif // if JSON_USE_EXCEPTION test->run( result ); #if JSON_USE_EXCEPTION } catch ( const std::exception &e ) { result.addFailure( __FILE__, __LINE__, "Unexpected exception caugth:" ) << e.what(); } #endif // if JSON_USE_EXCEPTION delete test; const char *status = result.failed() ? "FAILED" : "OK"; printf( "%s\n", status ); fflush( stdout ); }