Skip to content

Commit 50c44db

Browse files
committed
testrunner: added option -x to exclude the specified tests
1 parent cfe9b76 commit 50c44db

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

test/fixture.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ void TestFixture::printHelp()
346346
" -q Do not print the test cases that have run.\n"
347347
" -h, --help Print this help.\n"
348348
" -n Print no summaries.\n"
349-
" -d Do not execute the tests.\n";
349+
" -d Do not execute any tests (dry run).\n"
350+
" -x Exclude the specified tests.\n";
350351
}
351352

352353
void TestFixture::run(const std::string &str)
@@ -392,16 +393,21 @@ std::size_t TestFixture::runTests(const options& args)
392393
std::string testname;
393394
const std::string::size_type pos = classname.find("::");
394395
if (pos != std::string::npos) {
396+
// TODO: excluding indiviual tests is not supported yet
395397
testname = classname.substr(pos + 2);
396398
classname.erase(pos);
397399
}
398400

399401
for (TestInstance * test : TestRegistry::theInstance().tests()) {
400-
if (classname.empty() || test->classname == classname) {
401-
TestFixture* fixture = test->create();
402-
fixture->processOptions(args);
403-
fixture->run(testname);
402+
if (!classname.empty()) {
403+
const bool match = test->classname == classname;
404+
if ((match && args.exclude_tests()) || (!match && !args.exclude_tests()))
405+
continue;
404406
}
407+
408+
TestFixture* fixture = test->create();
409+
fixture->processOptions(args);
410+
fixture->run(testname);
405411
}
406412
}
407413

test/options.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ options::options(int argc, const char* const argv[])
2222
,mHelp(mWhichTests.count("-h") != 0 || mWhichTests.count("--help"))
2323
,mSummary(mWhichTests.count("-n") == 0)
2424
,mDryRun(mWhichTests.count("-d") != 0)
25+
,mExcludeTests(mWhichTests.count("-x") != 0)
2526
,mExe(argv[0])
2627
{
2728
for (auto it = mWhichTests.cbegin(); it != mWhichTests.cend();) {
@@ -65,3 +66,8 @@ const std::string& options::exe() const
6566
{
6667
return mExe;
6768
}
69+
70+
bool options::exclude_tests() const
71+
{
72+
return mExcludeTests;
73+
}

test/options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class options {
3737
bool summary() const;
3838
/** Perform dry run. */
3939
bool dry_run() const;
40+
/** Exclude provided lists of tests. */
41+
bool exclude_tests() const;
4042
/** Which test should be run. Empty string means 'all tests' */
4143
const std::set<std::string>& which_test() const;
4244

@@ -52,6 +54,7 @@ class options {
5254
const bool mHelp;
5355
const bool mSummary;
5456
const bool mDryRun;
57+
const bool mExcludeTests;
5558
std::string mExe;
5659
};
5760

0 commit comments

Comments
 (0)