[Cppunit-cvs] cppunit2/src/cpput SConscript,1.8,1.9 assert.cpp,1.10,1.11 cpput.vcproj,1.37,1.38 exce
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-08-09 05:39:26
|
Update of /cvsroot/cppunit/cppunit2/src/cpput In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31446/src/cpput Modified Files: SConscript assert.cpp cpput.vcproj exceptionguard.cpp lighttestrunner.cpp testcase.cpp testinfo.cpp Log Message: Rewrote failure reporting during test. It now provides more structure while still providing some flexibility. Index: lighttestrunner.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/lighttestrunner.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** lighttestrunner.cpp 7 Aug 2005 08:42:15 -0000 1.3 --- lighttestrunner.cpp 8 Aug 2005 22:10:21 -0000 1.4 *************** *** 35,39 **** if ( testFailed_ > 0 ) { ! printf( "Failure report:\n", report_ ); printf( "%d/%d tests passed, %d tests failed.", testRun_ - testFailed_, --- 35,39 ---- if ( testFailed_ > 0 ) { ! printf( "Failure report:\n", report_.c_str() ); printf( "%d/%d tests passed, %d tests failed.", testRun_ - testFailed_, *************** *** 72,77 **** LightTestRunner::runTestCase( const AbstractTestCasePtr &testCase ) { - result_.clear(); printf( "Testing %s : ", getTestPath().c_str() ); TestInfo::startNewTest(); ++testRun_; --- 72,77 ---- LightTestRunner::runTestCase( const AbstractTestCasePtr &testCase ) { printf( "Testing %s : ", getTestPath().c_str() ); + assertions_.clear(); TestInfo::startNewTest(); ++testRun_; *************** *** 83,129 **** ++testFailed_; ! printf( "Result tree: %s\n", result_.toString().c_str() ); ! ! CppTL::ConstString resultType = TestInfo::faultCount() ? "fault" : "assertion"; report_ += "-> " + getTestPath() + " : " + resultType + "\n"; ! ! OpenTest::PropertiesAccessor info = result_.accessor(); ! OpenTest::Properties::ValueEnum enumFaults = info["result/faults"].listValues(); ! while ( enumFaults.hasNext() ) ! { ! OpenTest::Value fault = enumFaults.next(); ! reportFailure( fault.asProperties(), false ); ! } ! OpenTest::Properties::ValueEnum enumAssertions = info["result/assertions"].listValues(); ! while ( enumAssertions.hasNext() ) ! { ! OpenTest::Value assertion = enumAssertions.next(); ! reportFailure( assertion.asProperties(), true ); ! } report_ += "\n"; } } - void ! LightTestRunner::mergeInResult( const OpenTest::Properties &result ) { ! result_.mergeReplacingExisting( result ); } void ! LightTestRunner::mergeInResult( const OpenTest::PropertyPath &path, ! const OpenTest::Value &value ) { ! result_[path] = value; } void ! LightTestRunner::appendToResult( const OpenTest::PropertyPath &path, ! const OpenTest::Value &value ) { - result_[path].append( value ); } --- 83,114 ---- ++testFailed_; ! CppTL::ConstString resultType = assertions_.back().kind() == Assertion::fault ? "fault" ! : "assertion"; report_ += "-> " + getTestPath() + " : " + resultType + "\n"; ! Assertions::const_iterator it = assertions_.begin(); ! for ( ; it != assertions_.end(); ++it ) ! reportFailure( *it ); report_ += "\n"; } } void ! LightTestRunner::addResultLog( const OpenTest::Value &log ) { ! // discard log for the time being. Need to incorporate them ! // into a single list with assertions. } void ! LightTestRunner::addResultAssertion( const Assertion &assertion ) { ! assertions_.push_back( assertion ); } void ! LightTestRunner::setTestStatus( const TestStatus &status ) { } *************** *** 140,171 **** void ! LightTestRunner::reportFailure( const OpenTest::Properties &failure, ! bool isAssertion ) ! { ! if ( failure.has( "location") && failure.has("location/file") ) { ! report_ += failure["location/file"].asString() + "(" ! + CppTL::toString( failure["location/line"].asInt() ) ! + ") : "; } else report_ += "unknwon failure location : "; ! CppTL::ConstString failureType = failure.getValue( "failure_type", ! isAssertion ? "assertion" ! : "fault" ).asString(); report_ += "[failure type: " + failureType + "]\n"; ! OpenTest::Properties::ValueEnum enumMessages = failure.accessor()["messages"].listValues(); ! if ( enumMessages.hasNext() ) ! report_ += "Messages:\n"; ! while ( enumMessages.hasNext() ) ! report_ += enumMessages.next().asString() + "\n"; ! ! OpenTest::Properties::ValueEnum enumLogs = failure.accessor()["logs"].listValues(); ! if ( enumLogs.hasNext() ) ! report_ += "Log:\n"; ! while ( enumLogs.hasNext() ) ! report_ += enumLogs.next().asString() + "\n"; ! report_ += "Specifics:\n" + failure.toString() + "\n"; } --- 125,150 ---- void ! LightTestRunner::reportFailure( const Assertion &failure ) ! { // @todo duplicated in Assertion::toString(). ! report_ += "* "; ! if ( failure.location().isValid() ) { ! report_ += failure.location().file_; ! report_ += "(" + CppTL::toString( failure.location().line_ ) + ") : "; } else report_ += "unknwon failure location : "; ! CppTL::ConstString failureType = failure.kind() == Assertion::fault ? "fault" ! : "assertion"; report_ += "[failure type: " + failureType + "]\n"; ! if ( !failure.messages().empty() ) ! report_ += "Messages:\n" + failure.messages().toString(); ! if ( !failure.testDataType().empty() ) ! { ! const OpenTest::Properties &testData = failure.testData(); ! report_ += "Test data type: " + failure.testDataType() + "\n"; ! report_ += testData.toString() + "\n"; ! } } Index: assert.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/assert.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** assert.cpp 6 Mar 2005 18:45:38 -0000 1.10 --- assert.cpp 8 Aug 2005 22:10:21 -0000 1.11 *************** *** 12,17 **** fail( const Message &message ) { ! for ( int index =0; index < message.count(); ++index ) ! TestInfo::currentAssertion()["messages"].append( message.at(index) ); TestInfo::realizeAssertion(); } --- 12,16 ---- fail( const Message &message ) { ! TestInfo::currentAssertion().setMessages( message ); TestInfo::realizeAssertion(); } Index: cpput.vcproj =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/cpput.vcproj,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** cpput.vcproj 6 Aug 2005 22:24:53 -0000 1.37 --- cpput.vcproj 8 Aug 2005 22:10:21 -0000 1.38 *************** *** 491,494 **** --- 491,506 ---- <File RelativePath=".\testrunner.cpp"> + <FileConfiguration + Name="Release|Win32" + ExcludedFromBuild="TRUE"> + <Tool + Name="VCCLCompilerTool"/> + </FileConfiguration> + <FileConfiguration + Name="Debug|Win32" + ExcludedFromBuild="TRUE"> + <Tool + Name="VCCLCompilerTool"/> + </FileConfiguration> </File> <File Index: SConscript =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/SConscript,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** SConscript 6 Aug 2005 22:26:31 -0000 1.8 --- SConscript 8 Aug 2005 22:10:21 -0000 1.9 *************** *** 11,15 **** testcase.cpp testinfo.cpp - testrunner.cpp testsuite.cpp """ ), --- 11,14 ---- Index: testinfo.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/testinfo.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** testinfo.cpp 2 Jul 2005 20:27:36 -0000 1.11 --- testinfo.cpp 8 Aug 2005 22:10:21 -0000 1.12 *************** *** 1,31 **** #include <cpput/testinfo.h> #include <cpptl/thread.h> ! namespace { ! struct CompactLocation { ! CompactLocation( const char *file = 0, ! const char *function = 0, ! unsigned int line =0 ) ! : file_( file ) ! , function_( function ) ! , line_( line ) ! { ! } ! void clear() ! { ! file_ = 0; ! function_ = 0; ! line_ = 0; ! } ! const char *file_; ! const char *function_; ! unsigned int line_; ! }; } ! namespace CppUT { // ////////////////////////////////////////////////////////////////// --- 1,157 ---- #include <cpput/testinfo.h> + #include <cpptl/stringtools.h> #include <cpptl/thread.h> ! namespace CppUT { ! ! // ////////////////////////////////////////////////////////////////// ! // ////////////////////////////////////////////////////////////////// ! // Class Assertion ! // ////////////////////////////////////////////////////////////////// ! // ////////////////////////////////////////////////////////////////// ! ! Assertion::Assertion( Kind kind, ! const SourceLocation &sourceLocation ) ! : kind_( kind ) ! , location_( sourceLocation ) ! { ! } ! ! void ! Assertion::setLocation( const SourceLocation &location ) ! { ! location_ = location; ! } ! ! const SourceLocation & ! Assertion::location() const ! { ! return location_; ! } ! ! void ! Assertion::setKind( Kind kind ) ! { ! kind_ = kind; ! } ! ! Assertion::Kind ! Assertion::kind() const ! { ! return kind_; ! } ! ! void ! Assertion::setMessages( const Message &messages ) ! { ! messages_ = messages; ! } ! ! const Message & ! Assertion::messages() const ! { ! return messages_; ! } ! ! void ! Assertion::setTestDataType( const CppTL::ConstString &type ) ! { ! testDataType_ = type; ! } ! ! const CppTL::ConstString & ! Assertion::testDataType() const ! { ! return testDataType_; ! } ! ! void ! Assertion::setTestData( const CppTL::ConstString &name, ! const OpenTest::Value &value, ! const CppTL::ConstString &type ) ! { ! testData_["name"]["type"] = type; ! testData_["name"]["value"] = value; ! } ! ! const OpenTest::Properties & ! Assertion::testData() const ! { ! return testData_; ! } ! ! CppTL::ConstString ! Assertion::toString() const ! { ! CppTL::StringBuffer buffer; ! buffer += "* "; ! if ( location().isValid() ) { ! buffer += location().file_; ! buffer += "(" + CppTL::toString( location().line_ ) + ") : "; ! } ! else ! buffer += "unknwon failure location : "; ! CppTL::ConstString failureType = kind() == fault ? "fault" ! : "assertion"; ! buffer += "[failure type: " + failureType + "]\n"; ! if ( !messages().empty() ) ! buffer += "Messages:\n" + messages().toString(); ! if ( !testDataType().empty() ) ! { ! buffer += "Test data type: " + testDataType() + "\n"; ! buffer += testData_.toString() + "\n"; ! } ! return buffer; ! } ! // ////////////////////////////////////////////////////////////////// ! // ////////////////////////////////////////////////////////////////// ! // Class TestStatus ! // ////////////////////////////////////////////////////////////////// ! // ////////////////////////////////////////////////////////////////// ! TestStatus::TestStatus( Status status ) ! : status_( status ) ! { } ! void ! TestStatus::setStatus( Status status ) ! { ! status_ = status; ! } ! ! TestStatus::Status ! TestStatus::status() const ! { ! return status_; ! } ! ! bool ! TestStatus::hasFailed() const ! { ! return status_ == failed; ! } ! ! void ! TestStatus::setStatistics( const CppTL::ConstString &name, ! const OpenTest::Value &value ) ! { ! statistics_[name] = value; ! } ! ! ! //OpenTest::Value ! //TestStatus::getStatistics( const CppTL::ConstString &name ) ! //{ ! //} ! ! void ! TestStatus::addSpecific( const CppTL::ConstString &type, ! const OpenTest::Value &value ) ! { ! specifics_[type] = value; ! } // ////////////////////////////////////////////////////////////////// *************** *** 49,71 **** void startNewTest() { ! result_.clear(); ! assertion_.clear(); assertionCount_ = 0; failedAssertionCount_ = 0; assertionType_ = abortingAssertion; - assertionLocation_.clear(); - } - - void updateTestStatistics() - { - TestInfo::mergeInResult( "statistics/assertions", assertionCount_ ); - } - - void newAssertion() - { - assertionType_ = abortingAssertion; - assertionLocation_.clear(); - assertion_.clear(); - ++assertionCount_; } --- 175,183 ---- void startNewTest() { ! testStatus_ = TestStatus( TestStatus::passed ); ! currentAssertion_ = Assertion(); assertionCount_ = 0; failedAssertionCount_ = 0; assertionType_ = abortingAssertion; } *************** *** 74,106 **** ++failedAssertionCount_; ! OpenTest::Properties assertion = assertion_; ! if ( assertionLocation_.file_ ) ! { ! assertion["location"]["file"] = assertionLocation_.file_; ! assertion["location"]["line"] = assertionLocation_.line_; ! } ! if ( assertionLocation_.function_ ) ! assertion["location"]["function"] = assertionLocation_.function_; ! TestInfo::appendToResult( "assertions", assertion ); // @todo Move appendToResult here ! if ( !assertion.has( "failure_type" ) ) ! assertion["failure_type"] = "assertion"; if ( assertionType_ == abortingAssertion ) { std::string message; if ( abortingAssertionMode_ != fastAbortingAssertion ) ! message = result_.toString().c_str(); throw AbortingAssertionException( message ); } } TestResultUpdater *updater_; ! OpenTest::Properties result_; ! OpenTest::Properties assertion_; AssertionType assertionType_; - CompactLocation assertionLocation_; AbortingAssertionMode abortingAssertionMode_; unsigned int assertionCount_; unsigned int failedAssertionCount_; - }; --- 186,215 ---- ++failedAssertionCount_; ! if ( updater_ ) ! updater_->addResultAssertion( currentAssertion_ ); ! if ( assertionType_ == abortingAssertion ) { std::string message; if ( abortingAssertionMode_ != fastAbortingAssertion ) ! message = currentAssertion_.toString().c_str(); throw AbortingAssertionException( message ); } } + TestStatus &getUpdatedTestStatus() + { + if ( !testStatus_.hasFailed() && failedAssertionCount_ > 0 ) + testStatus_.setStatus( TestStatus::failed ); + return testStatus_; + } + TestResultUpdater *updater_; ! TestStatus testStatus_; ! Assertion currentAssertion_; AssertionType assertionType_; AbortingAssertionMode abortingAssertionMode_; unsigned int assertionCount_; unsigned int failedAssertionCount_; }; *************** *** 132,145 **** } - void updateTestStatistics() - { - data().updateTestStatistics(); - } - - OpenTest::PropertiesAccessor result() - { - return data().result_.accessor(); - } - void newAssertion( AssertionType type, const char *fileName, --- 241,244 ---- *************** *** 147,153 **** const char *functionName ) { ! data().newAssertion(); data().assertionType_ = type; - data().assertionLocation_ = CompactLocation( fileName, functionName, lineNumber ); } --- 246,255 ---- const char *functionName ) { ! data().currentAssertion_ = Assertion( Assertion::assertion, ! SourceLocation( fileName, ! lineNumber, ! functionName ) ); ! ++(data().assertionCount_); data().assertionType_ = type; } *************** *** 162,182 **** } - OpenTest::Properties ¤tAssertion() - { - return data().assertion_; - } - - - OpenTest::Properties ¤tAssertionActual() - { - return currentAssertion()["actual"].asProperties(); - } - - - OpenTest::Properties ¤tAssertionExpected() - { - return currentAssertion()["expected"].asProperties(); - } - void realizeAssertion() { --- 264,267 ---- *************** *** 184,245 **** } ! unsigned int assertionCount() ! { ! return data().assertionCount_; ! } ! ! unsigned int failedAssertionCount() ! { ! return result()["assertions"].listSize(); ! } ! ! unsigned int faultCount() ! { ! return result()["faults"].listSize(); ! } ! ! bool testHasFailed() ! { ! const OpenTest::PropertiesAccessor &accessor = result(); ! return accessor["assertions"].hasList() ! || accessor["faults"].hasList(); ! } ! ! void log( const CppTL::ConstString &text ) ! { ! appendToResult( "logs", text ); ! } ! ! void appendFaultToResult( const OpenTest::Properties &fault ) ! { ! OpenTest::Properties actualFault = fault; ! if ( !actualFault.has( "failure_type" ) ) ! actualFault["failure_type"] = "fault"; ! appendToResult( "faults", actualFault ); ! } ! ! ! void mergeInResult( const OpenTest::Properties &result ) ! { ! data().result_.mergeReplacingExisting( result ); ! if ( data().updater_ ) ! data().updater_->mergeInResult( result ); ! } ! ! ! void mergeInResult( const OpenTest::PropertyPath &path, ! const OpenTest::Value &value ) { - data().result_[path] = value; if ( data().updater_ ) ! data().updater_->mergeInResult( path, value ); } ! void appendToResult( const OpenTest::PropertyPath &path, ! const OpenTest::Value &value ) { - data().result_[path].append( value ); if ( data().updater_ ) ! data().updater_->appendToResult( path, value ); } --- 269,283 ---- } ! void log( const OpenTest::Value &log ) { if ( data().updater_ ) ! data().updater_->addResultLog( log ); } ! void handleUnexpectedException( const Assertion &fault ) { if ( data().updater_ ) ! data().updater_->addResultAssertion( fault ); ! data().testStatus_.setStatus( TestStatus::failed ); } *************** *** 262,265 **** --- 300,318 ---- + Assertion & + currentAssertion() + { + return data().currentAssertion_; + } + + TestStatus & + getUpdatedTestStatus() + { + return data().getUpdatedTestStatus(); + } + + + + // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// Index: testcase.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/testcase.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** testcase.cpp 27 Feb 2005 14:38:27 -0000 1.10 --- testcase.cpp 8 Aug 2005 22:10:21 -0000 1.11 *************** *** 54,58 **** } ! return !TestInfo::testHasFailed(); } --- 54,58 ---- } ! return !TestInfo::getUpdatedTestStatus().hasFailed(); } Index: exceptionguard.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/exceptionguard.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** exceptionguard.cpp 28 Feb 2005 22:14:03 -0000 1.5 --- exceptionguard.cpp 8 Aug 2005 22:10:21 -0000 1.6 *************** *** 69,76 **** catch ( ... ) { ! OpenTest::Properties fault; ! fault["type"] = "unexpected exception"; ! fault["message"].append( "caught unexpected exception of unknown type." ); ! TestInfo::appendFaultToResult( fault ); } --- 69,77 ---- catch ( ... ) { ! Assertion fault( Assertion::fault ); ! Message messages( "test threw an unexpected exception" ); ! messages.add( "caught unexpected exception of unknown type (not a subclass of std::exception)." ); ! fault.setMessages( messages ); ! TestInfo::handleUnexpectedException( fault ); } *************** *** 82,91 **** const char *what ) { ! OpenTest::Properties fault; ! fault["type"] = "unexpected exception"; ! fault["exception_type"] = exceptionType; ! fault["message"].append( "caught unexpected exception." ); ! fault["message"].append( what ); ! TestInfo::appendFaultToResult( fault ); } }; --- 83,95 ---- const char *what ) { ! Assertion fault( Assertion::fault ); ! Message messages( "test threw an unexpected exception" ); ! messages.add( "caught unexpected exception of type: " + exceptionType ); ! messages.add( what ); ! fault.setMessages( messages ); ! fault.setTestDataType( "unexpected-exception-fault" ); ! fault.setTestData( "expection-type", exceptionType ); ! fault.setTestData( "expection-message", what ); ! TestInfo::handleUnexpectedException( fault ); } }; |