[Libreoffice-commits] core.git: sal/cppunittester

Michael Stahl mstahl at redhat.com
Thu Apr 27 14:47:30 UTC 2017


 sal/cppunittester/cppunittester.cxx |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

New commits:
commit 86931aded4e603d244c9aef17c872f0b3807bee9
Author: Michael Stahl <mstahl at redhat.com>
Date:   Thu Apr 27 16:39:44 2017 +0200

    sal: cppunittester: verify that CPPUNIT_TEST_NAME contains a test
    
    Fail the test if CPPUNIT_TEST_NAME does not contain at least one
    existing test, which is much better than silently reporting OK(0).
    
    Change-Id: If2137764b24aa52dc35fe2368ee8fe38cb7dbece

diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx
index 11078c7cf74b..7b321643a37a 100644
--- a/sal/cppunittester/cppunittester.cxx
+++ b/sal/cppunittester/cppunittester.cxx
@@ -197,15 +197,20 @@ struct test_name_compare
     std::string maName;
 };
 
-void addRecursiveTests(const std::vector<std::string>& test_names, CppUnit::Test* pTest, CppUnit::TestRunner& rRunner)
+bool addRecursiveTests(const std::vector<std::string>& test_names, CppUnit::Test* pTest, CppUnit::TestRunner& rRunner)
 {
+    bool ret(false);
     for (int i = 0; i < pTest->getChildTestCount(); ++i)
     {
         CppUnit::Test* pNewTest = pTest->getChildTestAt(i);
-        addRecursiveTests(test_names, pNewTest, rRunner);
+        ret |= addRecursiveTests(test_names, pNewTest, rRunner);
         if (std::find_if(test_names.begin(), test_names.end(), test_name_compare(pNewTest->getName())) != test_names.end())
+        {
             rRunner.addTest(pNewTest);
+            ret = true;
+        }
     }
+    return ret;
 }
 
 }
@@ -297,7 +302,12 @@ public:
                 std::vector<std::string> test_names;
                 boost::split(test_names, pVal, boost::is_any_of("\t "));
                 CppUnit::Test* pTest = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
-                addRecursiveTests(test_names, pTest, runner);
+                bool const added(addRecursiveTests(test_names, pTest, runner));
+                if (!added)
+                {
+                    std::cerr << "\nFatal error: CPPUNIT_TEST_NAME contains no valid tests\n";
+                    return false;
+                }
             }
             else
             {


More information about the Libreoffice-commits mailing list