cpp-utilities/tests/cppunit.h

49 lines
1.3 KiB
C
Raw Normal View History

2017-10-24 01:02:07 +02:00
#ifndef TESTUTILS_CPPUNIT_H
#define TESTUTILS_CPPUNIT_H
#include "./testutils.h"
2017-05-01 03:13:11 +02:00
#include <cppunit/TestPath.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
#include <iostream>
using namespace std;
using namespace CppUtilities;
using namespace CPPUNIT_NS;
/*!
* \brief Performs unit tests using cppunit.
*/
int main(int argc, char **argv)
{
TestApplication testApp(argc, argv);
2017-10-24 01:02:07 +02:00
if (!testApp) {
return -1;
}
// run tests
TextUi::TestRunner runner;
TestFactoryRegistry &registry = TestFactoryRegistry::getRegistry();
if (!testApp.unitsSpecified() || testApp.units().empty()) {
// no units specified -> test all
runner.addTest(registry.makeTest());
} else {
// pick specified units from overall test
Test *overallTest = registry.makeTest();
for (const char *unit : testApp.units()) {
try {
runner.addTest(overallTest->findTest(unit));
} catch (const invalid_argument &) {
2019-05-04 15:47:31 +02:00
cerr << "The specified test unit \"" << unit << "\" is not available and will be ignored.\n";
2016-05-01 20:09:20 +02:00
}
}
}
2019-05-04 15:47:31 +02:00
const auto ok = runner.run(string(), false);
cerr << (ok ? "Tests successful\n" : "Tests failed\n");
return !ok;
}
2017-10-24 01:02:07 +02:00
#endif // TESTUTILS_CPPUNIT_H