mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-26 16:19:30 +03:00
adding two functions to allow to run tests by name or suite name
This commit is contained in:
parent
9218ffc456
commit
cfbb58b0ad
2 changed files with 51 additions and 1 deletions
|
|
@ -6,7 +6,7 @@
|
|||
#include "MemoryOutStream.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
|
|
@ -17,6 +17,52 @@ int RunAllTests()
|
|||
return runner.RunTestsIf(Test::GetTestList(), NULL, True(), 0);
|
||||
}
|
||||
|
||||
int RunAllTestsInSuites(std::vector<char const *> suiteNames)
|
||||
{
|
||||
//walk list of all tests, add those with a suiteName that
|
||||
//matches one of the arguments to a new TestList
|
||||
const TestList& allTests(Test::GetTestList());
|
||||
TestList selectedTests;
|
||||
Test* p = allTests.GetHead();
|
||||
while (p)
|
||||
{
|
||||
for (unsigned int i = 0; i < suiteNames.size(); ++i)
|
||||
if (strcmp(p->m_details.suiteName, suiteNames[i]) == 0)
|
||||
selectedTests.Add(p);
|
||||
Test* q = p;
|
||||
p = p->m_nextTest;
|
||||
q->m_nextTest = NULL;
|
||||
}
|
||||
|
||||
//run selected test(s) only
|
||||
TestReporterStdout reporter;
|
||||
TestRunner runner(reporter);
|
||||
return runner.RunTestsIf(selectedTests, NULL, True(), 0);
|
||||
}
|
||||
|
||||
int RunAllNamedTests(std::vector<char const *> testNames)
|
||||
{
|
||||
//walk list of all tests, add those with a name that
|
||||
//matches one of the arguments to a new TestList
|
||||
const TestList& allTests(Test::GetTestList());
|
||||
TestList selectedTests;
|
||||
Test* p = allTests.GetHead();
|
||||
while (p)
|
||||
{
|
||||
for (unsigned int i = 0; i < testNames.size(); ++i)
|
||||
if (strcmp(p->m_details.testName, testNames[i]) == 0)
|
||||
selectedTests.Add(p);
|
||||
Test* q = p;
|
||||
p = p->m_nextTest;
|
||||
q->m_nextTest = NULL;
|
||||
}
|
||||
|
||||
//run selected test(s) only
|
||||
TestReporterStdout reporter;
|
||||
TestRunner runner(reporter);
|
||||
return runner.RunTestsIf(selectedTests, NULL, True(), 0);
|
||||
}
|
||||
|
||||
|
||||
TestRunner::TestRunner(TestReporter& reporter)
|
||||
: m_reporter(&reporter)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include "TestList.h"
|
||||
#include "CurrentTest.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class TestReporter;
|
||||
|
|
@ -12,6 +14,8 @@ class TestResults;
|
|||
class Timer;
|
||||
|
||||
UNITTEST_LINKAGE int RunAllTests();
|
||||
UNITTEST_LINKAGE int RunAllTestsInSuites(std::vector<char const *> suiteName);
|
||||
UNITTEST_LINKAGE int RunAllNamedTests(std::vector<char const *> testNames);
|
||||
|
||||
struct True
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue