loolwsd/test/test.cpp | 74 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 20 deletions(-)
New commits: commit 5ffcafa736d28ff6184b0711c14136133ea82ce9 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sun Aug 28 16:32:34 2016 -0400 loolwsd: CPPUNIT_TEST_NAME can be regex To run selective tests only, CPPUNIT_TEST_NAME envar can be defined to hold the test-name, for example TileCacheTests::testClientPartImpress. Now it's possible to pass a regex value instead, for example TileCacheTests::testC.* to run both TileCacheTests::testClientPartImpress and TileCacheTests::testClientPartCalc. Change-Id: I96aa1ce242fd8afaf073527777be50308dce867c Reviewed-on: https://gerrit.libreoffice.org/28515 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/test/test.cpp b/loolwsd/test/test.cpp index bfaa5af..af0ff59 100644 --- a/loolwsd/test/test.cpp +++ b/loolwsd/test/test.cpp @@ -8,45 +8,79 @@ */ #include <iostream> -#include <cppunit/TestRunner.h> + +#include <cppunit/BriefTestProgressListener.h> +#include <cppunit/CompilerOutputter.h> #include <cppunit/TestResult.h> #include <cppunit/TestResultCollector.h> +#include <cppunit/TestRunner.h> #include <cppunit/TextTestProgressListener.h> -#include <cppunit/BriefTestProgressListener.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <cppunit/CompilerOutputter.h> + +#include <Poco/RegularExpression.h> class HTTPGetTest; -int main(int /*argc*/, char** /*argv*/) +bool filterTests(CPPUNIT_NS::TestRunner& runner, CPPUNIT_NS::Test* testRegistry) { - CPPUNIT_NS::TestResult controller; - CPPUNIT_NS::TestResultCollector result; - controller.addListener(&result); - CPPUNIT_NS::BriefTestProgressListener progress; - controller.addListener(&progress); - controller.addListener(new CPPUNIT_NS::TextTestProgressListener()); - - CPPUNIT_NS::TestRunner runner; - const char* testName = getenv("CPPUNIT_TEST_NAME"); - if (testName) + const char* envar = getenv("CPPUNIT_TEST_NAME"); + if (envar) { - // Single test. - CPPUNIT_NS::Test* testRegistry = CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest(); + std::string testName(envar); + if (testName.empty()) + { + return false; + } + + Poco::RegularExpression re(testName, Poco::RegularExpression::RE_CASELESS); + Poco::RegularExpression::Match reMatch; + + bool haveTests = false; for (int i = 0; i < testRegistry->getChildTestCount(); ++i) { CPPUNIT_NS::Test* testSuite = testRegistry->getChildTestAt(i); for (int j = 0; j < testSuite->getChildTestCount(); ++j) { CPPUNIT_NS::Test* testCase = testSuite->getChildTestAt(j); - if (testCase->getName() == testName) - runner.addTest(testCase); + try + { + if (re.match(testCase->getName(), reMatch)) + { + runner.addTest(testCase); + haveTests = true; + } + } + catch (const std::exception& exc) + { + // Nothing to do; skip. + } } } + + std::cerr << "Failed to match [" << testName << "] to any names in the test-suite. Running all tests." << std::endl; + return haveTests; } - else + + return false; +} + +int main(int /*argc*/, char** /*argv*/) +{ + CPPUNIT_NS::TestResult controller; + CPPUNIT_NS::TestResultCollector result; + controller.addListener(&result); + CPPUNIT_NS::BriefTestProgressListener progress; + controller.addListener(&progress); + controller.addListener(new CPPUNIT_NS::TextTestProgressListener()); + + CPPUNIT_NS::Test* testRegistry = CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest(); + + CPPUNIT_NS::TestRunner runner; + if (!filterTests(runner, testRegistry)) + { // All tests. - runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest()); + runner.addTest(testRegistry); + } runner.run(controller); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits