1
#ifndef CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H
2
#define CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H
4
#include <cppunit/Portability.h>
5
#include <cppunit/Outputter.h>
6
#include <cppunit/portability/Stream.h>
15
class TestResultCollector;
18
* \brief Outputs a TestResultCollector in a compiler compatible format.
19
* \ingroup WritingTestResult
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() ).
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).
29
* Heres is an example of usage (from examples/cppunittest/CppUnitTestMain.cpp):
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]);
37
* CppUnit::TextUi::TestRunner runner;
38
* runner.addTest( CppUnitTest::suite() ); // Add the top suite to the test runner
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(),
47
* // Run the test and don't wait a key if post build check.
48
* bool wasSuccessful = runner.run( "", !selfTest );
50
* // Return error code 1 if the one of test failed.
51
* return wasSuccessful ? 0 : 1;
55
class CPPUNIT_API CompilerOutputter : public Outputter
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().
66
CompilerOutputter( TestResultCollector *result,
68
const std::string &locationFormat = CPPUNIT_COMPILER_LOCATION_FORMAT );
71
virtual ~CompilerOutputter();
73
/*! \brief Sets the error location format.
75
* Indicates the format used to report location of failed assertion. This format should
76
* match the one used by your compiler.
78
* The location format is a string in which the occurence of the following character
79
* sequence are replaced:
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")
87
* - VC++ error location format: "%p(%l):" => produce "G:\prg\MyTest.cpp(43):"
88
* - GCC error location format: "%f:%l:" => produce "MyTest.cpp:43:"
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.
96
void setLocationFormat( const std::string &locationFormat );
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.
102
static CompilerOutputter *defaultOutputter( TestResultCollector *result,
109
void setWrapColumn( int wrapColumn );
111
int wrapColumn() const;
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 );
124
/// Prevents the use of the copy constructor.
125
CompilerOutputter( const CompilerOutputter © );
127
/// Prevents the use of the copy operator.
128
void operator =( const CompilerOutputter © );
130
virtual bool processLocationFormatCommand( char command,
131
const SourceLine &sourceLine );
133
virtual std::string extractBaseName( const std::string &fileName ) const;
136
TestResultCollector *m_result;
138
std::string m_locationFormat;
146
#endif // CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H