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 /src/cppunit/CompilerOutputter.cpp | |
| 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 'src/cppunit/CompilerOutputter.cpp')
| -rw-r--r-- | src/cppunit/CompilerOutputter.cpp | 78 |
1 files changed, 69 insertions, 9 deletions
diff --git a/src/cppunit/CompilerOutputter.cpp b/src/cppunit/CompilerOutputter.cpp index 025dd34..a828a40 100644 --- a/src/cppunit/CompilerOutputter.cpp +++ b/src/cppunit/CompilerOutputter.cpp @@ -10,9 +10,11 @@ namespace CppUnit { CompilerOutputter::CompilerOutputter( TestResultCollector *result, - std::ostream &stream ) : - m_result( result ), - m_stream( stream ) + std::ostream &stream, + const std::string &locationFormat ) + : m_result( result ) + , m_stream( stream ) + , m_locationFormat( locationFormat ) { } @@ -22,13 +24,18 @@ CompilerOutputter::~CompilerOutputter() } +void +CompilerOutputter::setLocationFormat( const std::string &locationFormat ) +{ + m_locationFormat = locationFormat; +} + + CompilerOutputter * CompilerOutputter::defaultOutputter( TestResultCollector *result, std::ostream &stream ) { return new CompilerOutputter( result, stream ); -// For automatic adpatation... -// return new CPPUNIT_DEFAULT_OUTPUTTER( result, stream ); } @@ -81,11 +88,64 @@ CompilerOutputter::printFailureDetail( TestFailure *failure ) void CompilerOutputter::printFailureLocation( SourceLine sourceLine ) { - if ( sourceLine.isValid() ) - m_stream << sourceLine.fileName() - << "(" << sourceLine.lineNumber() << ") : "; - else + if ( !sourceLine.isValid() ) + { m_stream << "##Failure Location unknown## : "; + return; + } + + std::string location; + for ( int index = 0; index < m_locationFormat.length(); ++index ) + { + char c = m_locationFormat[ index ]; + if ( c == '%' && ( index+1 < m_locationFormat.length() ) ) + { + char command = m_locationFormat[index+1]; + if ( processLocationFormatCommand( command, sourceLine ) ) + { + ++index; + continue; + } + } + + m_stream << c; + } +} + + +bool +CompilerOutputter::processLocationFormatCommand( char command, + const SourceLine &sourceLine ) +{ + switch ( command ) + { + case 'p': + m_stream << sourceLine.fileName(); + return true; + case 'l': + m_stream << sourceLine.lineNumber(); + return true; + case 'f': + m_stream << extractBaseName( sourceLine.fileName() ); + return true; + } + + return false; +} + + +std::string +CompilerOutputter::extractBaseName( const std::string &fileName ) const +{ + int indexLastDirectorySeparator = fileName.find_last_of( '/' ); + + if ( indexLastDirectorySeparator < 0 ) + indexLastDirectorySeparator = fileName.find_last_of( '\\' ); + + if ( indexLastDirectorySeparator < 0 ) + return fileName; + + return fileName.substr( indexLastDirectorySeparator +1 ); } |
