From cfe9b766928d9fc3ccba72932d8a8000e8e3aff3 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 9 Mar 2026 21:19:17 +0100 Subject: [PATCH 1/2] TestFixture: avoid repeated lookups in `runTests()` --- test/fixture.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/fixture.cpp b/test/fixture.cpp index fb535b1a1d0..1ae87768e26 100644 --- a/test/fixture.cpp +++ b/test/fixture.cpp @@ -390,9 +390,10 @@ 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) { + testname = classname.substr(pos + 2); + classname.erase(pos); } for (TestInstance * test : TestRegistry::theInstance().tests()) { From 50c44db15b8166b3793ae9e32cf047e6ee75770b Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 9 Mar 2026 21:26:31 +0100 Subject: [PATCH 2/2] testrunner: added option `-x` to exclude the specified tests --- test/fixture.cpp | 16 +++++++++++----- test/options.cpp | 6 ++++++ test/options.h | 3 +++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/test/fixture.cpp b/test/fixture.cpp index 1ae87768e26..00c844815fa 100644 --- a/test/fixture.cpp +++ b/test/fixture.cpp @@ -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) @@ -392,16 +393,21 @@ std::size_t TestFixture::runTests(const options& args) std::string testname; 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); } } diff --git a/test/options.cpp b/test/options.cpp index e8b3be139ae..17e44eeb6bf 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -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();) { @@ -65,3 +66,8 @@ const std::string& options::exe() const { return mExe; } + +bool options::exclude_tests() const +{ + return mExcludeTests; +} diff --git a/test/options.h b/test/options.h index 18df1dd79b2..5be6ca34e61 100644 --- a/test/options.h +++ b/test/options.h @@ -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& which_test() const; @@ -52,6 +54,7 @@ class options { const bool mHelp; const bool mSummary; const bool mDryRun; + const bool mExcludeTests; std::string mExe; };