diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-10-03 20:16:12 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-10-03 20:16:12 +0000 |
| commit | c2ac2ac3bcfb30cb8ae4e95e531f1b630b8dd80e (patch) | |
| tree | 090517dbef21bb46ad096008a54cfdedd4066d3a /src/cppunit/TextTestResult.cpp | |
| parent | ddfca2261132a879f631cbaaf22e82feaa2460ef (diff) | |
| download | cppunit-c2ac2ac3bcfb30cb8ae4e95e531f1b630b8dd80e.tar.gz | |
Include/cppunit/TestFailure.
include/cppunit/TestFailure.cpp :
* include/cppunit/TestFailure.h : fixed some constness issues. Added
argument to indicate the type of failure to constructor. Added
isError().
* include/cppunit/TestListener.h : removed addError(). addFailure()
now take a TestFailure as argument.
* include/cppunit/TestResult.h :
* include/cppunit/TestResult.cpp : removed errors(). Refactored. Fixed
some constness issues. Added typedef TestFailures for vector returned
by failures(). failures() returns a const reference on the list of
failure. added testFailuresTotal(). Constructor can take an optional
synchronization object.
* include/cppunit/TextTestResult.h :
* include/cppunit/TextTestResult.cpp : removed printErrors().
Refactored. Updated to suit new TestResult, errors and failures are
reported in the same list.
* examples/cppunittest/TestFailureTest.cpp :
* examples/cppunittest/TestFailureTest.h : modified to use the new
TestFailure constructor. Added one test.
* examples/cppunittest/TestListenerTest.cpp: removed addError().
Refactored to suit new TestListener.
* examples/cppunittest/TestResultTest.h :
* examples/cppunittest/TestResultTest.cpp : modified to suit the
new TestResult.
Diffstat (limited to 'src/cppunit/TextTestResult.cpp')
| -rw-r--r-- | src/cppunit/TextTestResult.cpp | 196 |
1 files changed, 104 insertions, 92 deletions
diff --git a/src/cppunit/TextTestResult.cpp b/src/cppunit/TextTestResult.cpp index d04ce92..bfd6fb9 100644 --- a/src/cppunit/TextTestResult.cpp +++ b/src/cppunit/TextTestResult.cpp @@ -6,28 +6,27 @@ namespace CppUnit { -std::ostream& -operator<< (std::ostream& stream, TextTestResult& result) -{ - result.print (stream); return stream; -} void -TextTestResult::addError (Test *test, Exception *e) +TextTestResult::addError( Test *test, + Exception *e ) { - TestResult::addError (test, e); - std::cerr << "E"; + TestResult::addError( test, e ); + std::cerr << "E"; } + void -TextTestResult::addFailure (Test *test, Exception *e) +TextTestResult::addFailure( Test *test, + Exception *e ) { - TestResult::addFailure (test, e); - std::cerr << "F"; + TestResult::addFailure (test, e); + std::cerr << "F"; } + void -TextTestResult::startTest (Test *test) +TextTestResult::startTest( Test *test ) { TestResult::startTest (test); std::cerr << "."; @@ -35,104 +34,117 @@ TextTestResult::startTest (Test *test) void -TextTestResult::printErrors (std::ostream& stream) +TextTestResult::printFailures( std::ostream &stream ) +{ + TestFailures::const_iterator itFailure = failures().begin(); + int failureNumber = 1; + while ( itFailure != failures().end() ) + printFailure( *itFailure++, failureNumber++, stream ); +} + + +void +TextTestResult::printFailure( TestFailure *failure, + int failureNumber, + std::ostream &stream ) +{ + printFailureListMark( failureNumber, stream ); + stream << ' '; + printFailureTestName( failure, stream ); + stream << ' '; + printFailureType( failure, stream ); + stream << ' '; + printFailureLocation( failure->thrownException(), stream ); + stream << std::endl; + printFailureDetail( failure->thrownException(), stream ); + stream << std::endl; +} + + +void +TextTestResult::printFailureListMark( int failureNumber, + std::ostream &stream ) +{ + stream << failureNumber << ")"; +} + + +void +TextTestResult::printFailureTestName( TestFailure *failure, + std::ostream &stream ) { - if ( testErrors() == 0 ) - return; - - if (testErrors () == 1) - stream << "There was 1 error: " << std::endl; - else - stream << "There were " << testErrors () << " errors: " << std::endl; - - int i = 1; - - for (std::vector<TestFailure *>::iterator it = errors ().begin (); it != errors ().end (); ++it) { - TestFailure* failure = *it; - Exception* e = failure->thrownException (); - - stream << i - << ")" - << " test: " << failure->failedTest()->getName(); - if ( e ) - stream << " line: " << e->lineNumber() - << ' ' << e->fileName(); - stream << " \"" << failure->thrownException()->what() << "\"" - << std::endl; - i++; - } + stream << "test: " << failure->failedTest()->getName(); } void -TextTestResult::printFailures (std::ostream& stream) +TextTestResult::printFailureType( TestFailure *failure, + std::ostream &stream ) { - if ( testFailures() == 0 ) - return; - - if (testFailures () == 1) - stream << "There was 1 failure: " << std::endl; - else - stream << "There were " << testFailures () << " failures: " << std::endl; - - int i = 1; - - for (std::vector<TestFailure *>::iterator it = failures ().begin (); it != failures ().end (); ++it) { - TestFailure* failure = *it; - Exception* e = failure->thrownException(); - - stream << i - << ")" - << " test: " << failure->failedTest()->getName(); - if ( e ) - stream << " line: " << e->lineNumber() - << ' ' << e->fileName(); - - if ( failure->thrownException()->isInstanceOf( NotEqualException::type() ) ) - { - NotEqualException *e = (NotEqualException*)failure->thrownException(); - stream << std::endl - << "expected: " << e->expectedValue() << std::endl - << "but was: " << e->actualValue(); - } - else - { - stream << " \"" << failure->thrownException ()->what () << "\""; - } - - stream << std::endl; - i++; - } + stream << "(" + << (failure->isError() ? "E" : "F") + << ")"; } void -TextTestResult::print (std::ostream& stream) +TextTestResult::printFailureLocation( Exception *thrownException, + std::ostream &stream ) { - printHeader (stream); - printErrors (stream); - printFailures (stream); + stream << "line: " << thrownException->lineNumber() + << ' ' << thrownException->fileName(); +} + +void +TextTestResult::printFailureDetail( Exception *thrownException, + std::ostream &stream ) +{ + if ( thrownException->isInstanceOf( NotEqualException::type() ) ) + { + NotEqualException *e = (NotEqualException*)thrownException; + stream << "expected: " << e->expectedValue() << std::endl + << "but was: " << e->actualValue(); + } + else + { + stream << " \"" << thrownException->what() << "\""; + } } void -TextTestResult::printHeader (std::ostream& stream) +TextTestResult::print( std::ostream& stream ) { - if (wasSuccessful ()) - stream << std::endl << "OK (" << runTests () << " tests)" << std::endl; - else - stream << std::endl - << "!!!FAILURES!!!" << std::endl - << "Test Results:" << std::endl - << "Run: " - << runTests () - << " Failures: " - << testFailures () - << " Errors: " - << testErrors () - << std::endl; + printHeader( stream ); + stream << std::endl; + printFailures( stream ); +} + +void +TextTestResult::printHeader( std::ostream &stream ) +{ + if (wasSuccessful ()) + stream << std::endl << "OK (" << runTests () << " tests)" + << std::endl; + else + stream << std::endl + << "!!!FAILURES!!!" << std::endl + << "Test Results:" << std::endl + << "Run: " << runTests() + << " Failures: " << testFailures() + << " Errors: " << testErrors() + << std::endl; +} + + +std::ostream & +operator <<( std::ostream &stream, + TextTestResult &result ) +{ + result.print (stream); return stream; } + } // namespace CppUnit |
