Skip to content
Snippets Groups Projects
Commit 123eb257 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

use path to select up to single class of test

parent 8de2be73
No related branches found
No related tags found
No related merge requests found
......@@ -21,30 +21,30 @@ CPPUNIT_NS_BEGIN
class CPPUNIT_API TestProgressListener : public TestListener
{
public:
TestProgressListener();
TestProgressListener();
 
virtual ~TestProgressListener();
virtual ~TestProgressListener();
 
void startTest( Test *test );
void startTest( Test *test );
 
void addFailure( const TestFailure &failure );
void addFailure( const TestFailure &failure );
 
void endTest( Test *test );
void endTest( Test *test );
 
int getResult() const;
int getResult() const;
 
void printResults() const;
void printResults() const;
 
private:
TestProgressListener( const TestProgressListener &copy );
TestProgressListener( const TestProgressListener &copy );
 
void operator =( const TestProgressListener &copy );
void operator =( const TestProgressListener &copy );
 
private:
int m_Failures;
int m_Tests;
int m_Assertions;
bool m_lastTestFailed;
int m_Failures;
int m_Tests;
int m_Assertions;
bool m_lastTestFailed;
};
 
TestProgressListener::TestProgressListener() : m_Failures( 0 ), m_Tests(0), m_Assertions(0), m_lastTestFailed( false )
......@@ -79,7 +79,7 @@ void TestProgressListener::endTest( Test * test)
stdCOut().flush();
 
if ( !m_lastTestFailed )
stdCOut() << " : OK";
stdCOut() << " : OK";
else
stdCOut() << " : Fail";
stdCOut() << "\n\n";
......@@ -99,8 +99,8 @@ int main(int argc, char* argv[]) {
try {
TCLAP::CmdLine cmd("Main test binary.", ' ', "0.01");
 
TCLAP::MultiArg<std::string> testPath("p", "path", "test path", false, "string" );
cmd.add( testPath );
TCLAP::MultiArg<std::string> testPathSegments("p", "path", "test path", false, "string" );
cmd.add( testPathSegments );
 
cmd.parse(argc, argv);
 
......@@ -113,13 +113,23 @@ int main(int argc, char* argv[]) {
controller.addListener( &progressListener );
 
CppUnit::Test *suite = NULL;
if(testPath.getValue().size() == 0) {
std::string testPath = "";
if(testPathSegments.getValue().size() == 0) {
// Get the top level suite from the registry
suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
} else if(testPath.getValue().size() == 1) {
suite = CppUnit::TestFactoryRegistry::getRegistry(testPath.getValue()[0]).makeTest();
} else if(testPathSegments.getValue().size() == 1) {
suite = CppUnit::TestFactoryRegistry::getRegistry(testPathSegments.getValue()[0]).makeTest();
} else {
throw TCLAP::ArgException("too many arguments in path switch");
suite = CppUnit::TestFactoryRegistry::getRegistry(testPathSegments.getValue()[0]).makeTest();
bool first = true;
for(const std::string& path : testPathSegments.getValue()) {
if(first) {
first = false;
continue;
}
testPath += path + "/";
}
testPath.pop_back();
}
 
// Adds the test to the list of test to run
......@@ -129,7 +139,7 @@ int main(int argc, char* argv[]) {
// Change the default outputter to a compiler error format outputter
runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), std::cerr ) );
// Run the tests.
runner.run( controller );
runner.run( controller, testPath );
 
progressListener.printResults();
 
......
......@@ -99,8 +99,8 @@ int main(int argc, char* argv[]) {
try {
TCLAP::CmdLine cmd("Main test binary.", ' ', "0.01");
 
TCLAP::MultiArg<std::string> testPath("p", "path", "test path", false, "string" );
cmd.add( testPath );
TCLAP::MultiArg<std::string> testPathSegments("p", "path", "test path", false, "string" );
cmd.add( testPathSegments );
 
cmd.parse(argc, argv);
 
......@@ -113,13 +113,23 @@ int main(int argc, char* argv[]) {
controller.addListener( &progressListener );
 
CppUnit::Test *suite = NULL;
if(testPath.getValue().size() == 0) {
std::string testPath = "";
if(testPathSegments.getValue().size() == 0) {
// Get the top level suite from the registry
suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
} else if(testPath.getValue().size() == 1) {
suite = CppUnit::TestFactoryRegistry::getRegistry(testPath.getValue()[0]).makeTest();
} else if(testPathSegments.getValue().size() == 1) {
suite = CppUnit::TestFactoryRegistry::getRegistry(testPathSegments.getValue()[0]).makeTest();
} else {
throw TCLAP::ArgException("too many arguments in path switch");
suite = CppUnit::TestFactoryRegistry::getRegistry(testPathSegments.getValue()[0]).makeTest();
bool first = true;
for(const std::string& path : testPathSegments.getValue()) {
if(first) {
first = false;
continue;
}
testPath += path + "/";
}
testPath.pop_back();
}
 
// Adds the test to the list of test to run
......@@ -129,7 +139,7 @@ int main(int argc, char* argv[]) {
// Change the default outputter to a compiler error format outputter
runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), std::cerr ) );
// Run the tests.
runner.run( controller );
runner.run( controller, testPath );
 
progressListener.printResults();
 
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment