~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to third-party/cppunit/cppunit/include/cppunit/CompilerOutputter.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H
2
 
#define CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H
3
 
 
4
 
#include <cppunit/Portability.h>
5
 
#include <cppunit/Outputter.h>
6
 
#include <cppunit/portability/Stream.h>
7
 
 
8
 
CPPUNIT_NS_BEGIN
9
 
 
10
 
 
11
 
class Exception;
12
 
class SourceLine;
13
 
class Test;
14
 
class TestFailure;
15
 
class TestResultCollector;
16
 
 
17
 
/*! 
18
 
 * \brief Outputs a TestResultCollector in a compiler compatible format.
19
 
 * \ingroup WritingTestResult
20
 
 *
21
 
 * Printing the test results in a compiler compatible format (assertion
22
 
 * location has the same format as compiler error), allow you to use your
23
 
 * IDE to jump to the assertion failure. Location format can be customized (see
24
 
 * setLocationFormat() ).
25
 
 *
26
 
 * For example, when running the test in a post-build with VC++, if an assertion
27
 
 * fails, you can jump to the assertion by pressing F4 (jump to next error).
28
 
 *
29
 
 * Heres is an example of usage (from examples/cppunittest/CppUnitTestMain.cpp):
30
 
 * \code
31
 
 * int main( int argc, char* argv[] ) {
32
 
 *   // if command line contains "-selftest" then this is the post build check
33
 
 *   // => the output must be in the compiler error format.
34
 
 *   bool selfTest = (argc > 1)  &&  
35
 
 *                   (std::string("-selftest") == argv[1]);
36
 
 *
37
 
 *   CppUnit::TextUi::TestRunner runner;
38
 
 *   runner.addTest( CppUnitTest::suite() );   // Add the top suite to the test runner
39
 
 * 
40
 
 *  if ( selfTest )
41
 
 *   { // Change the default outputter to a compiler error format outputter
42
 
 *     // The test runner owns the new outputter.
43
 
 *     runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
44
 
 *                                                          std::cerr ) );
45
 
 *   }
46
 
 * 
47
 
 *  // Run the test and don't wait a key if post build check.
48
 
 *   bool wasSuccessful = runner.run( "", !selfTest );
49
 
 * 
50
 
 *   // Return error code 1 if the one of test failed.
51
 
 *   return wasSuccessful ? 0 : 1;
52
 
 * }
53
 
 * \endcode
54
 
 */
55
 
class CPPUNIT_API CompilerOutputter : public Outputter
56
 
{
57
 
public:
58
 
  /*! \brief Constructs a CompilerOutputter object.
59
 
   * \param result Result of the test run.
60
 
   * \param stream Stream used to output test result.
61
 
   * \param locationFormat Error location format used by your compiler. Default
62
 
   *                       to \c CPPUNIT_COMPILER_LOCATION_FORMAT which is defined
63
 
   *                       in the configuration file. See setLocationFormat() for detail.
64
 
   * \see setLocationFormat().
65
 
   */
66
 
  CompilerOutputter( TestResultCollector *result,
67
 
                     OStream &stream,
68
 
                     const std::string &locationFormat = CPPUNIT_COMPILER_LOCATION_FORMAT );
69
 
 
70
 
  /// Destructor.
71
 
  virtual ~CompilerOutputter();
72
 
 
73
 
  /*! \brief Sets the error location format.
74
 
   * 
75
 
   * Indicates the format used to report location of failed assertion. This format should
76
 
   * match the one used by your compiler.
77
 
   *
78
 
   * The location format is a string in which the occurence of the following character
79
 
   * sequence are replaced:
80
 
   *
81
 
   * - "%l" => replaced by the line number
82
 
   * - "%p" => replaced by the full path name of the file ("G:\prg\vc\cppunit\MyTest.cpp")
83
 
   * - "%f" => replaced by the base name of the file ("MyTest.cpp")
84
 
   *
85
 
   * Some examples:
86
 
   *
87
 
   * - VC++ error location format: "%p(%l):" => produce "G:\prg\MyTest.cpp(43):"
88
 
   * - GCC error location format: "%f:%l:" => produce "MyTest.cpp:43:"
89
 
   * 
90
 
   * Thoses are the two compilers currently <em>supported</em> (gcc format is used if
91
 
   * VC++ is not detected). If you want your compiler to be automatically supported by
92
 
   * CppUnit, send a mail to the mailing list (preferred), or submit a feature request
93
 
   * that indicates how to detect your compiler with the preprocessor (\#ifdef...) and
94
 
   * your compiler location format.
95
 
   */
96
 
  void setLocationFormat( const std::string &locationFormat );
97
 
 
98
 
  /*! \brief Creates an instance of an outputter that matches your current compiler.
99
 
   * \deprecated This class is specialized through parameterization instead of subclassing...
100
 
   *             Use CompilerOutputter::CompilerOutputter instead.
101
 
   */
102
 
  static CompilerOutputter *defaultOutputter( TestResultCollector *result,
103
 
                                              OStream &stream );
104
 
 
105
 
  void write();
106
 
 
107
 
  void setNoWrap();
108
 
 
109
 
  void setWrapColumn( int wrapColumn );
110
 
 
111
 
  int wrapColumn() const;
112
 
 
113
 
  virtual void printSuccess();
114
 
  virtual void printFailureReport();
115
 
  virtual void printFailuresList();
116
 
  virtual void printStatistics();
117
 
  virtual void printFailureDetail( TestFailure *failure );
118
 
  virtual void printFailureLocation( SourceLine sourceLine );
119
 
  virtual void printFailureType( TestFailure *failure );
120
 
  virtual void printFailedTestName( TestFailure *failure );
121
 
  virtual void printFailureMessage( TestFailure *failure );
122
 
 
123
 
private:
124
 
  /// Prevents the use of the copy constructor.
125
 
  CompilerOutputter( const CompilerOutputter &copy );
126
 
 
127
 
  /// Prevents the use of the copy operator.
128
 
  void operator =( const CompilerOutputter &copy );
129
 
 
130
 
  virtual bool processLocationFormatCommand( char command, 
131
 
                                             const SourceLine &sourceLine );
132
 
 
133
 
  virtual std::string extractBaseName( const std::string &fileName ) const;
134
 
 
135
 
private:
136
 
  TestResultCollector *m_result;
137
 
  OStream &m_stream;
138
 
  std::string m_locationFormat;
139
 
  int m_wrapColumn;
140
 
};
141
 
 
142
 
 
143
 
CPPUNIT_NS_END
144
 
 
145
 
 
146
 
#endif  // CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H