mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
fix test result reporting
This commit is contained in:
@@ -50,7 +50,6 @@ public:
|
|||||||
void addTest(const std::string& name, Test* test);
|
void addTest(const std::string& name, Test* test);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool run(Test* test, const std::string& ignore);
|
|
||||||
void printBanner();
|
void printBanner();
|
||||||
void print(const std::string& name, Test* pTest, int indent);
|
void print(const std::string& name, Test* pTest, int indent);
|
||||||
Test* find(const std::string& name, Test* pTest, const std::string& testName);
|
Test* find(const std::string& name, Test* pTest, const std::string& testName);
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ bool TestRunner::run(const std::vector<std::string>& args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "ignore file:" << ignore << std::endl;
|
|
||||||
if (all)
|
if (all)
|
||||||
{
|
{
|
||||||
tests.clear();
|
tests.clear();
|
||||||
@@ -131,6 +130,7 @@ bool TestRunner::run(const std::vector<std::string>& args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextTestResult result(_ostr, ignore);
|
||||||
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
|
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
|
||||||
{
|
{
|
||||||
Test* testToRun = *it;
|
Test* testToRun = *it;
|
||||||
@@ -138,9 +138,12 @@ bool TestRunner::run(const std::vector<std::string>& args)
|
|||||||
continue;
|
continue;
|
||||||
if (setup.size() > 0)
|
if (setup.size() > 0)
|
||||||
testToRun->addSetup(setup);
|
testToRun->addSetup(setup);
|
||||||
if (!run(testToRun, ignore)) success = false;
|
|
||||||
|
testToRun->run(&result);
|
||||||
numberOfTests++;
|
numberOfTests++;
|
||||||
}
|
}
|
||||||
|
_ostr << result << std::endl;
|
||||||
|
success = result.wasSuccessful();
|
||||||
|
|
||||||
if (numberOfTests == 0 && !printed)
|
if (numberOfTests == 0 && !printed)
|
||||||
{
|
{
|
||||||
@@ -158,17 +161,6 @@ bool TestRunner::run(const std::vector<std::string>& args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool TestRunner::run(Test* test, const std::string& ignore)
|
|
||||||
{
|
|
||||||
TextTestResult result(_ostr, ignore);
|
|
||||||
|
|
||||||
test->run(&result);
|
|
||||||
_ostr << result << std::endl;
|
|
||||||
|
|
||||||
return result.wasSuccessful();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TestRunner::addTest(const std::string& name, Test* test)
|
void TestRunner::addTest(const std::string& name, Test* test)
|
||||||
{
|
{
|
||||||
_mappings.push_back(Mapping(name, test));
|
_mappings.push_back(Mapping(name, test));
|
||||||
|
|||||||
@@ -16,21 +16,25 @@
|
|||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace CppUnit {
|
namespace CppUnit {
|
||||||
|
|
||||||
|
|
||||||
TextTestResult::TextTestResult() :
|
TextTestResult::TextTestResult() :
|
||||||
_ostr(std::cout)
|
_ostr(std::cout)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TextTestResult::TextTestResult(const std::string& ignore):
|
TextTestResult::TextTestResult(const std::string& ignore):
|
||||||
_ostr(std::cout)
|
_ostr(std::cout)
|
||||||
{
|
{
|
||||||
if (!ignore.empty())
|
if (!ignore.empty())
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
std::ifstream ifs(ignore);
|
std::ifstream ifs(ignore);
|
||||||
if (ifs.is_open()) {
|
if (ifs.is_open())
|
||||||
|
{
|
||||||
char line[256];
|
char line[256];
|
||||||
while (ifs.getline(line, sizeof(line)))
|
while (ifs.getline(line, sizeof(line)))
|
||||||
{
|
{
|
||||||
@@ -44,7 +48,8 @@ TextTestResult::TextTestResult(const std::string& ignore):
|
|||||||
ifs.close();
|
ifs.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception e) {
|
catch (std::exception e)
|
||||||
|
{
|
||||||
std::cout << e.what() << std::endl;
|
std::cout << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,13 +62,16 @@ TextTestResult::TextTestResult(std::ostream& ostr):
|
|||||||
_ostr(ostr)
|
_ostr(ostr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TextTestResult::TextTestResult(std::ostream& ostr, const std::string& ignore) :
|
TextTestResult::TextTestResult(std::ostream& ostr, const std::string& ignore) :
|
||||||
_ostr(ostr)
|
_ostr(ostr)
|
||||||
{
|
{
|
||||||
if (!ignore.empty())
|
if (!ignore.empty())
|
||||||
{
|
{
|
||||||
std::ifstream ifs(ignore);
|
std::ifstream ifs(ignore);
|
||||||
if (ifs.is_open()) {
|
if (ifs.is_open())
|
||||||
|
{
|
||||||
char line[256];
|
char line[256];
|
||||||
while (ifs.getline(line, sizeof(line)))
|
while (ifs.getline(line, sizeof(line)))
|
||||||
{
|
{
|
||||||
@@ -80,6 +88,7 @@ TextTestResult::TextTestResult(std::ostream& ostr, const std::string& ignore) :
|
|||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TextTestResult::ignoring(const std::string ignore)
|
void TextTestResult::ignoring(const std::string ignore)
|
||||||
{
|
{
|
||||||
std::string::const_iterator it = ignore.begin();
|
std::string::const_iterator it = ignore.begin();
|
||||||
@@ -95,6 +104,8 @@ void TextTestResult::ignoring(const std::string ignore)
|
|||||||
if (!test.empty()) _ignored.insert(test.erase(test.find_last_not_of(" \n\r\t") + 1));
|
if (!test.empty()) _ignored.insert(test.erase(test.find_last_not_of(" \n\r\t") + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TextTestResult::setup()
|
void TextTestResult::setup()
|
||||||
{
|
{
|
||||||
#if !defined(_WIN32_WCE)
|
#if !defined(_WIN32_WCE)
|
||||||
@@ -142,7 +153,7 @@ void TextTestResult::addFailure(Test* test, CppUnitException* e)
|
|||||||
void TextTestResult::startTest(Test* test)
|
void TextTestResult::startTest(Test* test)
|
||||||
{
|
{
|
||||||
TestResult::startTest(test);
|
TestResult::startTest(test);
|
||||||
_ostr << shortName(test->toString()) << ": ";
|
_ostr << "\n" << shortName(test->toString()) << ": ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -150,7 +161,7 @@ void TextTestResult::printErrors(std::ostream& stream)
|
|||||||
{
|
{
|
||||||
if (testErrors() != 0)
|
if (testErrors() != 0)
|
||||||
{
|
{
|
||||||
stream << std::endl;
|
stream << "\n";
|
||||||
|
|
||||||
if (testErrors() == 1)
|
if (testErrors() == 1)
|
||||||
stream << "There was " << testErrors() << " error: " << std::endl;
|
stream << "There was " << testErrors() << " error: " << std::endl;
|
||||||
@@ -165,8 +176,8 @@ void TextTestResult::printErrors(std::ostream& stream)
|
|||||||
|
|
||||||
stream << std::setw(2) << i
|
stream << std::setw(2) << i
|
||||||
<< ": "
|
<< ": "
|
||||||
<< failure->failedTest()->toString() << std::endl
|
<< failure->failedTest()->toString() << "\n"
|
||||||
<< " \"" << (e ? e->what() : "") << "\"" << std::endl
|
<< " \"" << (e ? e->what() : "") << "\"\n"
|
||||||
<< " in \""
|
<< " in \""
|
||||||
<< (e ? e->fileName() : std::string())
|
<< (e ? e->fileName() : std::string())
|
||||||
<< "\", line ";
|
<< "\", line ";
|
||||||
@@ -213,8 +224,8 @@ void TextTestResult::printFailures(std::ostream& stream)
|
|||||||
|
|
||||||
stream << std::setw(2) << i
|
stream << std::setw(2) << i
|
||||||
<< ": "
|
<< ": "
|
||||||
<< failure->failedTest()->toString() << std::endl
|
<< failure->failedTest()->toString() << "\n"
|
||||||
<< " \"" << (e ? e->what() : "") << "\"" << std::endl
|
<< " \"" << (e ? e->what() : "") << "\"\n"
|
||||||
<< " in \""
|
<< " in \""
|
||||||
<< (e ? e->fileName() : std::string())
|
<< (e ? e->fileName() : std::string())
|
||||||
<< "\", line ";
|
<< "\", line ";
|
||||||
@@ -253,11 +264,19 @@ void TextTestResult::print(std::ostream& stream)
|
|||||||
|
|
||||||
void TextTestResult::printHeader(std::ostream& stream)
|
void TextTestResult::printHeader(std::ostream& stream)
|
||||||
{
|
{
|
||||||
if (!wasSuccessful())
|
stream << "\n\n";
|
||||||
stream << "!!!FAILURES!!!" << std::endl
|
if (wasSuccessful())
|
||||||
<< "Runs: " << runTests()
|
stream << "OK ("
|
||||||
<< " Failures: " << testFailures()
|
<< runTests() << " tests)"
|
||||||
<< " Errors: " << testErrors()
|
<< std::endl;
|
||||||
|
else
|
||||||
|
stream << "!!!FAILURES!!!" << "\n"
|
||||||
|
<< "Runs: "
|
||||||
|
<< runTests ()
|
||||||
|
<< " Failures: "
|
||||||
|
<< testFailures ()
|
||||||
|
<< " Errors: "
|
||||||
|
<< testErrors ()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user