mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-26 16:19:30 +03:00
extracted in a dedicated class
This commit is contained in:
parent
53c478d501
commit
a6e914c701
3 changed files with 83 additions and 44 deletions
56
UnitTest++/SuitePredicateCmdBuilder.cpp
Normal file
56
UnitTest++/SuitePredicateCmdBuilder.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#include "SuitePredicateCmdBuilder.h"
|
||||
|
||||
using namespace UnitTest;
|
||||
|
||||
|
||||
SuitePredicateCmdBuilder::SuitePredicateCmdBuilder(int argc, char**argv)
|
||||
: _arguments(argc, argv)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SuitePredicate SuitePredicateCmdBuilder::buildPredicate()
|
||||
{
|
||||
SuitePredicate predicate;
|
||||
|
||||
bool specific = false;
|
||||
specific |= readSuiteArgument(_arguments, predicate, "--suite");
|
||||
specific |= readTestArgument(_arguments, predicate, "--test");
|
||||
specific |= readTestArgument(_arguments, predicate, "");
|
||||
|
||||
if (!specific)
|
||||
{
|
||||
predicate.addAll();
|
||||
}
|
||||
return predicate;
|
||||
}
|
||||
|
||||
|
||||
bool SuitePredicateCmdBuilder::readSuiteArgument(ArgumentsReader & arguments, SuitePredicate & predicate, const string & arg)
|
||||
{
|
||||
int from, count;
|
||||
if (!arguments.findArgumentListIndex(arg, from, count))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = from; i < from + count; i++)
|
||||
{
|
||||
predicate.addSuite(arguments.getArgument(i).c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SuitePredicateCmdBuilder::readTestArgument(ArgumentsReader & arguments, SuitePredicate & predicate, const string & arg)
|
||||
{
|
||||
int from, count;
|
||||
if (!arguments.findArgumentListIndex(arg, from, count))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = from; i < from + count; i++)
|
||||
{
|
||||
predicate.addTest(arguments.getArgument(i).c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
24
UnitTest++/SuitePredicateCmdBuilder.h
Normal file
24
UnitTest++/SuitePredicateCmdBuilder.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef UNITTEST_TESTRUNNERCMD_H
|
||||
#define UNITTEST_TESTRUNNERCMD_H
|
||||
|
||||
#include "ArgumentsReader.h"
|
||||
#include "SuitePredicate.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class SuitePredicateCmdBuilder
|
||||
{
|
||||
public:
|
||||
SuitePredicateCmdBuilder(int argc, char**argv);
|
||||
SuitePredicate buildPredicate();
|
||||
|
||||
protected:
|
||||
bool readSuiteArgument(ArgumentsReader & arguments, SuitePredicate & predicate, const string & arg);
|
||||
bool readTestArgument(ArgumentsReader & arguments, SuitePredicate & predicate, const string & arg);
|
||||
|
||||
private:
|
||||
ArgumentsReader _arguments;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
#include "TimeHelpers.h"
|
||||
#include "MemoryOutStream.h"
|
||||
#include "SuitePredicate.h"
|
||||
#include "ArgumentsReader.h"
|
||||
#include "SuitePredicateCmdBuilder.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
|
|
@ -20,54 +20,13 @@ namespace UnitTest {
|
|||
}
|
||||
|
||||
|
||||
bool readSuiteArgument(ArgumentsReader & arguments, SuitePredicate & predicate, char const* argument)
|
||||
{
|
||||
int from, count;
|
||||
if (!arguments.findArgumentListIndex(argument, from, count))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = from; i < from + count; i++)
|
||||
{
|
||||
predicate.addSuite(arguments.getArgument(i).c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool readTestArgument(ArgumentsReader & arguments, SuitePredicate & predicate, char const* argument)
|
||||
{
|
||||
int from, count;
|
||||
if (!arguments.findArgumentListIndex(argument, from, count))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = from; i < from + count; i++)
|
||||
{
|
||||
predicate.addTest(arguments.getArgument(i).c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int RunTestsCmd(int argc, char**argv)
|
||||
{
|
||||
ArgumentsReader arguments(argc, argv);
|
||||
SuitePredicate predicate;
|
||||
|
||||
bool specific = false;
|
||||
specific |= readSuiteArgument(arguments, predicate, "--suite");
|
||||
specific |= readTestArgument(arguments, predicate, "--test");
|
||||
specific |= readTestArgument(arguments, predicate, "");
|
||||
|
||||
if (!specific)
|
||||
{
|
||||
predicate.addAll();
|
||||
}
|
||||
|
||||
//run selected test(s) only
|
||||
SuitePredicateCmdBuilder suiteCmd(argc, argv);
|
||||
TestReporterStdout reporter;
|
||||
TestRunner runner(reporter);
|
||||
|
||||
return runner.RunTestsIf(Test::GetTestList(), 0, predicate, 0);
|
||||
return runner.RunTestsIf(Test::GetTestList(), 0, suiteCmd.buildPredicate(), 0);
|
||||
}
|
||||
|
||||
TestRunner::TestRunner(TestReporter& reporter)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue