mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-24 09:12:28 +02:00
Add -ignore <file> option to get rid of DOS script issues.
Rollback to previous rendering.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "CppUnit/TextTestResult.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
@@ -35,7 +36,7 @@ TestRunner::~TestRunner()
|
||||
void TestRunner::printBanner()
|
||||
{
|
||||
_ostr
|
||||
<< "Usage: driver [-all] [-long] [-print] [-wait] [name] ..." << std::endl
|
||||
<< "Usage: driver [-all] [-ignore <file> ] [-long] [-print] [-wait] [name] ..." << std::endl
|
||||
<< " where name is the name of a test case class" << std::endl;
|
||||
}
|
||||
|
||||
@@ -49,7 +50,8 @@ bool TestRunner::run(const std::vector<std::string>& args)
|
||||
bool wait = false;
|
||||
bool printed = false;
|
||||
bool long_running = false;
|
||||
|
||||
std::string ignore;
|
||||
|
||||
std::vector<std::string> setup;
|
||||
|
||||
std::vector<Test*> tests;
|
||||
@@ -71,6 +73,11 @@ bool TestRunner::run(const std::vector<std::string>& args)
|
||||
long_running = true;
|
||||
continue;
|
||||
}
|
||||
else if (arg == "-ignore")
|
||||
{
|
||||
ignore = args[++i];
|
||||
continue;
|
||||
}
|
||||
else if (arg == "-print")
|
||||
{
|
||||
for (Mappings::iterator it = _mappings.begin(); it != _mappings.end(); ++it)
|
||||
@@ -114,7 +121,7 @@ bool TestRunner::run(const std::vector<std::string>& args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "ignore file:" << ignore << std::endl;
|
||||
if (all)
|
||||
{
|
||||
tests.clear();
|
||||
@@ -131,7 +138,7 @@ bool TestRunner::run(const std::vector<std::string>& args)
|
||||
continue;
|
||||
if (setup.size() > 0)
|
||||
testToRun->addSetup(setup);
|
||||
if (!run(testToRun)) success = false;
|
||||
if (!run(testToRun, ignore)) success = false;
|
||||
numberOfTests++;
|
||||
}
|
||||
|
||||
@@ -151,9 +158,9 @@ bool TestRunner::run(const std::vector<std::string>& args)
|
||||
}
|
||||
|
||||
|
||||
bool TestRunner::run(Test* test)
|
||||
bool TestRunner::run(Test* test, const std::string& ignore)
|
||||
{
|
||||
TextTestResult result(_ostr);
|
||||
TextTestResult result(_ostr, ignore);
|
||||
|
||||
test->run(&result);
|
||||
_ostr << result << std::endl;
|
||||
|
||||
@@ -8,17 +8,47 @@
|
||||
#include "CppUnit/Test.h"
|
||||
#include "CppUnit/estring.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <cstdlib>
|
||||
#include <cctype>
|
||||
#include <exception>
|
||||
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
TextTestResult::TextTestResult():
|
||||
TextTestResult::TextTestResult() :
|
||||
_ostr(std::cout)
|
||||
{
|
||||
}
|
||||
TextTestResult::TextTestResult(const std::string& ignore):
|
||||
_ostr(std::cout)
|
||||
{
|
||||
if (!ignore.empty())
|
||||
{
|
||||
try {
|
||||
std::ifstream ifs(ignore);
|
||||
if (ifs.is_open()) {
|
||||
char line[256];
|
||||
while (ifs.getline(line, sizeof(line)))
|
||||
{
|
||||
if (line[0] == '#')
|
||||
continue;
|
||||
std::string ignored(line);
|
||||
std::string::const_iterator it = ignored.begin();
|
||||
std::string::const_iterator end = ignored.end();
|
||||
ignoring(ignored);
|
||||
}
|
||||
ifs.close();
|
||||
}
|
||||
}
|
||||
catch (std::exception e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
setup();
|
||||
}
|
||||
|
||||
@@ -26,10 +56,45 @@ TextTestResult::TextTestResult():
|
||||
TextTestResult::TextTestResult(std::ostream& ostr):
|
||||
_ostr(ostr)
|
||||
{
|
||||
}
|
||||
TextTestResult::TextTestResult(std::ostream& ostr, const std::string& ignore) :
|
||||
_ostr(ostr)
|
||||
{
|
||||
if (!ignore.empty())
|
||||
{
|
||||
std::ifstream ifs(ignore);
|
||||
if (ifs.is_open()) {
|
||||
char line[256];
|
||||
while (ifs.getline(line, sizeof(line)))
|
||||
{
|
||||
if (line[0] == '#')
|
||||
continue;
|
||||
std::string ignored(line);
|
||||
std::string::const_iterator it = ignored.begin();
|
||||
std::string::const_iterator end = ignored.end();
|
||||
ignoring(ignored);
|
||||
}
|
||||
ifs.close();
|
||||
}
|
||||
}
|
||||
setup();
|
||||
}
|
||||
|
||||
void TextTestResult::ignoring(const std::string ignore)
|
||||
{
|
||||
std::string::const_iterator it = ignore.begin();
|
||||
std::string::const_iterator end = ignore.end();
|
||||
for (;;)
|
||||
{
|
||||
while (it != end && (std::isspace(*it) || *it == '"' || *it == ',' || *it == '\'')) ++it;
|
||||
if (it == end)
|
||||
break;
|
||||
|
||||
std::string test;
|
||||
while (it != end && *it != ',' && *it != '"' && *it != '\'') test += *it++;
|
||||
if (!test.empty()) _ignored.insert(test.erase(test.find_last_not_of(" \n\r\t") + 1));
|
||||
}
|
||||
}
|
||||
void TextTestResult::setup()
|
||||
{
|
||||
#if !defined(_WIN32_WCE)
|
||||
@@ -39,17 +104,9 @@ void TextTestResult::setup()
|
||||
std::string ignored = env;
|
||||
std::string::const_iterator it = ignored.begin();
|
||||
std::string::const_iterator end = ignored.end();
|
||||
for (;;)
|
||||
{
|
||||
while (it != end && (std::isspace(*it) || *it == '"' || *it == ',' || *it == '\'')) ++it;
|
||||
if (it == end)
|
||||
break;
|
||||
|
||||
std::string test;
|
||||
while (it != end && *it != ',' && *it != '"' && *it != '\'') test += *it++;
|
||||
if (!test.empty()) _ignored.insert(test);
|
||||
}
|
||||
ignoring(ignored);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -196,18 +253,11 @@ void TextTestResult::print(std::ostream& stream)
|
||||
|
||||
void TextTestResult::printHeader(std::ostream& stream)
|
||||
{
|
||||
if (wasSuccessful())
|
||||
stream << "OK ("
|
||||
<< runTests() << " tests)"
|
||||
<< std::endl;
|
||||
else
|
||||
if (!wasSuccessful())
|
||||
stream << "!!!FAILURES!!!" << std::endl
|
||||
<< "Runs: "
|
||||
<< runTests ()
|
||||
<< " Failures: "
|
||||
<< testFailures ()
|
||||
<< " Errors: "
|
||||
<< testErrors ()
|
||||
<< "Runs: " << runTests()
|
||||
<< " Failures: " << testFailures()
|
||||
<< " Errors: " << testErrors()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user