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):
(std::string(
"-selftest") ==
argv[1]);
CppUnit::TextUi::TestRunner
runner;
{
runner.setOutputter(
new CppUnit::CompilerOutputter( &
runner.result(),
std::cerr ) );
}
return wasSuccessful ? 0 : 1;
}
Generate a test case from a fixture method.
Definition TestCaller.h:107
TestCaller(std::string name, TestMethod test)
Definition TestCaller.h:117
virtual void run(TestResult *result)
Run the test and catch any exceptions that are triggered by it.
Definition TestCase.cpp:53
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.