summaryrefslogtreecommitdiff
path: root/src/cppunit/TextTestResult.cpp
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2001-10-05 21:27:15 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2001-10-05 21:27:15 +0000
commitfbd454f554f13680fe62b36fb7a5829f6dc0c396 (patch)
tree4ef06f5085f7e68ebc144dd78560afec3e3aadc2 /src/cppunit/TextTestResult.cpp
parent6a1755ef0e36aeb1ac2df0a46e5dafe08a4699ee (diff)
downloadcppunit-fbd454f554f13680fe62b36fb7a5829f6dc0c396.tar.gz
Include/cppunit/Asserter.
include/cppunit/Asserter.h : * src/cppunit/Asserter.cpp : added. Helper to create assertion macros. * src/cppunit/cppunit.dsp : * src/cppunit/Makefile.am : * include/cppunit/Makefile.am : added Asserter.h and Asserter.cpp. * include/cppunit/Exception.h : * src/cppunit/Exception.cpp : added constructor that take a SourceLine argument. Deprecated static constant and old constructor. Fixed some constness issues. * examples/cppunittest/ExceptionTest.cpp : Refactored. * NEWS : partially updated (need to be more detailed) * include/cppunit/NotEqualException.h : * src/cppunit/NotEqualException.cpp : added constructor that take a SourceLine argument. Deprecated old constructor. Added a third element to compose message. * examples/cppunittest/NotEqualExceptionTest.cpp : moved to "Core" suite. Added test for SourceLine() and additionalMessage(). Refactored. * include/cppunit/SourceLine.h : * src/cppunit/SourceLine.cpp : added. Result of applying IntroduceParameterObject refactoring on filename & line number... * include/cppunit/TestAssert.h : * src/cppunit/TestAssert.cpp : deprecated old assert functions. added functions assertEquals() and assertDoubleEquals() which use SourceLine. * src/cppunit/TestCase.cpp : Modified for SourceLine. * include/cppunit/TestFailure.h : * src/cppunit/TestFailure.cpp : added failedTestName(), and sourceLine(). * src/msvc6/testrunner/TestRunnerDlg.cpp : modified to use SourceLine. * include/cppunit/TextTestResult.h : * src/cppunit/TextTestResult.cpp : corrected include order and switched to angled brackets. Refactored. Don't print failure location if not available. Not equal failure dump additional message if available. * src/cppunit/TextTestRunner.cpp : run() now returns a boolean to indicate if the run was sucessful. * src/cppunit/XmlTestResultOutputter.cpp : replaced itoa() with OStringStream. Refactored. * examples/cppunittest/XmlUniformiser.h : * examples/cppunittest/XmlUniformiser.cpp : CPPUNITTEST_ASSERT_XML_EQUAL capture failure location. Refactored checkXmlEqual(). * examples/cppunittest/XmlUniformiserTest.h : * examples/cppunittest/XmlUniformiserTest.cpp : added test for CPPUNITTEST_ASSERT_XML_EQUAL. * include/cppunit/XmlTestResultOutputter.h : * src/cppunit/XmlTestResultOutputter.cpp : updated to use SourceLine.
Diffstat (limited to 'src/cppunit/TextTestResult.cpp')
-rw-r--r--src/cppunit/TextTestResult.cpp60
1 files changed, 45 insertions, 15 deletions
diff --git a/src/cppunit/TextTestResult.cpp b/src/cppunit/TextTestResult.cpp
index bfd6fb9..44a8fa6 100644
--- a/src/cppunit/TextTestResult.cpp
+++ b/src/cppunit/TextTestResult.cpp
@@ -1,8 +1,9 @@
+#include <cppunit/Exception.h>
+#include <cppunit/NotEqualException.h>
+#include <cppunit/Test.h>
+#include <cppunit/TextTestResult.h>
#include <iostream>
-#include "cppunit/TextTestResult.h"
-#include "cppunit/Exception.h"
-#include "cppunit/NotEqualException.h"
-#include "cppunit/Test.h"
+
namespace CppUnit {
@@ -39,7 +40,10 @@ TextTestResult::printFailures( std::ostream &stream )
TestFailures::const_iterator itFailure = failures().begin();
int failureNumber = 1;
while ( itFailure != failures().end() )
+ {
+ stream << std::endl;
printFailure( *itFailure++, failureNumber++, stream );
+ }
}
@@ -54,7 +58,7 @@ TextTestResult::printFailure( TestFailure *failure,
stream << ' ';
printFailureType( failure, stream );
stream << ' ';
- printFailureLocation( failure->thrownException(), stream );
+ printFailureLocation( failure->sourceLine(), stream );
stream << std::endl;
printFailureDetail( failure->thrownException(), stream );
stream << std::endl;
@@ -88,11 +92,14 @@ TextTestResult::printFailureType( TestFailure *failure,
void
-TextTestResult::printFailureLocation( Exception *thrownException,
+TextTestResult::printFailureLocation( SourceLine sourceLine,
std::ostream &stream )
{
- stream << "line: " << thrownException->lineNumber()
- << ' ' << thrownException->fileName();
+ if ( !sourceLine.isValid() )
+ return;
+
+ stream << "line: " << sourceLine.lineNumber()
+ << ' ' << sourceLine.fileName();
}
@@ -105,6 +112,12 @@ TextTestResult::printFailureDetail( Exception *thrownException,
NotEqualException *e = (NotEqualException*)thrownException;
stream << "expected: " << e->expectedValue() << std::endl
<< "but was: " << e->actualValue();
+ if ( !e->additionalMessage().empty() )
+ {
+ stream << std::endl;
+ stream << "additional message:" << std::endl
+ << e->additionalMessage();
+ }
}
else
{
@@ -129,13 +142,30 @@ TextTestResult::printHeader( std::ostream &stream )
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;
+ {
+ stream << std::endl;
+ printFailureWarning( stream );
+ printStatistics( stream );
+ }
+}
+
+
+void
+TextTestResult::printFailureWarning( std::ostream &stream )
+{
+ stream << "!!!FAILURES!!!" << std::endl;
+}
+
+
+void
+TextTestResult::printStatistics( std::ostream &stream )
+{
+ stream << "Test Results:" << std::endl;
+
+ stream << "Run: " << runTests()
+ << " Failures: " << testFailures()
+ << " Errors: " << testErrors()
+ << std::endl;
}