Thread: [Cppunit-cvs] cppunit2/include/cpput assert.h,1.15,1.16 exceptionguard.h,1.3,1.4 lighttestrunner.h,1
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-11-11 20:54:24
|
Update of /cvsroot/cppunit/cppunit2/include/cpput In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6524/include/cpput Modified Files: assert.h exceptionguard.h lighttestrunner.h testinfo.h 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: testinfo.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/testinfo.h,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** testinfo.h 9 Nov 2005 20:04:06 -0000 1.17 --- testinfo.h 11 Nov 2005 20:54:15 -0000 1.18 *************** *** 77,80 **** --- 77,83 ---- Kind kind() const; + void setIgnoredFailure(); + bool isIgnoredFailure() const; + void setMessages( const Message &messages ); const Message &messages() const; *************** *** 97,100 **** --- 100,104 ---- SourceLocation location_; Kind kind_; + bool isIgnoredFailure_; }; *************** *** 127,134 **** --- 131,149 ---- void addSpecific( const std::string &type, const Json::Value &value ); + + int assertionCount() const; + int failedAssertionCount() const; + int ignoredFailureCount() const; + + void increaseAssertionCount( int delta = 1 ); + void increaseFailedAssertionCount( int delta = 1 ); + void increaseIgnoredFailureCount( int delta = 1 ); private: Json::Value statistics_; Json::Value specifics_; Status status_; + unsigned int assertionCount_; + unsigned int failedAssertionCount_; + unsigned int ignoredFailureCount_; }; *************** *** 169,176 **** ~ScopedContextOverride(); ! private: TestInfoPtr context_; }; static TestInfo &threadInstance(); --- 184,211 ---- ~ScopedContextOverride(); ! protected: TestInfoPtr context_; }; + class CPPUT_API IgnoreFailureScopedContextOverride : public ScopedContextOverride + , private TestResultUpdater + { + public: + IgnoreFailureScopedContextOverride( bool &assertionFailed ); + + ~IgnoreFailureScopedContextOverride(); + + private: // overridden from TestResultUpdater + virtual void addResultLog( const Json::Value &log ); + + virtual void addResultAssertion( const Assertion &assertion ); + + private: + Assertion *assertion_; + bool &assertionFailed_; + }; + + friend class IgnoreFailureScopedContextOverride; + static TestInfo &threadInstance(); *************** *** 179,186 **** void setTestResultUpdater( TestResultUpdater &updater ); void startNewTest(); ! TestStatus &getUpdatedTestStatus(); void newAssertion( AssertionType type, --- 214,222 ---- void setTestResultUpdater( TestResultUpdater &updater ); + void removeTestResultUpdater(); void startNewTest(); ! TestStatus &testStatus(); void newAssertion( AssertionType type, *************** *** 197,202 **** void setAbortingAssertionMode( AbortingAssertionMode mode ); - void ignoredFailure(); - void log( const Json::Value &log ); --- 233,236 ---- *************** *** 207,221 **** AssertionType assertionType_; AbortingAssertionMode abortingAssertionMode_; - unsigned int assertionCount_; - unsigned int failedAssertionCount_; - unsigned int ignoredAssertionCount_; }; - //void CPPUT_API newAssertion( AssertionType type, - // const char *fileName, - // unsigned int lineNumber, - // const char *functionName = 0 ); - Assertion &CPPUT_API currentAssertion(); --- 241,247 ---- *************** *** 230,233 **** --- 256,261 ---- void CPPUT_API log( const std::string &log ); + void CPPUT_API log( const char *log ); + // This overload allows usage of StringConcatenator... void CPPUT_API log( const CppTL::ConstString &log ); Index: assert.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/assert.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** assert.h 9 Nov 2005 20:04:06 -0000 1.15 --- assert.h 11 Nov 2005 20:54:15 -0000 1.16 *************** *** 253,259 **** } catch ( const ::CppUT::AbortingAssertionException & ) { \ } \ ! assertionFailedCppUT_ = ::CppUT::TestInfo::threadInstance().getUpdatedTestStatus().hasFailed(); \ } \ ! ::CppUT::checkAssertionFail( assertionFailedCppUT_, message ); \ } --- 253,259 ---- } catch ( const ::CppUT::AbortingAssertionException & ) { \ } \ ! assertionFailedCppUT_ = ::CppUT::TestInfo::threadInstance().testStatus().hasFailed(); \ } \ ! ::CppUT::checkAssertionFail( assertionFailedCppUT_, message ); \ } *************** *** 280,284 **** } catch ( const ::CppUT::AbortingAssertionException & ) { \ } \ ! assertionFailedCppUT_ = ::CppUT::TestInfo::threadInstance().getUpdatedTestStatus().hasFailed(); \ } \ ::CppUT::checkAssertionPass( assertionFailedCppUT_, message ); \ --- 280,284 ---- } catch ( const ::CppUT::AbortingAssertionException & ) { \ } \ ! assertionFailedCppUT_ = ::CppUT::TestInfo::threadInstance().testStatus().hasFailed(); \ } \ ::CppUT::checkAssertionPass( assertionFailedCppUT_, message ); \ *************** *** 300,316 **** ::CppUT::skipCurrentTest ! # define CPPUT_IGNORE_FAILURE( assertion ) \ { \ ! bool succeedCppUT_ = false; \ { \ ! ::CppUT::TestInfo::ScopedContextOverride contextSwitchCppUT_; \ try { \ assertion; \ } catch ( const ::CppUT::AbortingAssertionException & ) { \ } \ - succeedCppUT_ = ::CppUT::TestInfo::threadInstance().getUpdatedTestStatus().hasPassed(); \ } \ ! ::CppUT::checkAssertionFail( !succeedCppUT_, #assertion ); \ ! ::CppUT::TestInfo::threadInstance().ignoredFailure(); \ } --- 300,332 ---- ::CppUT::skipCurrentTest ! /*! Checks that an assertion fail, but ignore its failure ! * ! * A typical usage of CPPUT_IGNORE_FAILURE is to ignore a failing assertion temporary. ! * Even if the assertion fails, it does not cause the test to fail, but increased ! * CppUT::TestStatus::ignoredFailureCount() instead. ! * ! * Notes that CPPUT_IGNORE_FAILURE also checks that the \c assertion fails (just like ! * CPPUT_CHECK_ASSERTION_FAIL) and will therefore cause the test to fail if the ! * assertion did not fail. ! * ! * \code ! * CPPUT_IGNORE_FAILURE(( CPPUT_ASSERT_EQUAL( 1, 2 )); ! * \endcode ! * ! * \warning Be sure to always use double brace around the macro parameter to avoid ! * preprocessor mess. ! */ ! # define CPPUT_IGNORE_FAILURE( assertion ) \ { \ ! CPPUT_CHECK_POINT( checkingAssertion ); \ ! bool failedCppUT_; \ { \ ! ::CppUT::TestInfo::IgnoreFailureScopedContextOverride contextSwitchCppUT_( failedCppUT_ );\ try { \ assertion; \ } catch ( const ::CppUT::AbortingAssertionException & ) { \ } \ } \ ! ::CppUT::checkAssertionFail( failedCppUT_, #assertion ); \ } Index: exceptionguard.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/exceptionguard.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** exceptionguard.h 8 Nov 2005 21:50:33 -0000 1.3 --- exceptionguard.h 11 Nov 2005 20:54:15 -0000 1.4 *************** *** 41,44 **** --- 41,46 ---- /** Helpers to provide simple exception translation. + * \warning Ensure that either a fault, assertion is added to TestInfo, or + * that TestStatus is set to \c failed otherwise the test will not fail! */ template<class ExceptionType *************** *** 82,85 **** --- 84,88 ---- void removeLast(); + /// Returns \c true if the test did not fail (skipped or passed TestStatus). bool protect( CppTL::Functor0 test ) const; *************** *** 92,96 **** /** Register an exception translator. ! * @todo provides some helper to generate faul result... * \code * static void translateMFCException( CException *e ) { --- 95,99 ---- /** Register an exception translator. ! * @todo provides some helper to generate fault result... * \code * static void translateMFCException( CException *e ) { *************** *** 106,109 **** --- 109,114 ---- * } * \endcode + * \warning Ensure that either a fault, assertion is added to TestInfo, or + * that TestStatus is set to \c failed otherwise the test will not fail! */ template<class Translator Index: lighttestrunner.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/lighttestrunner.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** lighttestrunner.h 8 Nov 2005 20:25:49 -0000 1.5 --- lighttestrunner.h 11 Nov 2005 20:54:15 -0000 1.6 *************** *** 55,58 **** --- 55,60 ---- unsigned int testRun_; unsigned int testFailed_; + unsigned int testSkipped_; + unsigned int ignoredFailureCount_; }; |