From 7bb6875ded43e2f308a23fec15a56262adc89eea Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 1 May 2016 20:09:20 +0200 Subject: [PATCH] Allow testing particular units --- CMakeLists.txt | 4 ++-- tests/cppunit.h | 17 ++++++++++++++++- tests/testutils.cpp | 8 ++++++-- tests/testutils.h | 10 ++++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44cee46..0079bd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,8 +88,8 @@ set(META_APP_NAME "C++ Utilities") set(META_APP_AUTHOR "Martchus") set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") set(META_APP_DESCRIPTION "Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities.") -set(META_VERSION_MAJOR 3) -set(META_VERSION_MINOR 3) +set(META_VERSION_MAJOR 4) +set(META_VERSION_MINOR 0) set(META_VERSION_PATCH 0) # include modules to apply configuration diff --git a/tests/cppunit.h b/tests/cppunit.h index 363a1c7..2aba57f 100644 --- a/tests/cppunit.h +++ b/tests/cppunit.h @@ -5,6 +5,7 @@ #include #include +#include #include @@ -22,7 +23,21 @@ int main(int argc, char **argv) // run tests TextUi::TestRunner runner; TestFactoryRegistry ®istry = TestFactoryRegistry::getRegistry(); - runner.addTest(registry.makeTest()); + const auto &units = testApp.units(); + if(units.empty()) { + // no units specified -> test all + runner.addTest(registry.makeTest()); + } else { + // pick specified units from overall test + Test *overallTest = registry.makeTest(); + for(const string &unit : units) { + try { + runner.addTest(overallTest->findTest(unit)); + } catch(const invalid_argument &) { + cerr << "The specified test unit \"" << unit << "\" is not available and will be ignored." << endl; + } + } + } return !runner.run(string(), false); } else { return -1; diff --git a/tests/testutils.cpp b/tests/testutils.cpp index 56093a0..41ed88a 100644 --- a/tests/testutils.cpp +++ b/tests/testutils.cpp @@ -31,7 +31,8 @@ TestApplication *TestApplication::m_instance = nullptr; TestApplication::TestApplication(int argc, char **argv) : m_helpArg(m_parser), m_testFilesPathArg("test-files-path", "p", "specifies the path of the directory with test files"), - m_workingDirArg("working-dir", "w", "specifies the directory to store working copies of test files") + m_workingDirArg("working-dir", "w", "specifies the directory to store working copies of test files"), + m_unitsArg("units", "u", "specifies the units to test; omit to test all units") { // check whether there is already an instance if(m_instance) { @@ -55,7 +56,10 @@ TestApplication::TestApplication(int argc, char **argv) : m_workingDirArg.setRequiredValueCount(1); m_workingDirArg.setValueNames({"path"}); m_workingDirArg.setCombinable(true); - m_parser.setMainArguments({&m_testFilesPathArg, &m_workingDirArg, &m_helpArg}); + m_unitsArg.setRequiredValueCount(-1); + m_unitsArg.setValueNames({"unit1", "unit2", "unit3"}); + m_unitsArg.setCombinable(true); + m_parser.setMainArguments({&m_testFilesPathArg, &m_workingDirArg, &m_unitsArg, &m_helpArg}); // parse arguments try { diff --git a/tests/testutils.h b/tests/testutils.h index 9ed42bd..a26b819 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -18,6 +18,7 @@ public: #ifdef PLATFORM_UNIX std::string workingCopyPath(const std::string &name) const; #endif + const ApplicationUtilities::StringVector &units() const; static const TestApplication *instance(); private: @@ -25,6 +26,7 @@ private: ApplicationUtilities::HelpArgument m_helpArg; ApplicationUtilities::Argument m_testFilesPathArg; ApplicationUtilities::Argument m_workingDirArg; + ApplicationUtilities::Argument m_unitsArg; std::string m_testFilesPathArgValue; std::string m_testFilesPathEnvValue; std::string m_workingDir; @@ -51,6 +53,14 @@ inline const TestApplication *TestApplication::instance() return TestApplication::m_instance; } +/*! + * \brief Returns the specified test units. + */ +inline const ApplicationUtilities::StringVector &TestApplication::units() const +{ + return m_unitsArg.values(); +} + /*! * \brief Convenience function which returns the full path of the test file with the specified \a name. * \remarks A TestApplication must be present.