This class has absolutely no reliance on any other workspace code. It only uses classes and typedef's found in the C++ standard (eg in the STL) and all client test code which uses the class will not need to link in any other workspace library unless the client code calls workspace code itself.
void fail |
( |
const std::string & |
msg = "" | ) |
const |
|
inline |
- Parameters
-
msg | Some information about why the test failed. |
This function generates an exception which will be caught and handled appropriately by the run() function to indicate that the test failed. Unlike the functions for the other exit conditions, this function outputs the text messages now rather than letting the runTest() function handle it. This is required so that output is not lost if throwing an exception will result in a segmentation fault (and therefore an instant termination).
Most clients should prefer to use the failTest() macro, since it calls this function but with the source file and line number embedded within msg. This generally makes it easier to trace the source of the failure.
int run |
( |
bool |
captureOutput = false | ) |
|
|
inline |
- Parameters
-
captureOutput | If true, the test harness will capture all output sent to std::cerr and std::cout. If the test passes, the captured output will be discarded, but for any other exit conditions, the captured output will be included after the line indicating the exit condition. If captureOutput is false, then all text sent to std::cerr and std::cout will be sent to these streams as per normal. |
This used to be default to true but has been changed to false as there seems no reason why you wouldn't want as much information available as possible all the time.
Wrapper around runTest() to catch all exceptions. This function will output one of the following three strings followed by the name of the test:
In the case of FAILED, the next line will usually contain some text explaining why the test failed.
- Returns
- 0 if the test passed, 1 if the test was skipped, 2 if the test failed for a reason initiated by the test code, 3 if a standard C++ exception was spontaneously thrown and 4 if some other C++ exception was spontaneously thrown.
- See also
- runTest
Subclasses override this to perform the work of the test. If the test completes successfully, then runTest simply needs to return normally. If the test should be skipped, the subclass should call skip(), at which point an exception will be generated which will be caught by the run() function. If the test fails, the subclass should call fail() and again an exception will be generated which will be caught by run().
It is not normally necessary to call runTest directly. Instead, the test should be run by calling the public run() function, since this takes care of printing standard text to specify the outcome of the test and it catches all exceptions so that the outcome is always known.
Implemented in TestSuite::TestCase< TestNum >.
void setDescription |
( |
const std::string & |
desc | ) |
|
|
inline |
- Parameters
-
desc | The new description for the test. |
This function is rarely used for single tests, but tests that are part of a test suite may call this to provide additional information about that particular test. The description should not be particularly long, generally being no more than a few words and rarely longer than one line of text. It is quite common for the description to be empty.
A useful feature of the description is that for failed tests, it is shown immediately after the FAILED line to provide additional context for the failure.
- See also
- getDescription()