Menu

[r236]: / trunk / cppunit / include / cppunit / CompilerOutputter.h  Maximize  Restore  History

Download this file

110 lines (92 with data), 3.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
#ifndef CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H
#define CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H
#include <cppunit/Portability.h>
#include <cppunit/Outputter.h>
#include <vector>
#include <iostream>
namespace CppUnit
{
class Exception;
class SourceLine;
class Test;
class TestFailure;
class TestResultCollector;
/*!
* \brief Outputs a TestResultCollector in a compiler compatible format.
* \ingroup WritingTestResult
*
* 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.
*
* 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[] ) {
* // if command line contains "-selftest" then this is the post build check
* // => the output must be in the compiler error format.
* bool selfTest = (argc > 1) &&
* (std::string("-selftest") == argv[1]);
*
* CppUnit::TextUi::TestRunner runner;
* runner.addTest( CppUnitTest::suite() ); // Add the top suite to the test runner
*
* 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 ) );
* }
*
* // Run the test and don't wait a key if post build check.
* bool wasSucessful = runner.run( "", !selfTest );
*
* // Return error code 1 if the one of test failed.
* return wasSucessful ? 0 : 1;
* }
* \endcode
*/
class CPPUNIT_API CompilerOutputter : public Outputter
{
public:
/*! Constructs a CompilerOutputter object.
*/
CompilerOutputter( TestResultCollector *result,
std::ostream &stream );
/// Destructor.
virtual ~CompilerOutputter();
/*! Creates an instance of an outputter that matches your current compiler.
*/
static CompilerOutputter *defaultOutputter( TestResultCollector *result,
std::ostream &stream );
void write();
virtual void printSucess();
virtual void printFailureReport();
virtual void printFailuresList();
virtual void printStatistics();
virtual void printFailureDetail( TestFailure *failure );
virtual void printFailureLocation( SourceLine sourceLine );
virtual void printFailureType( TestFailure *failure );
virtual void printFailedTestName( TestFailure *failure );
virtual void printFailureMessage( TestFailure *failure );
virtual void printNotEqualMessage( Exception *thrownException );
virtual void printDefaultMessage( Exception *thrownException );
virtual std::string wrap( std::string message );
private:
/// Prevents the use of the copy constructor.
CompilerOutputter( const CompilerOutputter &copy );
/// Prevents the use of the copy operator.
void operator =( const CompilerOutputter &copy );
typedef std::vector<std::string> Lines;
static Lines splitMessageIntoLines( std::string message );
private:
TestResultCollector *m_result;
std::ostream &m_stream;
};
} // namespace CppUnit
#endif // CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H
MongoDB Logo MongoDB