diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-04-20 20:54:36 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-04-20 20:54:36 +0000 |
| commit | f05089dffe81419786776b60bc2dc13d2a421a5c (patch) | |
| tree | 8451a33146a505c999a28288fe4574e98f268238 /src/DllPlugInTester/DllPlugInTester.cpp | |
| parent | c4995a9e022ed586cf4e3f166738dfe01bf51c16 (diff) | |
| download | cppunit-f05089dffe81419786776b60bc2dc13d2a421a5c.tar.gz | |
THANKS: updated
THANKS: updated
* src/cppunit/DynamicLibraryManager.cpp: bugfix: did not pass
library name to exception.
* include/cppunit/TestPath.h:
* src/cppunit/TestPath.cpp: changed into value object.
* src/cppunit/BeosDynamicLibraryManager.cpp: integrated patch from
Shibu Yoshiki for BeOS ('cuppa' project team).
* src/DllPlugInTester/CommandLineParser.h:
* src/DllPlugInTester/CommandLineParser.cpp: added. Command line
parsing.
* src/DllPlugInTester/DllPlugInTester.cpp: full command line support
with parameters for plug-ins.
* src/DllPlugInTester/makefile.am:
* examples/simple/makefile.am:
* examples/cppunittest/makefile.am: integrated Jeffrey Morgan patch,
Unix side should be working again.
* examples/ReadMe.txt: added. Brief description of each example.
* examples/cppunittest/CppUnitTestPlugIn.cpp:
* examples/cppunittest/CppUnitTestPlugIn.dsp: added. New project to
build CppUnit's test suite as a test plug-in.
* examples/cppunittest/CppUnitTestSuite.cpp: updated. Use new
helper macros to create the test suite hierarchy.
* examples/simple/simple_plugin.opt: added. Contains debug tab
settings.
* examples/ClockerPlugIn/ClockerListener.cpp:
* examples/ClockerPlugIn/ClockerListener.h:
* examples/ClockerPlugIn/Timer.cpp:
* examples/ClockerPlugIn/Timer.h:
* examples/ClockerPlugIn/WinNtTimer.cpp:
* examples/ClockerPlugIn/WinNtTimer.h:
* examples/ClockerPlugIn/ClockerPlugIn.cpp:
* examples/ClockerPlugIn/ClockerPlugIn.dsp: added. test listener
plug-in that times tests.
* examples/DumperPlugIn/DumperListener.cpp:
* examples/DumperPlugIn/DumperListener.h:
* examples/DumperPlugIn/DumperPlugIn.cpp:
* examples/DumperPlugIn/DumperPlugIn.dsp: added. test listener
plug-in that dump the test tree.
Diffstat (limited to 'src/DllPlugInTester/DllPlugInTester.cpp')
| -rw-r--r-- | src/DllPlugInTester/DllPlugInTester.cpp | 93 |
1 files changed, 66 insertions, 27 deletions
diff --git a/src/DllPlugInTester/DllPlugInTester.cpp b/src/DllPlugInTester/DllPlugInTester.cpp index d52c552..df55e06 100644 --- a/src/DllPlugInTester/DllPlugInTester.cpp +++ b/src/DllPlugInTester/DllPlugInTester.cpp @@ -4,40 +4,58 @@ #include <cppunit/TestResult.h> #include <cppunit/TestResultCollector.h> #include <cppunit/TestRunner.h> +#include <cppunit/TextOutputter.h> #include <cppunit/TextTestProgressListener.h> +#include <cppunit/XmlOutputter.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <cppunit/plugin/DynamicLibraryManagerException.h> #include <cppunit/plugin/Parameters.h> #include <cppunit/plugin/PlugInManager.h> #include <cppunit/plugin/TestPlugIn.h> #include <iostream> +#include <fstream> +#include "CommandLineParser.h" /*! Runs the specified tests located in the root suite. - * \param parameters List of string representing the command line arguments. + * \param parser Command line parser. * \return \c true if the run succeed, \c false if a test failed or if a test * path was not resolved. */ bool -runTests( CppUnit::Parameters parameters ) +runTests( const CommandLineParser &parser ) { CppUnit::TestResult controller; CppUnit::TestResultCollector result; controller.addListener( &result ); - CppUnit::TextTestProgressListener progress; -// CppUnit::BriefTestProgressListener progress; - controller.addListener( &progress ); - std::string testPath; + // Set up outputters + std::ostream *stream = &std::cerr; + if ( parser.useCoutStream() ) + stream = &std::cout; + + std::ostream *xmlStream = stream; + if ( !parser.getXmlFileName().empty() ) + xmlStream = new std::ofstream( parser.getXmlFileName().c_str() ); + + CppUnit::XmlOutputter xmlOutputter( &result, *xmlStream, parser.getEncoding() ); + CppUnit::TextOutputter textOutputter( &result, *stream ); + CppUnit::CompilerOutputter compilerOutputter( &result, *stream ); + + // Set up test listeners + CppUnit::BriefTestProgressListener briefListener; + CppUnit::TextTestProgressListener dotListener; + if ( parser.useBriefTestProgress() ) + controller.addListener( &briefListener ); + else if ( !parser.noTestProgress() ) + controller.addListener( &dotListener ); + + // Set up plug-ins CppUnit::PlugInManager plugInManager; - // Loads plug-ins & get test path. - for ( int index =0; index < parameters.size(); ++index ) + for ( int index =0; index < parser.getPlugInCount(); ++index ) { - std::string parameter = parameters[index]; - if ( parameter[0] == ':' ) - testPath = parameter.substr(1); - else - plugInManager.load( parameter ); + CommandLinePlugInInfo plugIn = parser.getPlugInAt( index ); + plugInManager.load( plugIn.m_fileName, plugIn.m_parameters ); } // Registers plug-in specific TestListener (global setUp/tearDown, custom TestListener...) @@ -48,26 +66,36 @@ runTests( CppUnit::Parameters parameters ) runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() ); // Runs the specified test + bool wasSuccessful = false; try { - runner.run( controller ); + runner.run( controller, parser.getTestPath() ); + wasSuccessful = result.wasSuccessful(); } catch ( std::invalid_argument & ) { - std::cerr << "Failed to resolve test path: " << testPath << std::endl; - return false; + std::cerr << "Failed to resolve test path: " + << parser.getTestPath() + << std::endl; } // Removes plug-in specific TestListener (not really needed but...) plugInManager.removeListener( &controller ); - std::cerr << std::endl; + // write using outputters + if ( parser.useCompilerOutputter() ) + compilerOutputter.write(); + + if ( parser.useTextOutputter() ) + textOutputter.write(); + + if ( parser.useXmlOutputter() ) + xmlOutputter.write(); - // Outputs test result - CppUnit::CompilerOutputter outputter( &result, std::cerr ); - outputter.write(); + if ( !parser.getXmlFileName().empty() ) + delete xmlStream; - return result.wasSuccessful(); + return wasSuccessful; } @@ -96,7 +124,8 @@ runTests( CppUnit::Parameters parameters ) * * If all test succeed and no error happen then the application exit with code 0. * If any error occurs (failed to load dll, failed to resolve test paths) or a - * test fail, the application exit with code 1. + * test fail, the application exit with code 1. If the application failed to + * parse the command line, it exits with code 2. */ int main( int argc, @@ -104,6 +133,7 @@ main( int argc, { const int successReturnCode = 0; const int failureReturnCode = 1; + const int badCommadLineReturnCode = 2; // check command line std::string applicationName( argv[0] ); @@ -113,16 +143,25 @@ main( int argc, << applicationName << " dll-filename1 [dll-filename2 ...] [:test-path]..." << std::endl; - return failureReturnCode; + return badCommadLineReturnCode; + } + + CommandLineParser parser( argc, argv ); + try + { + parser.parse(); + } + catch ( CommandLineParserException &e ) + { + std::cerr << "Error while parsing command line: " << e.what() + << std::endl; + return badCommadLineReturnCode; } bool wasSuccessful = false; try { - CppUnit::Parameters parameters; - for ( int index =1; index < argc; ++index ) - parameters.push_back( argv[index] ); - wasSuccessful = runTests( parameters ); + wasSuccessful = runTests( parser ); } catch ( CppUnit::DynamicLibraryManagerException &e ) { |
