From 9ce371fa1626bb845e702ceef66a730547b313a8 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Thu, 30 Apr 2015 20:51:29 +0200 Subject: 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 Reviewed-by: Markus Mohrhard --- sal/cppunittester/cppunittester.cxx | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'sal/cppunittester') diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx index ffad4d402b70..6c1541733ad5 100644 --- a/sal/cppunittester/cppunittester.cxx +++ b/sal/cppunittester/cppunittester.cxx @@ -49,6 +49,9 @@ #include "boost/noncopyable.hpp" #include +#include + +#include namespace { @@ -161,6 +164,21 @@ private: } }; +namespace { + +void addRecursiveTests(const std::vector& 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 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()); -- cgit v1.2.3