101 lines
2.4 KiB
C++
101 lines
2.4 KiB
C++
#include <iostream>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <getopt.h>
|
|
|
|
#include <cppunit/TestRunner.h>
|
|
#include <cppunit/TestResult.h>
|
|
#include <cppunit/TestResultCollector.h>
|
|
#include <cppunit/TextTestProgressListener.h>
|
|
#include <cppunit/extensions/TestFactoryRegistry.h>
|
|
#include <cppunit/CompilerOutputter.h>
|
|
|
|
|
|
using namespace std;
|
|
|
|
int main(int argc,char *argv[])
|
|
{
|
|
bool xmlOutput = false;
|
|
vector<string> tests;
|
|
|
|
int c;
|
|
opterr = 0; // disable getopt error
|
|
|
|
int option_index = 0;
|
|
static struct option long_options[] = {
|
|
{"test", required_argument, 0, 't' },
|
|
{"xml-output", required_argument, 0, 'x' },
|
|
{0, 0, 0, 0 }
|
|
};
|
|
|
|
while ((c = getopt_long(argc, argv, "", long_options,&option_index)) != -1){
|
|
switch (c){
|
|
case 'x':
|
|
xmlOutput = true;
|
|
break;
|
|
case 't':
|
|
tests.push_back(optarg); //get input files
|
|
break;
|
|
case '?':
|
|
if (optopt == 'o')
|
|
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
|
else if (isprint (optopt))
|
|
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
|
else
|
|
fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
|
|
return 1;
|
|
default:
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
//get input files
|
|
for (int index = optind; index < argc; index++)
|
|
tests.push_back(argv[index]);
|
|
|
|
|
|
// Create the event manager and test controller
|
|
CppUnit::TestResult controller;
|
|
|
|
// Add a listener that colllects test result
|
|
CppUnit::TestResultCollector result;
|
|
controller.addListener( &result );
|
|
|
|
// Add a listener that print dots as test run.
|
|
CppUnit::TextTestProgressListener progress;
|
|
controller.addListener( &progress );
|
|
|
|
|
|
CppUnit::TestRunner testrunner;
|
|
|
|
testrunner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
|
|
|
try
|
|
{
|
|
if(tests.empty()){
|
|
cout << "Running all tests" << endl;
|
|
testrunner.run(controller);
|
|
cerr << endl;
|
|
CppUnit::CompilerOutputter outputter( &result, cerr );
|
|
outputter.write();
|
|
|
|
}else{
|
|
for(int i = 0; i < tests.size(); i++){
|
|
cout << "Running " << tests[i];
|
|
testrunner.run( controller, tests[i] );
|
|
cerr << endl;
|
|
CppUnit::CompilerOutputter outputter( &result, cerr );
|
|
outputter.write();
|
|
}
|
|
}
|
|
}
|
|
catch ( std::invalid_argument &e ) // Test path not resolved
|
|
{
|
|
std::cerr << std::endl
|
|
<< "ERROR: " << e.what()
|
|
<< std::endl;
|
|
return 0;
|
|
}
|
|
|
|
return result.wasSuccessful() ? 0 : 1;
|
|
} |