[Libreoffice-commits] core.git: sal/cppunittester
Markus Mohrhard
markus.mohrhard at googlemail.com
Thu Apr 30 12:11:51 PDT 2015
sal/cppunittester/cppunittester.cxx | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
New commits:
commit 9ce371fa1626bb845e702ceef66a730547b313a8
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Thu Apr 30 20:51:29 2015 +0200
provide a way to execute single test case from test suite
CPPUNIT_TEST_NAME is the environment variable that needs to be set and
contain the name of the tests. The test names need to be fully qualified
to be recognized.
Examples:
CPPUNIT_TEST_NAME="ScFiltersTest::testOutlineODS ScFiltersTest::testRangeNameXLS" make CppunitTest_sc_subsequent_filters_test
CPPUNIT_TEST_NAME="ScFiltersTest" make CppunitTest_sc_subsequent_filters_test
Change-Id: I78a8a076638e19c918ca1c411086bb353f5100a2
Reviewed-on: https://gerrit.libreoffice.org/15579
Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx
index ffad4d4..6c15417 100644
--- a/sal/cppunittester/cppunittester.cxx
+++ b/sal/cppunittester/cppunittester.cxx
@@ -49,6 +49,9 @@
#include "boost/noncopyable.hpp"
#include <boost/scoped_array.hpp>
+#include <boost/algorithm/string.hpp>
+
+#include <algorithm>
namespace {
@@ -161,6 +164,21 @@ private:
}
};
+namespace {
+
+void addRecursiveTests(const std::vector<std::string>& test_names, CppUnit::Test* pTest, CppUnit::TestRunner& rRunner)
+{
+ for (int i = 0; i < pTest->getChildTestCount(); ++i)
+ {
+ CppUnit::Test* pNewTest = pTest->getChildTestAt(i);
+ addRecursiveTests(test_names, pNewTest, rRunner);
+ if (std::find(test_names.begin(), test_names.end(), pNewTest->getName()) != test_names.end())
+ rRunner.addTest(pNewTest);
+ }
+}
+
+}
+
//Allow the whole uniting testing framework to be run inside a "Protector"
//which knows about uno exceptions, so it can print the content of the
//exception before falling over and dying
@@ -241,9 +259,20 @@ public:
setenv("LO_TESTNAME", lib.c_str(), true);
#endif
+ const char* pVal = getenv("CPPUNIT_TEST_NAME");
+
CppUnit::TestRunner runner;
- runner.addTest(
- CppUnit::TestFactoryRegistry::getRegistry().makeTest());
+ if (pVal)
+ {
+ 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);
+ }
+ else
+ {
+ runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
+ }
runner.run(result);
CppUnit::CompilerOutputter outputter(&collector, CppUnit::stdCErr());
More information about the Libreoffice-commits
mailing list