mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 04:17:55 +01:00
allow to select long tests to be run from cmdline
This commit is contained in:
@@ -25,11 +25,19 @@ class TestResult;
|
||||
*/
|
||||
class CppUnit_API Test
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
Suite, // Only set on CppUnit::TestSuite
|
||||
Normal, // Default TestCase always run
|
||||
Long // Such TestCase will only be run if the `-long` command line argument is set
|
||||
};
|
||||
|
||||
public:
|
||||
virtual ~Test() = 0;
|
||||
virtual void run(TestResult* result) = 0;
|
||||
virtual int countTestCases() = 0;
|
||||
virtual std::string toString() = 0;
|
||||
virtual int countTestCases() const = 0;
|
||||
virtual std::string toString() const = 0;
|
||||
virtual Test::Type getType() const = 0;
|
||||
|
||||
void addSetup(const std::vector<std::string>& setup);
|
||||
const std::vector<std::string>& setup() const;
|
||||
@@ -51,19 +59,26 @@ inline void Test::run(TestResult *result)
|
||||
|
||||
|
||||
// Counts the number of test cases that will be run by this test.
|
||||
inline int Test::countTestCases()
|
||||
inline int Test::countTestCases() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Returns the name of the test instance.
|
||||
inline std::string Test::toString()
|
||||
inline std::string Test::toString() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
// Returns the type of the test, see Test::Type
|
||||
inline Test::Type Test::getType() const
|
||||
{
|
||||
return Test::Normal;
|
||||
}
|
||||
|
||||
|
||||
inline void Test::addSetup(const std::vector<std::string>& setup)
|
||||
{
|
||||
_setup = setup;
|
||||
|
||||
@@ -54,8 +54,8 @@ class TestCaller: public TestCase
|
||||
typedef void (Fixture::*TestMethod)();
|
||||
|
||||
public:
|
||||
TestCaller(const std::string& name, TestMethod test):
|
||||
TestCase(name),
|
||||
TestCaller(const std::string& name, TestMethod test, Test::Type testType = Test::Type::Normal):
|
||||
TestCase(name, testType),
|
||||
_test(test),
|
||||
_fixture(new Fixture(name))
|
||||
{
|
||||
@@ -95,7 +95,13 @@ private:
|
||||
#define CppUnit_addTest(suite, cls, mth) \
|
||||
suite->addTest(new CppUnit::TestCaller<cls>(#mth, &cls::mth))
|
||||
|
||||
#define CppUnit_addLongTest(suite, cls, mth) \
|
||||
suite->addTest(new CppUnit::TestCaller<cls>(#mth, &cls::mth, CppUnit::Test::Long))
|
||||
|
||||
#define CppUnit_addQualifiedTest(suite, cls, mth) \
|
||||
suite->addTest(new CppUnit::TestCaller<cls>(#cls"::"#mth, &cls::mth))
|
||||
|
||||
#define CppUnit_addLongQualifiedTest(suite, cls, mth) \
|
||||
suite->addTest(new CppUnit::TestCaller<cls>(#cls"::"#mth, &cls::mth, CppUnit::Test::Long))
|
||||
|
||||
#endif // CppUnit_TestCaller_INCLUDED
|
||||
|
||||
@@ -87,14 +87,16 @@ class CppUnit_API TestCase: public Test
|
||||
REFERENCEOBJECT (TestCase)
|
||||
|
||||
public:
|
||||
TestCase(const std::string& Name);
|
||||
TestCase(const std::string& Name, Test::Type testType = Test::Normal);
|
||||
~TestCase();
|
||||
|
||||
virtual void run(TestResult* result);
|
||||
virtual TestResult* run();
|
||||
virtual int countTestCases();
|
||||
virtual int countTestCases() const;
|
||||
virtual std::string toString() const;
|
||||
virtual Test::Type getType() const;
|
||||
void setType(Test::Type testType);
|
||||
const std::string& name() const;
|
||||
std::string toString();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void setUp(const std::vector<std::string>& setup);
|
||||
@@ -169,12 +171,15 @@ protected:
|
||||
|
||||
private:
|
||||
const std::string _name;
|
||||
Test::Type _type;
|
||||
};
|
||||
|
||||
|
||||
// Constructs a test case
|
||||
inline TestCase::TestCase(const std::string& name): _name (name)
|
||||
inline TestCase::TestCase(const std::string& name, Test::Type testType)
|
||||
: _name (name)
|
||||
{
|
||||
setType(testType);
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +190,7 @@ inline TestCase::~TestCase()
|
||||
|
||||
|
||||
// Returns a count of all the tests executed
|
||||
inline int TestCase::countTestCases()
|
||||
inline int TestCase::countTestCases() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -217,12 +222,23 @@ inline void TestCase::tearDown()
|
||||
|
||||
|
||||
// Returns the name of the test case instance
|
||||
inline std::string TestCase::toString()
|
||||
inline std::string TestCase::toString() const
|
||||
{
|
||||
const std::type_info& thisClass = typeid(*this);
|
||||
return std::string(thisClass.name()) + "." + name();
|
||||
}
|
||||
|
||||
// Returns the type of the test, see Test::Type
|
||||
inline Test::Type TestCase::getType() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
// Set the type of the test, see Test::Type
|
||||
inline void TestCase::setType(Test::Type testType)
|
||||
{
|
||||
_type = testType;
|
||||
}
|
||||
|
||||
// A set of macros which allow us to get the line number
|
||||
// and file name at the point of an error.
|
||||
|
||||
@@ -33,7 +33,7 @@ class Test;
|
||||
*
|
||||
* Here is the synopsis:
|
||||
*
|
||||
* TestRunner [-all] [-print] [-wait] ExampleTestCase
|
||||
* TestRunner [-all] [-long] [-print] [-wait] ExampleTestCase
|
||||
*
|
||||
*/
|
||||
class CppUnit_API TestRunner
|
||||
@@ -54,6 +54,7 @@ protected:
|
||||
void printBanner();
|
||||
void print(const std::string& name, Test* pTest, int indent);
|
||||
Test* find(const std::string& name, Test* pTest, const std::string& testName);
|
||||
int collectAllTestCases(Test* pTest, std::vector<Test*>& tests);
|
||||
|
||||
private:
|
||||
std::ostream& _ostr;
|
||||
|
||||
@@ -42,9 +42,10 @@ public:
|
||||
~TestSuite();
|
||||
|
||||
void run(TestResult* result);
|
||||
int countTestCases();
|
||||
int countTestCases() const;
|
||||
void addTest(Test* test);
|
||||
std::string toString();
|
||||
std::string toString() const;
|
||||
Test::Type getType() const;
|
||||
|
||||
virtual void deleteContents();
|
||||
|
||||
@@ -77,11 +78,16 @@ inline void TestSuite::addTest(Test* test)
|
||||
|
||||
|
||||
// Returns a std::string representation of the test suite.
|
||||
inline std::string TestSuite::toString()
|
||||
inline std::string TestSuite::toString() const
|
||||
{
|
||||
return "suite " + _name;
|
||||
}
|
||||
|
||||
// Returns the type of the test, see Test::Type
|
||||
inline Test::Type TestSuite::getType() const
|
||||
{
|
||||
return Test::Suite;
|
||||
}
|
||||
|
||||
// Returns all tests
|
||||
inline const std::vector<Test*> TestSuite::tests() const
|
||||
|
||||
Reference in New Issue
Block a user