Allow testing particular units
This commit is contained in:
parent
1aa5421e9b
commit
7bb6875ded
|
@ -88,8 +88,8 @@ set(META_APP_NAME "C++ Utilities")
|
||||||
set(META_APP_AUTHOR "Martchus")
|
set(META_APP_AUTHOR "Martchus")
|
||||||
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
|
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_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_MAJOR 4)
|
||||||
set(META_VERSION_MINOR 3)
|
set(META_VERSION_MINOR 0)
|
||||||
set(META_VERSION_PATCH 0)
|
set(META_VERSION_PATCH 0)
|
||||||
|
|
||||||
# include modules to apply configuration
|
# include modules to apply configuration
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||||
#include <cppunit/ui/text/TestRunner.h>
|
#include <cppunit/ui/text/TestRunner.h>
|
||||||
|
#include <cppunit/TestPath.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -22,7 +23,21 @@ int main(int argc, char **argv)
|
||||||
// run tests
|
// run tests
|
||||||
TextUi::TestRunner runner;
|
TextUi::TestRunner runner;
|
||||||
TestFactoryRegistry ®istry = TestFactoryRegistry::getRegistry();
|
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);
|
return !runner.run(string(), false);
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -31,7 +31,8 @@ TestApplication *TestApplication::m_instance = nullptr;
|
||||||
TestApplication::TestApplication(int argc, char **argv) :
|
TestApplication::TestApplication(int argc, char **argv) :
|
||||||
m_helpArg(m_parser),
|
m_helpArg(m_parser),
|
||||||
m_testFilesPathArg("test-files-path", "p", "specifies the path of the directory with test files"),
|
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
|
// check whether there is already an instance
|
||||||
if(m_instance) {
|
if(m_instance) {
|
||||||
|
@ -55,7 +56,10 @@ TestApplication::TestApplication(int argc, char **argv) :
|
||||||
m_workingDirArg.setRequiredValueCount(1);
|
m_workingDirArg.setRequiredValueCount(1);
|
||||||
m_workingDirArg.setValueNames({"path"});
|
m_workingDirArg.setValueNames({"path"});
|
||||||
m_workingDirArg.setCombinable(true);
|
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
|
// parse arguments
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -18,6 +18,7 @@ public:
|
||||||
#ifdef PLATFORM_UNIX
|
#ifdef PLATFORM_UNIX
|
||||||
std::string workingCopyPath(const std::string &name) const;
|
std::string workingCopyPath(const std::string &name) const;
|
||||||
#endif
|
#endif
|
||||||
|
const ApplicationUtilities::StringVector &units() const;
|
||||||
static const TestApplication *instance();
|
static const TestApplication *instance();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -25,6 +26,7 @@ private:
|
||||||
ApplicationUtilities::HelpArgument m_helpArg;
|
ApplicationUtilities::HelpArgument m_helpArg;
|
||||||
ApplicationUtilities::Argument m_testFilesPathArg;
|
ApplicationUtilities::Argument m_testFilesPathArg;
|
||||||
ApplicationUtilities::Argument m_workingDirArg;
|
ApplicationUtilities::Argument m_workingDirArg;
|
||||||
|
ApplicationUtilities::Argument m_unitsArg;
|
||||||
std::string m_testFilesPathArgValue;
|
std::string m_testFilesPathArgValue;
|
||||||
std::string m_testFilesPathEnvValue;
|
std::string m_testFilesPathEnvValue;
|
||||||
std::string m_workingDir;
|
std::string m_workingDir;
|
||||||
|
@ -51,6 +53,14 @@ inline const TestApplication *TestApplication::instance()
|
||||||
return TestApplication::m_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.
|
* \brief Convenience function which returns the full path of the test file with the specified \a name.
|
||||||
* \remarks A TestApplication must be present.
|
* \remarks A TestApplication must be present.
|
||||||
|
|
Loading…
Reference in New Issue