Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions test/fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ void TestFixture::printHelp()
" -q Do not print the test cases that have run.\n"
" -h, --help Print this help.\n"
" -n Print no summaries.\n"
" -d Do not execute the tests.\n";
" -d Do not execute any tests (dry run).\n"
" -x Exclude the specified tests.\n";
}

void TestFixture::run(const std::string &str)
Expand Down Expand Up @@ -390,17 +391,23 @@ std::size_t TestFixture::runTests(const options& args)
// TODO: bail out when given class/test is not found?
for (std::string classname : args.which_test()) {
std::string testname;
if (classname.find("::") != std::string::npos) {
testname = classname.substr(classname.find("::") + 2);
classname.erase(classname.find("::"));
const std::string::size_type pos = classname.find("::");
if (pos != std::string::npos) {
// TODO: excluding indiviual tests is not supported yet
testname = classname.substr(pos + 2);
classname.erase(pos);
}

for (TestInstance * test : TestRegistry::theInstance().tests()) {
if (classname.empty() || test->classname == classname) {
TestFixture* fixture = test->create();
fixture->processOptions(args);
fixture->run(testname);
if (!classname.empty()) {
const bool match = test->classname == classname;
if ((match && args.exclude_tests()) || (!match && !args.exclude_tests()))
continue;
}

TestFixture* fixture = test->create();
fixture->processOptions(args);
fixture->run(testname);
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ options::options(int argc, const char* const argv[])
,mHelp(mWhichTests.count("-h") != 0 || mWhichTests.count("--help"))
,mSummary(mWhichTests.count("-n") == 0)
,mDryRun(mWhichTests.count("-d") != 0)
,mExcludeTests(mWhichTests.count("-x") != 0)
,mExe(argv[0])
{
for (auto it = mWhichTests.cbegin(); it != mWhichTests.cend();) {
Expand Down Expand Up @@ -65,3 +66,8 @@ const std::string& options::exe() const
{
return mExe;
}

bool options::exclude_tests() const
{
return mExcludeTests;
}
3 changes: 3 additions & 0 deletions test/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class options {
bool summary() const;
/** Perform dry run. */
bool dry_run() const;
/** Exclude provided lists of tests. */
bool exclude_tests() const;
/** Which test should be run. Empty string means 'all tests' */
const std::set<std::string>& which_test() const;

Expand All @@ -52,6 +54,7 @@ class options {
const bool mHelp;
const bool mSummary;
const bool mDryRun;
const bool mExcludeTests;
std::string mExe;
};

Expand Down
Loading