summaryrefslogtreecommitdiff
path: root/src/cppunit/TextTestResult.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cppunit/TextTestResult.cpp')
-rw-r--r--src/cppunit/TextTestResult.cpp196
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