Add -setup, a command line argument.

This commit is contained in:
Francis ANDRE 2018-05-19 15:04:59 +02:00
parent 8951b90bbe
commit 904b0061eb
4 changed files with 32 additions and 1 deletions

View File

@ -9,6 +9,7 @@
#include "CppUnit/CppUnit.h"
#include <string>
#include <vector>
namespace CppUnit {
@ -29,6 +30,11 @@ public:
virtual void run(TestResult* result) = 0;
virtual int countTestCases() = 0;
virtual std::string toString() = 0;
void addSetup(const std::vector<std::string>& setup);
protected:
std::vector<std::string> _setup;
};
@ -57,6 +63,11 @@ inline std::string Test::toString()
}
inline void Test::addSetup(const std::vector<std::string>& setup)
{
_setup = setup;
}
} // namespace CppUnit

View File

@ -96,6 +96,7 @@ public:
std::string toString();
virtual void setUp();
virtual void setUp(const std::vector<std::string>& setup);
virtual void tearDown();
protected:
@ -202,6 +203,12 @@ inline void TestCase::setUp()
}
// A hook for fixture set up with command line arguments
inline void TestCase::setUp(const std::vector<std::string>& setup)
{
}
// A hook for fixture tear down
inline void TestCase::tearDown()
{

View File

@ -110,7 +110,10 @@ void TestCase::run(TestResult *result)
{
result->startTest(this);
setUp();
if (_setup.size() > 0)
setUp(_setup);
else
setUp();
try
{
runTest();

View File

@ -48,6 +48,7 @@ bool TestRunner::run(const std::vector<std::string>& args)
bool all = false;
bool wait = false;
bool printed = false;
std::vector<std::string> setup;
for (int i = 1; i < args.size(); i++)
{
@ -71,6 +72,13 @@ bool TestRunner::run(const std::vector<std::string>& args)
printed = true;
continue;
}
else if (arg == "-setup")
{
if (i + 1 < args.size())
setup.push_back(args[++i]);
continue;
}
if (!all)
{
@ -89,6 +97,8 @@ bool TestRunner::run(const std::vector<std::string>& args)
}
if (testToRun)
{
if (setup.size() > 0)
testToRun->addSetup(setup);
if (!run(testToRun)) success = false;
}
numberOfTests++;