arabica/tests/CppUnit/textui/TextTestResult.cpp

158 lines
4.1 KiB
C++
Raw Normal View History

2005-08-04 23:23:48 +02:00
#ifdef _MSC_VER
#pragma warning(disable: 4996)
#endif
2005-08-04 23:23:48 +02:00
#include "TextTestResult.h"
#include "../framework/CppUnitException.h"
#include "../framework/estring.h"
using namespace std;
void TextTestResult::addError (Test *test, CppUnitException *e)
{
TestResult::addError (test, e);
2006-10-12 00:51:04 +02:00
if(verbose_)
cerr << "E" << endl;
2005-08-04 23:23:48 +02:00
}
void TextTestResult::addFailure (Test *test, CppUnitException *e)
{
TestResult::addFailure (test, e);
2006-10-12 00:51:04 +02:00
if(verbose_)
cerr << "F" << endl;
2005-08-04 23:23:48 +02:00
}
2007-07-19 18:57:04 +02:00
void TextTestResult::addSkip (Test *test, CppUnitException *e)
{
TestResult::addSkip (test, e);
cerr << "S" << endl;
}
2005-08-04 23:23:48 +02:00
void TextTestResult::startTest (Test *test)
{
TestResult::startTest (test);
2006-10-12 00:51:04 +02:00
if(verbose_)
cerr << ".";
2005-08-04 23:23:48 +02:00
}
void TextTestResult::printErrors (ostream& stream)
{
if (testErrors () != 0) {
if (testErrors () == 1)
stream << "There was " << testErrors () << " error: " << endl;
else
stream << "There were " << testErrors () << " errors: " << endl;
int i = 1;
for (vector<TestFailure *>::iterator it = errors ().begin (); it != errors ().end (); ++it) {
TestFailure *failure = *it;
CppUnitException *e = failure->thrownException ();
stream << i
<< ") "
<< "line: " << (e ? estring (e->lineNumber ()) : "") << " "
<< (e ? e->fileName () : "") << " "
<< "\"" << failure->thrownException ()->what () << "\""
<< endl;
i++;
}
}
}
void TextTestResult::printFailures (ostream& stream)
{
if (testFailures () != 0) {
if (testFailures () == 1)
stream << "There was " << testFailures () << " failure: " << endl;
else
stream << "There were " << testFailures () << " failures: " << endl;
int i = 1;
for (vector<TestFailure *>::iterator it = failures ().begin (); it != failures ().end (); ++it) {
TestFailure *failure = *it;
CppUnitException *e = failure->thrownException ();
stream << i
<< ") "
<< "line: " << (e ? estring (e->lineNumber ()) : "") << " "
<< (e ? e->fileName () : "") << " "
<< "\"" << failure->thrownException ()->what () << "\""
<< endl;
i++;
}
}
}
2007-07-19 18:57:04 +02:00
void TextTestResult::printSkips (ostream& stream)
{
if (testSkips () != 0) {
if (testSkips () == 1)
stream << "There was " << testSkips () << " skip: " << endl;
else
stream << "There were " << testSkips () << " skips: " << endl;
int i = 1;
for (vector<TestFailure *>::iterator it = skips ().begin (); it != skips ().end (); ++it) {
TestFailure *skip = *it;
CppUnitException *e = skip ->thrownException ();
stream << i
<< ") "
<< "line: " << (e ? estring (e->lineNumber ()) : "") << " "
<< (e ? e->fileName () : "") << " "
<< "\"" << skip->thrownException ()->what () << "\""
<< endl;
i++;
}
}
}
2005-08-04 23:23:48 +02:00
void TextTestResult::print (ostream& stream)
{
printHeader (stream);
printErrors (stream);
printFailures (stream);
2007-07-19 18:57:04 +02:00
printSkips (stream);
2006-10-12 00:51:04 +02:00
if(verbose_ || !wasSuccessful())
cout << endl;
2005-08-04 23:23:48 +02:00
}
void TextTestResult::printHeader (ostream& stream)
{
if (wasSuccessful ())
2006-10-12 00:51:04 +02:00
{
if(verbose_)
2007-07-19 18:57:04 +02:00
{
if(testSkips())
cout << endl << "OK (" << runTests () << " tests, with " << testSkips() << " skips)" << endl;
else
2005-08-04 23:23:48 +02:00
cout << endl << "OK (" << runTests () << " tests)" << endl;
2007-07-19 18:57:04 +02:00
}
2006-10-12 00:51:04 +02:00
}
2005-08-04 23:23:48 +02:00
else
cout << endl
<< "!!!FAILURES!!!" << endl
<< "Test Results:" << endl
<< "Run: "
<< runTests ()
<< " Failures: "
<< testFailures ()
<< " Errors: "
<< testErrors ()
2007-07-19 18:57:04 +02:00
<< " Skips: "
<< testSkips ()
2005-08-04 23:23:48 +02:00
<< endl;
}