diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-04-12 21:34:37 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-04-12 21:34:37 +0000 |
| commit | 8cabaebd9f8689ca96184daf415e3cc6cf67d722 (patch) | |
| tree | 3c1b0f8d4a74147dbf659875e1a646def0dfb7b9 /include/cppunit/CompilerOutputter.h | |
| parent | ed406a2966e62072fa6afaca8abc578db7c0c9fb (diff) | |
| download | cppunit-8cabaebd9f8689ca96184daf415e3cc6cf67d722.tar.gz | |
Include/cppunit/CompilerOutputter.
include/cppunit/CompilerOutputter.h:
* src/cppunit/CompilerOutputter.h: deprecated defaultOuputter(). Added
setLocationFormat() and format specifiation in constructor. A string that
represent the location format is used to output the location. Default format
is defined by CPPUNIT_COMPILER_LOCATION_FORMAT.
* include/cppunit/config-msvc6.h:
* include/cppunit/Portability.h: added CPPUNIT_COMPILER_LOCATION_FORMAT. Use
gcc location format if VC++ is not detected.
* include/cppunit/Test.h: fixed documentation.
* include/cppunit/TestListener.h: added startSuite() and endSuite()
callbacks. Added new example to documentation.
* include/cppunit/TestResult.h:
* src/cppunit/TestResult.cpp:
* include/cppunit/TestComposite.h:
* src/cppunit/TestComposite.cpp: Updated to inform the listeners.
* src/qttestrunner/TestBrowserDlgImpl.cpp: used Test new composite interface
instead of RTTI to explore the test hierarchy.
* examples/cppunittest/MockTestListener.h:
* examples/cppunittest/MockTestListener.cpp: updated,added support for
startSuite() and endSuite().
* examples/cppunittest/TestResultTest.h:
* examples/cppunittest/TestResultTest.cpp: added tests for startSuite()
and endSuite().
Diffstat (limited to 'include/cppunit/CompilerOutputter.h')
| -rw-r--r-- | include/cppunit/CompilerOutputter.h | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/include/cppunit/CompilerOutputter.h b/include/cppunit/CompilerOutputter.h index 0075972..b2b183d 100644 --- a/include/cppunit/CompilerOutputter.h +++ b/include/cppunit/CompilerOutputter.h @@ -21,13 +21,12 @@ class TestResultCollector; * * Printing the test results in a compiler compatible format (assertion * location has the same format as compiler error), allow you to use your - * IDE to jump to the assertion failure. + * IDE to jump to the assertion failure. Location format can be customized (see + * setLocationFormat() ). * * For example, when running the test in a post-build with VC++, if an assertion * fails, you can jump to the assertion by pressing F4 (jump to next error). * - * You should use defaultOutputter() to create an instance. - * * Heres is an example of usage (from examples/cppunittest/CppUnitTestMain.cpp): * \code * int main( int argc, char* argv[] ) { @@ -42,9 +41,8 @@ class TestResultCollector; * if ( selfTest ) * { // Change the default outputter to a compiler error format outputter * // The test runner owns the new outputter. - * runner.setOutputter( CppUnit::CompilerOutputter::defaultOutputter( - * &runner.result(), - * std::cerr ) ); + * runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), + * std::cerr ) ); * } * * // Run the test and don't wait a key if post build check. @@ -59,14 +57,48 @@ class CPPUNIT_API CompilerOutputter : public Outputter { public: /*! Constructs a CompilerOutputter object. + * \param result Result of the test run. + * \param stream Stream used to output test result. + * \param locationFormat Error location format used by your compiler. Default + * to \c CPPUNIT_COMPILER_LOCATION_FORMAT which is defined + * in the configuration file. See setLocationFormat() for detail. + * \see setLocationFormat(). */ CompilerOutputter( TestResultCollector *result, - std::ostream &stream ); + std::ostream &stream, + const std::string &locationFormat = CPPUNIT_COMPILER_LOCATION_FORMAT ); /// Destructor. virtual ~CompilerOutputter(); + /*! Sets the error location format. + * + * Indicates the format used to report location of failed assertion. This format should + * match the one used by your compiler. + * + * The location format is a string in which the occurence of the following character + * sequence are replaced: + * + * - "%l" => replaced by the line number + * - "%p" => replaced by the full path name of the file ("G:\prg\vc\cppunit\MyTest.cpp") + * - "%f" => replaced by the base name of the file ("MyTest.cpp") + * + * Some examples: + * + * - VC++ error location format: "%p(%l):" => produce "G:\prg\MyTest.cpp(43):" + * - GCC error location format: "%f:%l:" => produce "MyTest.cpp(43):" + * + * Thoses are the two compilers currently <em>supported</em> (gcc format is used if + * VC++ is not detected). If you want your compiler to be automatically supported by + * CppUnit, send a mail to the mailing list (preferred), or submit a feature request + * that indicates how to detect your compiler with the preprocessor (#ifdef...) and + * your compiler location format. + */ + void setLocationFormat( const std::string &locationFormat ); + /*! Creates an instance of an outputter that matches your current compiler. + * \deprecated This class is specialized through parameterization instead of subclassing... + * Use CompilerOutputter::CompilerOutputter instead. */ static CompilerOutputter *defaultOutputter( TestResultCollector *result, std::ostream &stream ); @@ -93,12 +125,18 @@ private: /// Prevents the use of the copy operator. void operator =( const CompilerOutputter © ); + virtual bool processLocationFormatCommand( char command, + const SourceLine &sourceLine ); + + virtual std::string extractBaseName( const std::string &fileName ) const; + typedef std::vector<std::string> Lines; static Lines splitMessageIntoLines( std::string message ); private: TestResultCollector *m_result; std::ostream &m_stream; + std::string m_locationFormat; }; |
