test failures can be ignored for certain tests (specified in CPPUNIT_IGNORE environment variable)

This commit is contained in:
Guenter Obiltschnig 2014-01-16 18:07:03 +01:00
parent 0cf0469596
commit 16885da987
2 changed files with 44 additions and 5 deletions

View File

@ -11,6 +11,7 @@
#include "CppUnit/CppUnit.h"
#include "CppUnit/TestResult.h"
#include <set>
#include <ostream>
@ -33,9 +34,11 @@ public:
protected:
std::string shortName(const std::string& testName);
void setup();
private:
std::ostream& _ostr;
std::set<std::string> _ignored;
};

View File

@ -11,6 +11,7 @@
#include "CppUnit/estring.h"
#include <iostream>
#include <iomanip>
#include <cstdlib>
namespace CppUnit {
@ -19,26 +20,61 @@ namespace CppUnit {
TextTestResult::TextTestResult():
_ostr(std::cout)
{
setup();
}
TextTestResult::TextTestResult(std::ostream& ostr):
_ostr(ostr)
{
setup();
}
void TextTestResult::setup()
{
const char* env = std::getenv("CPPUNIT_IGNORE");
if (env)
{
std::string ignored = env;
std::string::const_iterator it = ignored.begin();
std::string::const_iterator end = ignored.end();
while (it != end)
{
while (it != end && *it == ' ') ++it;
std::string test;
while (it != end && *it != ' ') test += *it++;
if (!test.empty()) _ignored.insert(test);
}
}
}
void TextTestResult::addError(Test* test, CppUnitException* e)
{
TestResult::addError(test, e);
_ostr << "ERROR" << std::flush;
if (_ignored.find(test->toString()) == _ignored.end())
{
TestResult::addError(test, e);
_ostr << "ERROR" << std::flush;
}
else
{
_ostr << "ERROR (ignored)" << std::flush;
}
}
void TextTestResult::addFailure(Test* test, CppUnitException* e)
{
TestResult::addFailure(test, e);
_ostr << "FAILURE" << std::flush;
if (_ignored.find(test->toString()) == _ignored.end())
{
TestResult::addFailure(test, e);
_ostr << "FAILURE" << std::flush;
}
else
{
_ostr << "FAILURE (ignored)" << std::flush;
}
}