Allow testing particular units

This commit is contained in:
Martchus 2016-05-01 20:09:20 +02:00
parent 1aa5421e9b
commit 7bb6875ded
4 changed files with 34 additions and 5 deletions

View File

@ -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

View File

@ -5,6 +5,7 @@
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/TestPath.h>
#include <iostream>
@ -22,7 +23,21 @@ int main(int argc, char **argv)
// run tests
TextUi::TestRunner runner;
TestFactoryRegistry &registry = 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;

View File

@ -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 {

View File

@ -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.