Another way of doing it is to use the \snippet
command.
- In your header file write something like:
\section ex1 Example
\snippet path_to_test_class/TestClass.cpp TestClass example
\section ex2 Expected output
\snippet path_to_test_class/TestClass.cpp TestClass expected output
- In the TestClass.cpp file, have something like:
//! [OptimizeSpeedOnTrackTest example]
Class c;
const double res = c.do_something();
//! [OptimizeSpeedOnTrackTest example]
//! [OptimizeSpeedOnTrackTest expected output]
ASSERT_DOUBLE_EQ(5,res);
//! [OptimizeSpeedOnTrackTest expected output]
path_to_test_class
must be in your EXAMPLE_PATH.
This gives you the following:
- Your examples aren't just there for documentation: they provide test coverage as well
- Your test runner (& your compiler) give you the insurance that your examples actually compile & run
- It fits in pretty nicely in a TDD workflow