[Libreoffice-commits] online.git: loolwsd/test

Pranav Kant pranavk at collabora.co.uk
Mon Oct 17 15:57:31 UTC 2016


 loolwsd/test/test.cpp |   73 ++++++++++++++++++++++++--------------------------
 1 file changed, 36 insertions(+), 37 deletions(-)

New commits:
commit 8ab4682a710dbea6286ccd09c2239413038c80fd
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Mon Oct 17 21:21:54 2016 +0530

    loolwsd: Fix handling of CPPUNIT_TEST_NAME in external test-suite
    
    Doing a plain CPPUNIT_TEST_NAME='somettest' make check will
    result in executing all the tests in external test suite. This is
    a problem when one wants to execute only internal tests (unit-*
    ones) as test harness first executes those followed by all of the
    tests in external test-suites.
    
    Lets execute all the tests only when no CPPUNIT_TEST_NAME is
    provided, and ignore when it is provided but no match is found.
    
    Change-Id: I7e40b6f3124e6965a86cfb6395d246df3b5c17ba

diff --git a/loolwsd/test/test.cpp b/loolwsd/test/test.cpp
index 7a081a9..ba80912 100644
--- a/loolwsd/test/test.cpp
+++ b/loolwsd/test/test.cpp
@@ -24,51 +24,34 @@
 
 class HTTPGetTest;
 
-bool filterTests(CPPUNIT_NS::TestRunner& runner, CPPUNIT_NS::Test* testRegistry)
+bool filterTests(CPPUNIT_NS::TestRunner& runner, CPPUNIT_NS::Test* testRegistry, const std::string testName)
 {
-    const char* envar = std::getenv("CPPUNIT_TEST_NAME");
-    if (envar)
-    {
-        std::string testName(envar);
-        if (testName.empty())
-        {
-            return false;
-        }
-
-        Poco::RegularExpression re(testName, Poco::RegularExpression::RE_CASELESS);
-        Poco::RegularExpression::Match reMatch;
+    Poco::RegularExpression re(testName, Poco::RegularExpression::RE_CASELESS);
+    Poco::RegularExpression::Match reMatch;
 
-        bool haveTests = false;
-        for (int i = 0; i < testRegistry->getChildTestCount(); ++i)
+    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* testSuite = testRegistry->getChildTestAt(i);
-            for (int j = 0; j < testSuite->getChildTestCount(); ++j)
+            CPPUNIT_NS::Test* testCase = testSuite->getChildTestAt(j);
+            try
             {
-                CPPUNIT_NS::Test* testCase = testSuite->getChildTestAt(j);
-                try
-                {
-                    if (re.match(testCase->getName(), reMatch))
-                    {
-                        runner.addTest(testCase);
-                        haveTests = true;
-                    }
-                }
-                catch (const std::exception& exc)
+                if (re.match(testCase->getName(), reMatch))
                 {
-                    // Nothing to do; skip.
+                    runner.addTest(testCase);
+                    haveTests = true;
                 }
             }
+            catch (const std::exception& exc)
+            {
+                // Nothing to do; skip.
+            }
         }
-
-        if (!haveTests)
-        {
-            std::cerr << "Failed to match [" << testName << "] to any names in the test-suite. Running all tests." << std::endl;
-        }
-
-        return haveTests;
     }
 
-    return false;
+    return haveTests;
 }
 
 int main(int /*argc*/, char** /*argv*/)
@@ -86,11 +69,27 @@ int main(int /*argc*/, char** /*argv*/)
     CPPUNIT_NS::Test* testRegistry = CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
 
     CPPUNIT_NS::TestRunner runner;
-    if (!filterTests(runner, testRegistry))
+    const char* envar = std::getenv("CPPUNIT_TEST_NAME");
+    std::string testName;
+    if (envar)
+    {
+        testName = std::string(envar);
+    }
+
+    if (testName.empty())
     {
-        // All tests.
+        // Add all tests.
         runner.addTest(testRegistry);
     }
+    else
+    {
+        const bool testsAdded = filterTests(runner, testRegistry, testName);
+        if (!testsAdded)
+        {
+            std::cerr << "Failed to match [" << testName << "] to any names in the external test-suite. "
+                      << "No external tests will be executed" << std::endl;
+        }
+    }
 
     runner.run(controller);
 


More information about the Libreoffice-commits mailing list