Blame include/cppunit/CompilerOutputter.h

Packit 8c9aa0
#ifndef CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H
Packit 8c9aa0
#define CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H
Packit 8c9aa0
Packit 8c9aa0
#include <cppunit/Portability.h>
Packit 8c9aa0
#include <cppunit/Outputter.h>
Packit 8c9aa0
#include <cppunit/portability/Stream.h>
Packit 8c9aa0
Packit 8c9aa0
CPPUNIT_NS_BEGIN
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
class Exception;
Packit 8c9aa0
class SourceLine;
Packit 8c9aa0
class Test;
Packit 8c9aa0
class TestFailure;
Packit 8c9aa0
class TestResultCollector;
Packit 8c9aa0
Packit 8c9aa0
/*! 
Packit 8c9aa0
 * \brief Outputs a TestResultCollector in a compiler compatible format.
Packit 8c9aa0
 * \ingroup WritingTestResult
Packit 8c9aa0
 *
Packit 8c9aa0
 * Printing the test results in a compiler compatible format (assertion
Packit 8c9aa0
 * location has the same format as compiler error), allow you to use your
Packit 8c9aa0
 * IDE to jump to the assertion failure. Location format can be customized (see
Packit 8c9aa0
 * setLocationFormat() ).
Packit 8c9aa0
 *
Packit 8c9aa0
 * For example, when running the test in a post-build with VC++, if an assertion
Packit 8c9aa0
 * fails, you can jump to the assertion by pressing F4 (jump to next error).
Packit 8c9aa0
 *
Packit 8c9aa0
 * Heres is an example of usage (from examples/cppunittest/CppUnitTestMain.cpp):
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * int main( int argc, char* argv[] ) {
Packit 8c9aa0
 *   // if command line contains "-selftest" then this is the post build check
Packit 8c9aa0
 *   // => the output must be in the compiler error format.
Packit 8c9aa0
 *   bool selfTest = (argc > 1)  &&  
Packit 8c9aa0
 *                   (std::string("-selftest") == argv[1]);
Packit 8c9aa0
 *
Packit 8c9aa0
 *   CppUnit::TextUi::TestRunner runner;
Packit 8c9aa0
 *   runner.addTest( CppUnitTest::suite() );   // Add the top suite to the test runner
Packit 8c9aa0
 * 
Packit 8c9aa0
 *  if ( selfTest )
Packit 8c9aa0
 *   { // Change the default outputter to a compiler error format outputter
Packit 8c9aa0
 *     // The test runner owns the new outputter.
Packit 8c9aa0
 *     runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
Packit 8c9aa0
 *                                                          std::cerr ) );
Packit 8c9aa0
 *   }
Packit 8c9aa0
 * 
Packit 8c9aa0
 *  // Run the test and don't wait a key if post build check.
Packit 8c9aa0
 *   bool wasSuccessful = runner.run( "", !selfTest );
Packit 8c9aa0
 * 
Packit 8c9aa0
 *   // Return error code 1 if the one of test failed.
Packit 8c9aa0
 *   return wasSuccessful ? 0 : 1;
Packit 8c9aa0
 * }
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 */
Packit 8c9aa0
class CPPUNIT_API CompilerOutputter : public Outputter
Packit 8c9aa0
{
Packit 8c9aa0
public:
Packit 8c9aa0
  /*! \brief Constructs a CompilerOutputter object.
Packit 8c9aa0
   * \param result Result of the test run.
Packit 8c9aa0
   * \param stream Stream used to output test result.
Packit 8c9aa0
   * \param locationFormat Error location format used by your compiler. Default
Packit 8c9aa0
   *                       to \c CPPUNIT_COMPILER_LOCATION_FORMAT which is defined
Packit 8c9aa0
   *                       in the configuration file. See setLocationFormat() for detail.
Packit 8c9aa0
   * \see setLocationFormat().
Packit 8c9aa0
   */
Packit 8c9aa0
  CompilerOutputter( TestResultCollector *result,
Packit 8c9aa0
                     OStream &stream,
Packit 8c9aa0
                     const std::string &locationFormat = CPPUNIT_COMPILER_LOCATION_FORMAT );
Packit 8c9aa0
Packit 8c9aa0
  /// Destructor.
Packit 8c9aa0
  virtual ~CompilerOutputter();
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Sets the error location format.
Packit 8c9aa0
   * 
Packit 8c9aa0
   * Indicates the format used to report location of failed assertion. This format should
Packit 8c9aa0
   * match the one used by your compiler.
Packit 8c9aa0
   *
Packit 8c9aa0
   * The location format is a string in which the occurence of the following character
Packit 8c9aa0
   * sequence are replaced:
Packit 8c9aa0
   *
Packit 8c9aa0
   * - "%l" => replaced by the line number
Packit 8c9aa0
   * - "%p" => replaced by the full path name of the file ("G:\prg\vc\cppunit\MyTest.cpp")
Packit 8c9aa0
   * - "%f" => replaced by the base name of the file ("MyTest.cpp")
Packit 8c9aa0
   *
Packit 8c9aa0
   * Some examples:
Packit 8c9aa0
   *
Packit 8c9aa0
   * - VC++ error location format: "%p(%l):" => produce "G:\prg\MyTest.cpp(43):"
Packit 8c9aa0
   * - GCC error location format: "%f:%l:" => produce "MyTest.cpp:43:"
Packit 8c9aa0
   * 
Packit 8c9aa0
   * Thoses are the two compilers currently supported (gcc format is used if
Packit 8c9aa0
   * VC++ is not detected). If you want your compiler to be automatically supported by
Packit 8c9aa0
   * CppUnit, send a mail to the mailing list (preferred), or submit a feature request
Packit 8c9aa0
   * that indicates how to detect your compiler with the preprocessor (\#ifdef...) and
Packit 8c9aa0
   * your compiler location format.
Packit 8c9aa0
   */
Packit 8c9aa0
  void setLocationFormat( const std::string &locationFormat );
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Creates an instance of an outputter that matches your current compiler.
Packit 8c9aa0
   * \deprecated This class is specialized through parameterization instead of subclassing...
Packit 8c9aa0
   *             Use CompilerOutputter::CompilerOutputter instead.
Packit 8c9aa0
   */
Packit 8c9aa0
  static CompilerOutputter *defaultOutputter( TestResultCollector *result,
Packit 8c9aa0
                                              OStream &stream );
Packit 8c9aa0
Packit 8c9aa0
  void write();
Packit 8c9aa0
Packit 8c9aa0
  void setNoWrap();
Packit 8c9aa0
Packit 8c9aa0
  void setWrapColumn( int wrapColumn );
Packit 8c9aa0
Packit 8c9aa0
  int wrapColumn() const;
Packit 8c9aa0
Packit 8c9aa0
  virtual void printSuccess();
Packit 8c9aa0
  virtual void printFailureReport();
Packit 8c9aa0
  virtual void printFailuresList();
Packit 8c9aa0
  virtual void printStatistics();
Packit 8c9aa0
  virtual void printFailureDetail( TestFailure *failure );
Packit 8c9aa0
  virtual void printFailureLocation( SourceLine sourceLine );
Packit 8c9aa0
  virtual void printFailureType( TestFailure *failure );
Packit 8c9aa0
  virtual void printFailedTestName( TestFailure *failure );
Packit 8c9aa0
  virtual void printFailureMessage( TestFailure *failure );
Packit 8c9aa0
Packit 8c9aa0
private:
Packit 8c9aa0
  /// Prevents the use of the copy constructor.
Packit 8c9aa0
  CompilerOutputter( const CompilerOutputter &copy );
Packit 8c9aa0
Packit 8c9aa0
  /// Prevents the use of the copy operator.
Packit 8c9aa0
  void operator =( const CompilerOutputter &copy );
Packit 8c9aa0
Packit 8c9aa0
  virtual bool processLocationFormatCommand( char command, 
Packit 8c9aa0
                                             const SourceLine &sourceLine );
Packit 8c9aa0
Packit 8c9aa0
  virtual std::string extractBaseName( const std::string &fileName ) const;
Packit 8c9aa0
Packit 8c9aa0
private:
Packit 8c9aa0
  TestResultCollector *m_result;
Packit 8c9aa0
  OStream &m_stream;
Packit 8c9aa0
  std::string m_locationFormat;
Packit 8c9aa0
  int m_wrapColumn;
Packit 8c9aa0
};
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
CPPUNIT_NS_END
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
#endif  // CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H