CppUnit project page | FAQ

Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
CompilerOutputter Class Reference
Writing test result

Outputs a TestResultCollector in a compiler compatible format.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. Location format can be customized (see setLocationFormat() ). More...

`#include <CompilerOutputter.h>`

Inheritance diagram for CompilerOutputter:

## Public Member Functions

| CompilerOutputter (TestResultCollector *result, OStream &stream, const std::string &locationFormat=CPPUNIT_COMPILER_LOCATION_FORMAT)
| Constructs a CompilerOutputter object. More...
virtual | ~CompilerOutputter ()
| Destructor. More...
void | setLocationFormat (const std::string &locationFormat)
| Sets the error location format. More...
void | write ()
void | setNoWrap ()
void | setWrapColumn (int wrapColumn)
int | wrapColumn () const
virtual void | printSuccess ()
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)
Public Member Functions inherited from Outputter
virtual | ~Outputter ()
| Destructor. More...

## Static Public Member Functions

static CompilerOutputter * | defaultOutputter (TestResultCollector *result, OStream &stream)
| Creates an instance of an outputter that matches your current compiler. More...

## Private Member Functions

| CompilerOutputter (const CompilerOutputter &copy)
| Prevents the use of the copy constructor. More...
void | operator= (const CompilerOutputter &copy)
| Prevents the use of the copy operator. More...
virtual bool | processLocationFormatCommand (char command, const SourceLine &sourceLine)
virtual std::string | extractBaseName (const std::string &fileName) const

## Private Attributes

TestResultCollector * | m_result
OStream & | m_stream
std::string | m_locationFormat
int | m_wrapColumn

## Detailed Description

Outputs a TestResultCollector in a compiler compatible format.

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. 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).

Heres is an example of usage (from examples/cppunittest/CppUnitTestMain.cpp):

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( new CppUnit::CompilerOutputter( &runner.result(),
std::cerr ) );
}
// Run the test and don't wait a key if post build check.
bool wasSuccessful = runner.run( "", !selfTest );
// Return error code 1 if the one of test failed.
return wasSuccessful ? 0 : 1;
}

## Constructor & Destructor Documentation

## ◆ CompilerOutputter() [1/2]

CPPUNIT_NS_BEGIN CompilerOutputter::CompilerOutputter | ( | TestResultCollector * | result,
|  | OStream & | stream,
|  | const std::string & | locationFormat = `CPPUNIT_COMPILER_LOCATION_FORMAT`
| ) |  |

Constructs a CompilerOutputter object.

Parameters

  result | Result of the test run.
  stream | Stream used to output test result.
  locationFormat | Error location format used by your compiler. Default to `CPPUNIT_COMPILER_LOCATION_FORMAT` which is defined in the configuration file. See setLocationFormat() for detail.

See also
  setLocationFormat().

## ◆ ~CompilerOutputter()

CompilerOutputter::~CompilerOutputter | ( |  | ) |

virtual

Destructor.

## ◆ CompilerOutputter() [2/2]

CompilerOutputter::CompilerOutputter | ( | const CompilerOutputter & | copy | ) |

private

Prevents the use of the copy constructor.

## Member Function Documentation

## ◆ defaultOutputter()

CompilerOutputter * CompilerOutputter::defaultOutputter | ( | TestResultCollector * | result,
|  | OStream & | stream
| ) |  |

static

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.

## ◆ extractBaseName()

std::string CompilerOutputter::extractBaseName | ( | const std::string & | fileName | ) | const

private virtual

## ◆ operator=()

void CompilerOutputter::operator= | ( | const CompilerOutputter & | copy | ) |

private

Prevents the use of the copy operator.

## ◆ printFailedTestName()

void CompilerOutputter::printFailedTestName | ( | TestFailure * | failure | ) |

virtual

## ◆ printFailureDetail()

void CompilerOutputter::printFailureDetail | ( | TestFailure * | failure | ) |

virtual

## ◆ printFailureLocation()

void CompilerOutputter::printFailureLocation | ( | SourceLine | sourceLine | ) |

virtual

## ◆ printFailureMessage()

void CompilerOutputter::printFailureMessage | ( | TestFailure * | failure | ) |

virtual

## ◆ printFailureReport()

void CompilerOutputter::printFailureReport | ( |  | ) |

virtual

## ◆ printFailuresList()

void CompilerOutputter::printFailuresList | ( |  | ) |

virtual

## ◆ printFailureType()

void CompilerOutputter::printFailureType | ( | TestFailure * | failure | ) |

virtual

## ◆ printStatistics()

void CompilerOutputter::printStatistics | ( |  | ) |

virtual

## ◆ printSuccess()

void CompilerOutputter::printSuccess | ( |  | ) |

virtual

## ◆ processLocationFormatCommand()

bool CompilerOutputter::processLocationFormatCommand | ( | char | command,
|  | const SourceLine & | sourceLine
| ) |  |

private virtual

## ◆ setLocationFormat()

void CompilerOutputter::setLocationFormat | ( | const std::string & | locationFormat | ) |

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 supported (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.

## ◆ setNoWrap()

void CompilerOutputter::setNoWrap | ( |  | ) |

## ◆ setWrapColumn()

void CompilerOutputter::setWrapColumn | ( | int | wrapColumn | ) |

## ◆ wrapColumn()

int CompilerOutputter::wrapColumn | ( |  | ) | const

## ◆ write()

void CompilerOutputter::write | ( |  | ) |

virtual

Implements Outputter.

## Member Data Documentation

## ◆ m_locationFormat

std::string CompilerOutputter::m_locationFormat

private

## ◆ m_result

TestResultCollector* CompilerOutputter::m_result

private

## ◆ m_stream

OStream& CompilerOutputter::m_stream

private

## ◆ m_wrapColumn

int CompilerOutputter::m_wrapColumn

private

The documentation for this class was generated from the following files:

- CompilerOutputter.h
- CompilerOutputter.cpp

| Send comments to: CppUnit Developers