[Cppunit-cvs] cppunit2/src/cpput assert.cpp,1.16,1.17 exceptionguard.cpp,1.8,1.9 lighttestrunner.cpp
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-11-11 20:54:24
|
Update of /cvsroot/cppunit/cppunit2/src/cpput In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6524/src/cpput Modified Files: assert.cpp exceptionguard.cpp lighttestrunner.cpp testcase.cpp testinfo.cpp Log Message: - added unit tests for TestInfo - fixed bug in CPPUT_IGNORE_FAILURE and exception guard. - added 'isIgnoredFailure' to Assertion. - lighttestrunner now print ignored failure and skipped tests. Index: assert.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/assert.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** assert.cpp 9 Nov 2005 20:04:06 -0000 1.16 --- assert.cpp 11 Nov 2005 20:54:15 -0000 1.17 *************** *** 120,124 **** skipCurrentTest() { ! TestStatus &status = TestInfo::threadInstance().getUpdatedTestStatus(); if ( status.hasPassed() ) status.setStatus( TestStatus::skipped ); --- 120,124 ---- skipCurrentTest() { ! TestStatus &status = TestInfo::threadInstance().testStatus(); if ( status.hasPassed() ) status.setStatus( TestStatus::skipped ); Index: exceptionguard.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/exceptionguard.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** exceptionguard.cpp 9 Nov 2005 20:04:06 -0000 1.8 --- exceptionguard.cpp 11 Nov 2005 20:54:15 -0000 1.9 *************** *** 35,39 **** else context.test_(); ! return !(TestInfo::threadInstance().getUpdatedTestStatus().hasFailed()); } --- 35,39 ---- else context.test_(); ! return !(TestInfo::threadInstance().testStatus().hasFailed()); } Index: lighttestrunner.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/lighttestrunner.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** lighttestrunner.cpp 9 Nov 2005 22:42:31 -0000 1.11 --- lighttestrunner.cpp 11 Nov 2005 20:54:15 -0000 1.12 *************** *** 11,14 **** --- 11,16 ---- : testRun_( 0 ) , testFailed_( 0 ) + , testSkipped_( 0 ) + , ignoredFailureCount_( 0 ) { } *************** *** 37,51 **** fprintf( stdout, "Failure report:\n%s", report_.c_str() ); fflush( stdout ); ! fprintf( stdout, "%d/%d tests passed, %d tests failed.", testRun_ - testFailed_, testRun_, testFailed_ ); - fflush( stdout ); } else { ! fprintf( stdout, "All %d tests passed.\n", testRun_ ); fflush( stdout ); } return testFailed_ == 0; } --- 39,58 ---- fprintf( stdout, "Failure report:\n%s", report_.c_str() ); fflush( stdout ); ! fprintf( stdout, "%d/%d tests passed, %d tests failed", testRun_ - testFailed_, testRun_, testFailed_ ); } else { ! fprintf( stdout, "All %d tests passed", testRun_ ); fflush( stdout ); } + + if ( ignoredFailureCount_ > 0 ) + fprintf( stdout, ", %d ignored failures", ignoredFailureCount_ ); + fprintf( stdout, ".\n", ignoredFailureCount_ ); + fflush( stdout ); + return testFailed_ == 0; } *************** *** 81,91 **** results_.clear(); ++testRun_; ! bool succeeded = testCase->runTest(); ! fprintf( stdout, "%s\n", succeeded ? "OK" : "FAIL" ); ! fflush( stdout ); ! if ( !succeeded ) { ++testFailed_; CppTL::ConstString resultType = assertions_.back().kind() == Assertion::fault ? "fault" --- 88,122 ---- results_.clear(); ++testRun_; ! testCase->runTest(); ! ! TestStatus &testStatus = TestInfo::threadInstance().testStatus(); ! std::string status; ! switch ( testStatus.status() ) { + case TestStatus::passed: + status = "OK"; + break; + case TestStatus::skipped: + status = "SKIP"; + ++testSkipped_; + break; + case TestStatus::failed: + status = "FAIL"; ++testFailed_; + break; + default: status = "?"; break; + } + + if ( testStatus.ignoredFailureCount() > 0 ) + { + std::string count = CppTL::toString( testStatus.ignoredFailureCount() ).c_str(); + status += " (" + count + " ignored failures)"; + } + + fprintf( stdout, "%s\n", status.c_str() ); + fflush( stdout ); + if ( !assertions_.empty() ) + { CppTL::ConstString resultType = assertions_.back().kind() == Assertion::fault ? "fault" *************** *** 153,156 **** --- 184,192 ---- CppTL::ConstString failureType = failure.kind() == Assertion::fault ? "fault" : "assertion"; + if ( failure.isIgnoredFailure() ) + { + failureType = "*ignored* " + failureType; + ++ignoredFailureCount_; + } report_ += "[failure type: " + failureType + "]\n"; if ( !failure.messages().empty() ) Index: testinfo.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/testinfo.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** testinfo.cpp 9 Nov 2005 20:04:06 -0000 1.19 --- testinfo.cpp 11 Nov 2005 20:54:15 -0000 1.20 *************** *** 15,18 **** --- 15,19 ---- : kind_( kind ) , location_( sourceLocation ) + , isIgnoredFailure_( false ) { } *************** *** 48,51 **** --- 49,65 ---- void + Assertion::setIgnoredFailure() + { + isIgnoredFailure_ = true; + } + + bool + Assertion::isIgnoredFailure() const + { + return isIgnoredFailure_; + } + + + void Assertion::setMessages( const Message &messages ) { *************** *** 127,130 **** --- 141,147 ---- TestStatus::TestStatus( Status status ) : status_( status ) + , assertionCount_( 0 ) + , failedAssertionCount_( 0 ) + , ignoredFailureCount_( 0 ) { } *************** *** 180,183 **** --- 197,238 ---- } + int + TestStatus::assertionCount() const + { + return assertionCount_; + } + + int + TestStatus::failedAssertionCount() const + { + return failedAssertionCount_; + } + + int + TestStatus::ignoredFailureCount() const + { + return ignoredFailureCount_; + } + + void + TestStatus::increaseAssertionCount( int delta ) + { + assertionCount_ += delta; + } + + void + TestStatus::increaseFailedAssertionCount( int delta ) + { + failedAssertionCount_ += delta; + if ( failedAssertionCount_ > 0 && status_ != failed ) + status_ = failed; + } + + void + TestStatus::increaseIgnoredFailureCount( int delta ) + { + ignoredFailureCount_ += delta; + } + // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// *************** *** 200,206 **** TestInfo::TestInfo() : assertionType_( abortingAssertion ) - , assertionCount_( 0 ) - , failedAssertionCount_( 0 ) - , ignoredAssertionCount_( 0 ) , updater_( 0 ) { --- 255,258 ---- *************** *** 214,217 **** --- 266,276 ---- } + + void + TestInfo::removeTestResultUpdater() + { + updater_ = 0; + } + void TestInfo::startNewTest() *************** *** 219,225 **** testStatus_ = TestStatus( TestStatus::passed ); currentAssertion_ = Assertion(); - assertionCount_ = 0; - failedAssertionCount_ = 0; - ignoredAssertionCount_ = 0; assertionType_ = abortingAssertion; } --- 278,281 ---- *************** *** 227,234 **** TestStatus & ! TestInfo::getUpdatedTestStatus() { - if ( !testStatus_.hasFailed() && failedAssertionCount_ > 0 ) - testStatus_.setStatus( TestStatus::failed ); return testStatus_; } --- 283,288 ---- TestStatus & ! TestInfo::testStatus() { return testStatus_; } *************** *** 237,249 **** void TestInfo::newAssertion( AssertionType type, ! const char *fileName, ! unsigned int lineNumber, ! const char *functionName ) { currentAssertion_ = Assertion( Assertion::assertion, ! SourceLocation( fileName, ! lineNumber, ! functionName ) ); ! ++assertionCount_; assertionType_ = type; } --- 291,303 ---- void TestInfo::newAssertion( AssertionType type, ! const char *fileName, ! unsigned int lineNumber, ! const char *functionName ) { currentAssertion_ = Assertion( Assertion::assertion, ! SourceLocation( fileName, ! lineNumber, ! functionName ) ); ! testStatus_.increaseAssertionCount(); assertionType_ = type; } *************** *** 260,264 **** TestInfo::realizeAssertion() { ! ++failedAssertionCount_; if ( updater_ ) --- 314,318 ---- TestInfo::realizeAssertion() { ! testStatus_.increaseFailedAssertionCount(); if ( updater_ ) *************** *** 299,309 **** - void - TestInfo::ignoredFailure() - { - ++ignoredAssertionCount_; - } - - // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// --- 353,356 ---- *************** *** 326,329 **** --- 373,422 ---- // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// + // Class IgnoreFailureScopedContextOverride + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + + TestInfo::IgnoreFailureScopedContextOverride::IgnoreFailureScopedContextOverride( + bool &assertionFailed ) + : assertionFailed_( assertionFailed ) + , assertion_( 0 ) + { + assertionFailed_ = false; + TestInfo::threadInstance().setTestResultUpdater( *this ); + } + + TestInfo::IgnoreFailureScopedContextOverride::~IgnoreFailureScopedContextOverride() + { + TestStatus &testStatus = TestInfo::threadInstance().testStatus(); + assertionFailed_ = !testStatus.hasPassed(); + if ( assertionFailed_ ) + { + context_->testStatus().increaseIgnoredFailureCount( testStatus.failedAssertionCount() ); + if ( assertion_ && context_->updater_ ) + { + perThreadStaticData = context_; // restore context before calling callback + assertion_->setIgnoredFailure(); + context_->updater_->addResultAssertion( *assertion_ ); + } + } + delete assertion_; + } + + void + TestInfo::IgnoreFailureScopedContextOverride::addResultLog( const Json::Value &log ) + { + } + + + void + TestInfo::IgnoreFailureScopedContextOverride::addResultAssertion( const Assertion &assertion ) + { + if ( !assertion_ ) + assertion_ = new Assertion( assertion ); + } + + + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// // Short-hand functions in namespace CppUT // ////////////////////////////////////////////////////////////////// *************** *** 363,366 **** --- 456,464 ---- } + void log( const char *log ) + { + TestInfo::threadInstance().log( log ); + } + void log( const CppTL::ConstString &log ) { Index: testcase.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/testcase.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** testcase.cpp 8 Nov 2005 21:44:55 -0000 1.13 --- testcase.cpp 11 Nov 2005 20:54:15 -0000 1.14 *************** *** 55,59 **** } ! return !TestInfo::threadInstance().getUpdatedTestStatus().hasFailed(); } --- 55,59 ---- } ! return !TestInfo::threadInstance().testStatus().hasFailed(); } |