Blame include/cppunit/CompilerOutputter.h

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